Skip to content

Commit 2317de9

Browse files
Html5libTest: Add copyright; match project style
1 parent c1c1035 commit 2317de9

File tree

1 file changed

+47
-12
lines changed

1 file changed

+47
-12
lines changed

test-src/nu/validator/htmlparser/test/Html5libTest.java

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/*
2+
* Copyright (c) 2020 Mozilla Foundation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*/
22+
123
package nu.validator.htmlparser.test;
224

325
import java.io.IOException;
@@ -14,26 +36,33 @@ public class Html5libTest {
1436
private final Path testDir;
1537

1638
public Html5libTest() throws URISyntaxException {
17-
this.testDir = Path.of(Html5libTest.class.getResource("/html5lib-tests").toURI());
39+
this.testDir = Path.of(
40+
Html5libTest.class.getResource("/html5lib-tests").toURI());
1841
}
1942

2043
public void testEncoding() throws Exception {
21-
Files.walkFileTree(testDir.resolve("encoding"), new TestVisitor(true, false, file -> new EncodingTester(Files.newInputStream(file)).runTests()));
22-
if(EncodingTester.exitStatus != 0) {
44+
Files.walkFileTree(testDir.resolve("encoding"), //
45+
new TestVisitor(true, false, file -> //
46+
new EncodingTester(Files.newInputStream(file)).runTests()));
47+
if (EncodingTester.exitStatus != 0) {
2348
assert false : "Encoding test failed";
2449
}
2550
}
2651

2752
public void testTokenizer() throws Exception {
28-
Files.walkFileTree(testDir.resolve("tokenizer"), new TestVisitor(true, true, file -> new TokenizerTester(Files.newInputStream(file)).runTests()));
29-
if(TokenizerTester.exitStatus != 0) {
53+
Files.walkFileTree(testDir.resolve("tokenizer"),
54+
new TestVisitor(true, true, file -> //
55+
new TokenizerTester(Files.newInputStream(file)).runTests()));
56+
if (TokenizerTester.exitStatus != 0) {
3057
assert false : "Tokenizer test failed";
3158
}
3259
}
3360

3461
public void testTree() throws Exception {
35-
Files.walkFileTree(testDir.resolve("tree-construction"), new TestVisitor(true, false, file -> new TreeTester(Files.newInputStream(file)).runTests()));
36-
if(TreeTester.exitStatus != 0) {
62+
Files.walkFileTree(testDir.resolve("tree-construction"),
63+
new TestVisitor(true, false, file -> //
64+
new TreeTester(Files.newInputStream(file)).runTests()));
65+
if (TreeTester.exitStatus != 0) {
3766
assert false : "Tree test failed";
3867
}
3968
}
@@ -44,7 +73,7 @@ private interface TestConsumer extends Consumer<Path> {
4473
default void accept(Path t) {
4574
try {
4675
acceptTest(t);
47-
} catch(Throwable e) {
76+
} catch (Throwable e) {
4877
throw new AssertionError(e);
4978
}
5079
}
@@ -56,17 +85,21 @@ default void accept(Path t) {
5685
private static class TestVisitor extends SimpleFileVisitor<Path> {
5786

5887
private final boolean skipScripted;
88+
5989
private final boolean requireTestExtension;
90+
6091
private final TestConsumer runner;
6192

62-
private TestVisitor(boolean skipScripted, boolean requireTestExtension, TestConsumer runner) {
93+
private TestVisitor(boolean skipScripted, boolean requireTestExtension,
94+
TestConsumer runner) {
6395
this.skipScripted = skipScripted;
6496
this.requireTestExtension = requireTestExtension;
6597
this.runner = runner;
6698
}
6799

68100
@Override
69-
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
101+
public FileVisitResult preVisitDirectory(Path dir,
102+
BasicFileAttributes attrs) throws IOException {
70103
if (skipScripted && dir.getFileName().equals(Path.of("scripted"))) {
71104
return FileVisitResult.SKIP_SUBTREE;
72105
}
@@ -75,8 +108,10 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
75108
}
76109

77110
@Override
78-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
79-
if (!requireTestExtension || file.getFileName().toString().endsWith(".test")) {
111+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
112+
throws IOException {
113+
if (!requireTestExtension
114+
|| file.getFileName().toString().endsWith(".test")) {
80115
runner.accept(file);
81116
}
82117
return FileVisitResult.CONTINUE;

0 commit comments

Comments
 (0)