Skip to content

Commit

Permalink
#603 extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 25, 2022
1 parent 40da462 commit 8f92d01
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 10 deletions.
75 changes: 75 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/XslsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2022 Yegor Bugayenko
*
* 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.
*/
package org.eolang.maven;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.stream.Collectors;
import org.cactoos.text.TextOf;
import org.eolang.parser.CheckXSL;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test case for all .xsl files, which are specified in .yaml files
* in {@code src/test/xsl} directories.
*
* @since 0.21
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class XslsTest {

/**
* Where is the home of this module.
*/
private static final Path HOME = Paths.get(
System.getProperty("basedir", "eo-maven-plugin")
);

@ParameterizedTest
@MethodSource("yamlPacks")
public void testPacks(final Path path) throws Exception {
MatcherAssert.assertThat(
new CheckXSL(
XslsTest.HOME.resolve("src/main/resources"),
new TextOf(path).asString()
).isValid(),
Matchers.is(true)
);
}

@SuppressWarnings("PMD.UnusedPrivateMethod")
private static Collection<Path> yamlPacks() throws IOException {
return Files.walk(XslsTest.HOME)
.filter(file -> file.toString().contains("src/test/xsl/"))
.filter(file -> file.toString().endsWith(".yml"))
.filter(file -> !file.toFile().isDirectory())
.collect(Collectors.toList());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
xsl: org/eolang/maven/pre/classes.xsl
input:
<xmir>
<listing>[] &gt; foo</listing>
</xmir>
output:
<xmir>
<listing>[] &gt; foo</listing>
</xmir>
3 changes: 2 additions & 1 deletion eo-parser/src/main/java/org/eolang/parser/CheckXSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eolang.parser;

import com.jcabi.log.Logger;
import com.jcabi.xml.ClasspathSources;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.jcabi.xml.XSL;
Expand Down Expand Up @@ -76,7 +77,7 @@ public boolean isValid() throws IOException {
final XML output = new XMLDocument(map.get("output").toString());
final XSL xsl = new XSLDocument(
this.home.resolve(map.get("xsl").toString())
);
).with(new ClasspathSources());
final XML after = new XMLDocument(xsl.applyTo(input));
final boolean matches = after.toString().equals(output.toString());
if (!matches) {
Expand Down

0 comments on commit 8f92d01

Please sign in to comment.