diff --git a/pom.xml b/pom.xml index 4073a8ee..662fca0e 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,24 @@ SOFTWARE. 12.5 runtime + + org.yaml + snakeyaml + 2.3 + test + + + com.yegor256 + xsline + 0.21.1 + test + + + com.jcabi + jcabi-log + 0.24.3 + test + org.eolang eo-parser diff --git a/src/main/resources/org/eolang/lints/lines/meta-line-out-of-listing.xsl b/src/main/resources/org/eolang/lints/lines/meta-line-out-of-listing.xsl new file mode 100644 index 00000000..09658940 --- /dev/null +++ b/src/main/resources/org/eolang/lints/lines/meta-line-out-of-listing.xsl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + error + + The line + + is out of listing, which contains only + + lines + + + + + diff --git a/src/main/resources/org/eolang/lints/lines/object-line-out-of-listing.xsl b/src/main/resources/org/eolang/lints/lines/object-line-out-of-listing.xsl new file mode 100644 index 00000000..4b6678e3 --- /dev/null +++ b/src/main/resources/org/eolang/lints/lines/object-line-out-of-listing.xsl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + error + + The line + + is out of listing, which contains only + + lines + + + + + diff --git a/src/test/java/org/eolang/lints/LintByXslTest.java b/src/test/java/org/eolang/lints/LintByXslTest.java index 3348eb11..a19a5668 100644 --- a/src/test/java/org/eolang/lints/LintByXslTest.java +++ b/src/test/java/org/eolang/lints/LintByXslTest.java @@ -23,17 +23,29 @@ */ package org.eolang.lints; +import com.jcabi.log.Logger; +import com.jcabi.xml.XML; +import com.jcabi.xml.XMLDocument; +import com.yegor256.xsline.Shift; +import com.yegor256.xsline.StClasspath; +import com.yegor256.xsline.Train; +import com.yegor256.xsline.Xsline; import java.io.IOException; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Map; import org.cactoos.io.InputOf; import org.eolang.jucs.ClasspathSource; import org.eolang.parser.CheckPack; import org.eolang.parser.EoSyntax; +import org.eolang.parser.TrParsing; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.hamcrest.core.IsEqual; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.yaml.snakeyaml.Yaml; /** * Test for {@link LintByXsl}. @@ -57,7 +69,7 @@ void lintsOneFile() throws IOException { @ParameterizedTest @ClasspathSource(value = "org/eolang/lints/eo-packs/", glob = "**.yaml") - void testsAllLints(final String pack) throws IOException { + void testsAllLintsByEo(final String pack) throws IOException { final CheckPack check = new CheckPack(pack); if (check.skip()) { Assumptions.abort(String.format("%s is not ready", pack)); @@ -69,6 +81,36 @@ void testsAllLints(final String pack) throws IOException { ); } + @ParameterizedTest + @SuppressWarnings("unchecked") + @ClasspathSource(value = "org/eolang/lints/xmir-packs/", glob = "**.yaml") + void testsAllLintsByXmir(final String pack) { + final Yaml yaml = new Yaml(); + final Map map = yaml.load(pack); + final Iterable xsls = (Iterable) map.get("xsls"); + Train train = new TrParsing(); + if (xsls != null) { + for (final String xsl : xsls) { + train = train.with(new StClasspath(xsl)); + } + } + final XML out = new Xsline(train).pass( + new XMLDocument(map.get("xmir").toString()) + ); + Logger.debug(this, "Output XML:\n%s", out); + final Collection failures = new LinkedList<>(); + for (final String xpath : (Iterable) map.get("tests")) { + if (out.nodes(xpath).isEmpty()) { + failures.add(xpath); + } + } + MatcherAssert.assertThat( + String.format("Broken XML:\n%s", out), + failures, + Matchers.emptyIterable() + ); + } + @Test void returnsMotive() throws Exception { MatcherAssert.assertThat( diff --git a/src/test/resources/org/eolang/lints/xmir-packs/line-out-of-listing/catches-meta-outsider.yaml b/src/test/resources/org/eolang/lints/xmir-packs/line-out-of-listing/catches-meta-outsider.yaml new file mode 100644 index 00000000..410d3469 --- /dev/null +++ b/src/test/resources/org/eolang/lints/xmir-packs/line-out-of-listing/catches-meta-outsider.yaml @@ -0,0 +1,38 @@ +# The MIT License (MIT) +# +# Copyright (c) 2016-2024 Objectionary.com +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +xsls: + - /org/eolang/lints/lines/meta-line-out-of-listing.xsl +tests: + - /defects[count(defect[@severity='error'])=1] +xmir: | + + first line + second line + third line + + + hello + + + + diff --git a/src/test/resources/org/eolang/lints/xmir-packs/line-out-of-listing/catches-object-outsider.yaml b/src/test/resources/org/eolang/lints/xmir-packs/line-out-of-listing/catches-object-outsider.yaml new file mode 100644 index 00000000..cb0ac4b4 --- /dev/null +++ b/src/test/resources/org/eolang/lints/xmir-packs/line-out-of-listing/catches-object-outsider.yaml @@ -0,0 +1,35 @@ +# The MIT License (MIT) +# +# Copyright (c) 2016-2024 Objectionary.com +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +xsls: + - /org/eolang/lints/lines/object-line-out-of-listing.xsl +tests: + - /defects[count(defect[@severity='error'])=1] +xmir: | + + first line + second line + third line + + + +