added test for void elements

This commit is contained in:
Wouter Scherphof 2013-04-02 12:59:44 +02:00
parent 6ec365ac58
commit 2bba6a7189

View File

@ -8,38 +8,75 @@ module("html", lunitx.testcase, package.seeall)
local htmlparser = require("htmlparser")
local tree, sel
function test_void()
tree = htmlparser.parse([[
<p>
<br>
<br/>
<br >
<br />
</p>
<br>
<br/>
<br >
<br />
]])
assert_equal(5, #tree.nodes, "top level")
for _,n in ipairs(tree.nodes) do
if n.name == "p" then
assert_equal(4, #n.nodes, "deeper level")
else
assert_equal("br", n.name, "name")
assert_equal(0, #n.attributes, "attributes")
assert_equal("", n:getcontent(), "content")
end
end
end
function test_descendants()
tree = htmlparser.parse([[
<parent>1
<child>1.1</child>
<child>1.2
<child>1.2.1</child>
<child>1</child>
<child>2
<child>3</child>
</child>
<arbitrary>
<child>4</child>
</arbitrary>
</parent>
<parent>2
<child>2.1</child>
<child>2.2
<child>2.2.1</child>
<child>5</child>
<child>6
<child>7</child>
</child>
<arbitrary>
<child>8</child>
</arbitrary>
</parent>
]])
sel = tree("parent child")
assert_equal(6, sel:len(), 'parent child')
assert_equal(8, sel:len(), 'parent child')
end
function test_children()
tree = htmlparser.parse([[
<parent>1
<child>1.1</child>
<child>1.2
<child>1.2.1</child>
<child>1</child>
<child>2
<child>not</child>
</child>
<arbitrary>
<child>not</child>
</arbitrary>
</parent>
<parent>2
<child>2.1</child>
<child>2.2
<child>2.2.1</child>
<child>3</child>
<child>4
<child>not</child>
</child>
<arbitrary>
<child>not</child>
</arbitrary>
</parent>
]])
sel = tree("parent > child")