1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
include shared/tree_common
import std/streams
proc runTest(test: TCTest, factory: MAtomFactory, scripting: bool) =
let ss = newStringStream(test.data)
let opts = HTML5ParserOpts[Node, MAtom](
scripting: scripting
)
let pdoc = if test.fragment.isNone:
parseHTML(ss, opts, factory)
else:
let ctx = Element()
ctx[] = test.fragment.get.ctx[]
let childList = parseHTMLFragment(ss, ctx, opts, factory)
for child in childList:
if ctx.preInsertionValidity(child, nil):
ctx.childList.add(child)
Document(nodeType: DOCUMENT_NODE, childList: ctx.childList)
#[
var ins = ""
for x in test.document.childList:
ins &= $x & '\n'
var ps = ""
for x in pdoc.childList:
ps &= $x & '\n'
echo "data ", test.data
echo "indoc ", $ins
echo "psdoc ", $ps
]#
checkTest(test.document, pdoc)
const rootpath = "tests/html5lib-tests/tree-construction/"
proc runTests(filename: string) =
let factory = newMAtomFactory()
let tests = parseTests(readFile(rootpath & filename), factory)
for test in tests:
case test.script
of SCRIPT_OFF:
test.runTest(factory, scripting = false)
of SCRIPT_ON:
test.runTest(factory, scripting = true)
of SCRIPT_BOTH:
test.runTest(factory, scripting = false)
test.runTest(factory, scripting = true)
test "tests1.dat":
runTests("tests1.dat")
test "tests2.dat":
runTests("tests2.dat")
test "tests3.dat":
runTests("tests3.dat")
test "tests4.dat":
runTests("tests4.dat")
test "tests5.dat":
runTests("tests5.dat")
test "tests6.dat":
runTests("tests6.dat")
test "tests7.dat":
runTests("tests7.dat")
test "tests8.dat":
runTests("tests8.dat")
test "tests9.dat":
runTests("tests9.dat")
test "tests10.dat":
runTests("tests10.dat")
test "tests11.dat":
runTests("tests11.dat")
test "tests12.dat":
runTests("tests12.dat")
# no tests13 in html5lib-tests :)
test "tests14.dat":
runTests("tests14.dat")
test "tests15.dat":
runTests("tests15.dat")
test "tests16.dat":
runTests("tests16.dat")
test "tests17.dat":
runTests("tests17.dat")
|