require("luarocks.loader")
-- Omit next line in actual module clients; it's only to support development of the module itself
package.path = "../src/?.lua;" .. package.path
local lunitx = require("lunitx")
module("html", lunitx.testcase, package.seeall)
local htmlparser = require("htmlparser")
local tree, sel
function test_void()
tree = htmlparser.parse([[
]])
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([[
1
1
2
3
4
2
5
6
7
8
]])
sel = tree("parent child")
assert_equal(8, sel:len(), 'parent child')
end
function test_children()
tree = htmlparser.parse([[
1
1
2
not
not
2
3
4
not
not
]])
sel = tree("parent > child")
assert_equal(4, sel:len(), 'parent > child')
end