From 2317de99a676ef9e483987ed9d22bd47378403e9 Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Tue, 25 Aug 2020 16:48:16 +0900 Subject: [PATCH] Html5libTest: Add copyright; match project style --- .../htmlparser/test/Html5libTest.java | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/test-src/nu/validator/htmlparser/test/Html5libTest.java b/test-src/nu/validator/htmlparser/test/Html5libTest.java index 2b336b7a..9c18e749 100644 --- a/test-src/nu/validator/htmlparser/test/Html5libTest.java +++ b/test-src/nu/validator/htmlparser/test/Html5libTest.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2020 Mozilla Foundation + * + * 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 NONINFRINGEMENT. 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 nu.validator.htmlparser.test; import java.io.IOException; @@ -14,26 +36,33 @@ public class Html5libTest { private final Path testDir; public Html5libTest() throws URISyntaxException { - this.testDir = Path.of(Html5libTest.class.getResource("/html5lib-tests").toURI()); + this.testDir = Path.of( + Html5libTest.class.getResource("/html5lib-tests").toURI()); } public void testEncoding() throws Exception { - Files.walkFileTree(testDir.resolve("encoding"), new TestVisitor(true, false, file -> new EncodingTester(Files.newInputStream(file)).runTests())); - if(EncodingTester.exitStatus != 0) { + Files.walkFileTree(testDir.resolve("encoding"), // + new TestVisitor(true, false, file -> // + new EncodingTester(Files.newInputStream(file)).runTests())); + if (EncodingTester.exitStatus != 0) { assert false : "Encoding test failed"; } } public void testTokenizer() throws Exception { - Files.walkFileTree(testDir.resolve("tokenizer"), new TestVisitor(true, true, file -> new TokenizerTester(Files.newInputStream(file)).runTests())); - if(TokenizerTester.exitStatus != 0) { + Files.walkFileTree(testDir.resolve("tokenizer"), + new TestVisitor(true, true, file -> // + new TokenizerTester(Files.newInputStream(file)).runTests())); + if (TokenizerTester.exitStatus != 0) { assert false : "Tokenizer test failed"; } } public void testTree() throws Exception { - Files.walkFileTree(testDir.resolve("tree-construction"), new TestVisitor(true, false, file -> new TreeTester(Files.newInputStream(file)).runTests())); - if(TreeTester.exitStatus != 0) { + Files.walkFileTree(testDir.resolve("tree-construction"), + new TestVisitor(true, false, file -> // + new TreeTester(Files.newInputStream(file)).runTests())); + if (TreeTester.exitStatus != 0) { assert false : "Tree test failed"; } } @@ -44,7 +73,7 @@ private interface TestConsumer extends Consumer { default void accept(Path t) { try { acceptTest(t); - } catch(Throwable e) { + } catch (Throwable e) { throw new AssertionError(e); } } @@ -56,17 +85,21 @@ default void accept(Path t) { private static class TestVisitor extends SimpleFileVisitor { private final boolean skipScripted; + private final boolean requireTestExtension; + private final TestConsumer runner; - private TestVisitor(boolean skipScripted, boolean requireTestExtension, TestConsumer runner) { + private TestVisitor(boolean skipScripted, boolean requireTestExtension, + TestConsumer runner) { this.skipScripted = skipScripted; this.requireTestExtension = requireTestExtension; this.runner = runner; } @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + public FileVisitResult preVisitDirectory(Path dir, + BasicFileAttributes attrs) throws IOException { if (skipScripted && dir.getFileName().equals(Path.of("scripted"))) { return FileVisitResult.SKIP_SUBTREE; } @@ -75,8 +108,10 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th } @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (!requireTestExtension || file.getFileName().toString().endsWith(".test")) { + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) + throws IOException { + if (!requireTestExtension + || file.getFileName().toString().endsWith(".test")) { runner.accept(file); } return FileVisitResult.CONTINUE;