@@ -32,6 +32,39 @@ func Test_ancestor(t *testing.T) {
3232 //test_xpath_elements(t, employee_example, `//ancestor::name`, 4, 9, 14)
3333}
3434
35+ func Test_ancestor_predicate (t * testing.T ) {
36+ doc := createElement (0 , "" ,
37+ createElement (1 , "html" ,
38+ createElement (2 , "body" ,
39+ createElement (3 , "h1" ),
40+ createElement (4 , "section" ,
41+ createElement (5 , "div" ,
42+ createElement (6 , "section" ,
43+ createElement (7 , "div" ,
44+ createElement (8 , "span" ),
45+ ),
46+ ),
47+ ),
48+ ),
49+ createElement (9 , "section" ,
50+ createElement (10 , "div" ,
51+ createElement (11 , "section" ,
52+ createElement (12 , "div" ,
53+ createElement (13 , "span" ),
54+ ),
55+ ),
56+ ),
57+ ),
58+ ),
59+ ),
60+ )
61+
62+ test_xpath_elements (t , doc , `//span/ancestor::*` , 7 , 6 , 5 , 4 , 2 , 1 , 12 , 11 , 10 , 9 )
63+ test_xpath_elements (t , doc , `//span/ancestor::section` , 6 , 4 , 11 , 9 )
64+ test_xpath_elements (t , doc , `//span/ancestor::section[1]` , 6 , 11 )
65+ test_xpath_elements (t , doc , `//span/ancestor::section[2]` , 4 , 9 )
66+ }
67+
3568func Test_ancestor_or_self (t * testing.T ) {
3669 // Expected the value is [2, 3, 8, 13], but got [3, 2, 8, 13]
3770 test_xpath_elements (t , employee_example , `//employee/ancestor-or-self::*` , 3 , 2 , 8 , 13 )
0 commit comments