about summary refs log tree commit diff stats
path: root/lib/chame0/test/tree.nim
blob: 87731f62175c3d9d1d3c170cde41be94180471f6 (plain) (blame)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
include shared/tree_common

import std/streams

proc runTest(test: TCTest, factory: MAtomFactory, scripting, print: 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(childList: ctx.childList)
  if print:
    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 = "test/html5lib-tests/tree-construction/"

proc runTests(filename: string, print = false) =
  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, print = print)
    of SCRIPT_ON:
      test.runTest(factory, scripting = true, print = print)
    of SCRIPT_BOTH:
      test.runTest(factory, scripting = false, print = print)
      test.runTest(factory, scripting = true, print = print)

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")

test "tests18.dat":
  runTests("tests18.dat")

test "tests19.dat":
  runTests("tests19.dat")

test "tests20.dat":
  runTests("tests20.dat")

test "tests21.dat":
  runTests("tests21.dat")

test "tests22.dat":
  runTests("tests22.dat")

test "tests23.dat":
  runTests("tests23.dat")

test "tests24.dat":
  runTests("tests24.dat")

test "tests25.dat":
  runTests("tests25.dat")

test "tests26.dat":
  runTests("tests26.dat")

test "adoption01.dat":
  runTests("adoption01.dat")

test "adoption02.dat":
  runTests("adoption02.dat")

test "blocks.dat":
  runTests("blocks.dat")

test "comments01.dat":
  runTests("comments01.dat")

test "doctype01.dat":
  runTests("doctype01.dat")

test "domjs-unsafe.dat":
  runTests("domjs-unsafe.dat")

test "entities01.dat":
  runTests("entities01.dat")

test "entities02.dat":
  runTests("entities02.dat")

test "foreign-fragment.dat":
  runTests("foreign-fragment.dat")

test "html5test-com.dat":
  runTests("html5test-com.dat")

test "inbody01.dat":
  runTests("inbody01.dat")

test "isindex.dat":
  runTests("isindex.dat")

test "main-element.dat":
  runTests("main-element.dat")

test "math.dat":
  runTests("math.dat")

test "menuitem-element.dat":
  runTests("menuitem-element.dat")

test "namespace-sensitivity.dat":
  runTests("namespace-sensitivity.dat")

test "noscript01.dat":
  runTests("noscript01.dat")

test "pending-spec-changes.dat":
  runTests("pending-spec-changes.dat")

test "pending-spec-changes-plain-text-unsafe.dat":
  runTests("pending-spec-changes-plain-text-unsafe.dat")

test "plain-text-unsafe.dat":
  runTests("plain-text-unsafe.dat")

test "quirks01.dat":
  runTests("quirks01.dat")

test "ruby.dat":
  runTests("ruby.dat")

test "scriptdata01.dat":
  runTests("scriptdata01.dat")

test "search-element.dat":
  runTests("search-element.dat")

test "svg.dat":
  runTests("svg.dat")

test "tables01.dat":
  runTests("tables01.dat")

test "template.dat":
  runTests("template.dat")

test "tests_innerHTML_1.dat":
  runTests("tests_innerHTML_1.dat")

test "tricky01.dat":
  runTests("tricky01.dat")

test "webkit01.dat":
  runTests("webkit01.dat")

test "webkit02.dat":
  runTests("webkit02.dat")