-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.lua
56 lines (41 loc) · 1.91 KB
/
test.lua
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
local h = require'html'
local function test(msg, expected, actual)
assert(expected==tostring(actual), string.format("Failed test: %s:\n expected: %s\n actual: %s", msg, expected, actual))
end
test("Empty element", "<span></span>", h.span)
local voids = {'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'}
for i=1,#voids do
test("Void elements unclosed", "<"..voids[i]..">", h[voids[i]])
end
test("Class name",'<a class="c"></a>', h.a.class'c')
test("No mutation on attrs", '<a id="test"></a><a></a>',h(function(_ENV)
local custom = a.id'test'
return custom .. a
end))
test("No mutation on content", '<a>content1</a><a>content2</a>', h(function(_ENV)
local content1 = a'content1'
local content2 = a'content2'
return content1 .. content2
end))
test('add content to existing', '<a class="test">c1</a><a class="test">c2</a>', h(function(_ENV)
local custom = a.class'test'
return custom'c1' .. custom'c2'
end))
test('add attrs to existing', '<a class="test">c1</a><a>c1</a>', h(function(_ENV)
local custom = a'c1'
return custom.class'test' .. custom
end))
test('call appends content', '<a>c1c2</a>', h(function(_ENV)
return a 'c1' 'c2'
end))
test('content as a table', '<a>abc</a>',h(function(_ENV)
return a {'a','b','c'}
end))
test('multiple concats', '<br><img><area>', h.br .. h.img .. h.area)
test('concat with string', '<p>Hello <strong>there</strong>!</p>', h.p{"Hello " .. h.strong"there" .. "!"})
test('multiple calls', '<p>1234567</p>', h.p {1,2,3} {4,5,6} '7')
test('escapes attribute values', '<p class="&"></p>', h.p.class'&')
test('escapes attribute values', '<p class="<"></p>', h.p.class'<')
test('escapes attribute values', '<p class=">"></p>', h.p.class'>')
test('escapes attribute values', '<p class="""></p>', h.p.class'"')
test('url encoding', 'http://example.com/page?test=%3D',h.url'http://example.com/page%q'{test='='})