-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest-html-build.lua
More file actions
115 lines (106 loc) · 3.07 KB
/
test-html-build.lua
File metadata and controls
115 lines (106 loc) · 3.07 KB
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
local luaunit = require("luaunit")
local HTML = require("xmlua.html")
local ffi = require("ffi")
TestHTMLBuild = {}
function TestHTMLBuild.test_empty()
local document = HTML.build({})
luaunit.assertEquals(document:to_html(),
[[
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
]])
end
function TestHTMLBuild.test_empty_root()
local document = HTML.build({"html"})
luaunit.assertEquals(document:to_html(),
[[
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html></html>
]])
end
function TestHTMLBuild.test_empty_root_dtd_systemid()
local uri = "file:///usr/local/share/test.dtd"
local document = HTML.build({"html"}, uri)
luaunit.assertEquals({
ffi.string(document.raw_document.intSubset.SystemID),
document:to_html()
},
{
uri,
[[
<!DOCTYPE html SYSTEM "file:///usr/local/share/test.dtd">
<html></html>
]]
})
end
function TestHTMLBuild.test_empty_root_dtd_publicid()
local uri = "http://www.w3.org/TR/html4/strict.dtd"
local public_id = "-//W3C//DTD HTML 4.01//EN"
local document = HTML.build({"html"}, uri, public_id)
luaunit.assertEquals({
ffi.string(document.raw_document.intSubset.SystemID),
ffi.string(document.raw_document.intSubset.ExternalID),
document:to_html()
},
{
uri,
public_id,
[[
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html></html>
]]
})
end
function TestHTMLBuild.test_root_children()
local tree = {
"html",
{},
{
"body",
},
}
local document = HTML.build(tree)
luaunit.assertEquals(document:to_html(),
[[
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body></body></html>
]])
end
function TestHTMLBuild.test_nested()
local tree = {
"html",
{
["lang"] = "ja",
},
{
"title",
{},
"This is Test Page!",
}
}
local document = HTML.build(tree)
luaunit.assertEquals(document:to_html(),
[[
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="ja"><title>This is Test Page!</title></html>
]])
end
function TestHTMLBuild.test_texts()
local tree = {
"html",
{},
{
"div",
{
["class"] = "A"
},
"text1",
"text2",
},
}
local document = HTML.build(tree)
luaunit.assertEquals(document:to_html(),
[[
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><div class="A">text1text2</div></html>
]])
end