diff --git a/tst/init.lua b/tst/init.lua index fc80b37..7097331 100644 --- a/tst/init.lua +++ b/tst/init.lua @@ -8,38 +8,75 @@ 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.1 - 1.2 - 1.2.1 + 1 + 2 + 3 + + 4 + 2 - 2.1 - 2.2 - 2.2.1 + 5 + 6 + 7 + + 8 + ]]) 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([[ 1 - 1.1 - 1.2 - 1.2.1 + 1 + 2 + not + + not + 2 - 2.1 - 2.2 - 2.2.1 + 3 + 4 + not + + not + ]]) sel = tree("parent > child")