diff --git a/tst/init.lua b/tst/init.lua index e3b164e..44d22f4 100644 --- a/tst/init.lua +++ b/tst/init.lua @@ -31,6 +31,35 @@ function test_void() end end +function test_id() + local tree = htmlparser.parse([[ + + + + ]]) + assert_equal(1, #tree.nodes, "top level") + assert_equal("n", tree("#4711"):tolist()[1].name, "#4711") + assert_equal("m", tree("#1174"):tolist()[1].name, "#1174") +end + +function test_class() + local tree = htmlparser.parse([[ + + + + + + + + ]]) + assert_equal(3, #tree.nodes, "top level") + assert_equal(1, tree(".one"):len(), ".one") + assert_equal(2, tree(".two"):len(), ".two") + assert_equal(2, tree(".three"):len(), ".three") + assert_equal(1, tree(".two.three"):len(), ".two.three") + assert_equal(0, tree(".four"):len(), ".four") +end + function test_attr() local tree = htmlparser.parse([[ ]]) assert_equal(4, tree("parent > child"):len(), 'parent > child') -end \ No newline at end of file +end + +function test_not() + local tree = htmlparser.parse([[ + + + + + ]]) + assert_equal(2, #tree.nodes, "top level") + assert_equal(1, tree(":not([a1=1])"):len(), ":not([a1=1])") + assert_equal(1, tree(":not([a2])"):len(), ":not([a2])") + assert_equal(1, tree(":not(n)"):len(), ":not(n)") + assert_equal(2, tree(":not(m)"):len(), ":not(m)") +end + +function test_combine() + local tree = htmlparser.parse([[ + + + + + + + + + ]]) + assert_equal(2, #tree.nodes, "top level") + assert_equal(2, tree("e.c:not([a|='1']) > n[b*='2']"):len(), "e.c:not([a|='1']) > n[b*='2']") + assert_equal(3, tree("e.c:not([a|='1']) n[b*='2']"):len(), "e.c:not([a|='1']) n[b*='2']") + assert_equal(1, tree("#123 .c[b]"):len(), "#123 .c[b]") +end