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
+
1
23
package nu .validator .htmlparser .test ;
2
24
3
25
import java .io .IOException ;
@@ -14,26 +36,33 @@ public class Html5libTest {
14
36
private final Path testDir ;
15
37
16
38
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 ());
18
41
}
19
42
20
43
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 ) {
23
48
assert false : "Encoding test failed" ;
24
49
}
25
50
}
26
51
27
52
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 ) {
30
57
assert false : "Tokenizer test failed" ;
31
58
}
32
59
}
33
60
34
61
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 ) {
37
66
assert false : "Tree test failed" ;
38
67
}
39
68
}
@@ -44,7 +73,7 @@ private interface TestConsumer extends Consumer<Path> {
44
73
default void accept (Path t ) {
45
74
try {
46
75
acceptTest (t );
47
- } catch (Throwable e ) {
76
+ } catch (Throwable e ) {
48
77
throw new AssertionError (e );
49
78
}
50
79
}
@@ -56,17 +85,21 @@ default void accept(Path t) {
56
85
private static class TestVisitor extends SimpleFileVisitor <Path > {
57
86
58
87
private final boolean skipScripted ;
88
+
59
89
private final boolean requireTestExtension ;
90
+
60
91
private final TestConsumer runner ;
61
92
62
- private TestVisitor (boolean skipScripted , boolean requireTestExtension , TestConsumer runner ) {
93
+ private TestVisitor (boolean skipScripted , boolean requireTestExtension ,
94
+ TestConsumer runner ) {
63
95
this .skipScripted = skipScripted ;
64
96
this .requireTestExtension = requireTestExtension ;
65
97
this .runner = runner ;
66
98
}
67
99
68
100
@ Override
69
- public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) throws IOException {
101
+ public FileVisitResult preVisitDirectory (Path dir ,
102
+ BasicFileAttributes attrs ) throws IOException {
70
103
if (skipScripted && dir .getFileName ().equals (Path .of ("scripted" ))) {
71
104
return FileVisitResult .SKIP_SUBTREE ;
72
105
}
@@ -75,8 +108,10 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
75
108
}
76
109
77
110
@ 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" )) {
80
115
runner .accept (file );
81
116
}
82
117
return FileVisitResult .CONTINUE ;
0 commit comments