@@ -65,6 +65,28 @@ func Test_ancestor_predicate(t *testing.T) {
6565 test_xpath_elements (t , doc , `//span/ancestor::section[2]` , 4 , 9 )
6666}
6767
68+ func Test_ancestor_predicate_chain (t * testing.T ) {
69+ doc := createElement (0 , "" ,
70+ createElement (1 , "html" ,
71+ createElementAttr (2 , "body" , map [string ]string {"itemscope" : "" , "itemtype" : "Article" },
72+ createElement (3 , "section" ,
73+ createElementAttr (4 , "span" , map [string ]string {"itemprop" : "author" }),
74+ createElementAttr (5 , "div" , map [string ]string {"itemscope" : "" , "itemtype" : "Comment" },
75+ createElementAttr (6 , "span" , map [string ]string {"itemprop" : "author" }),
76+ createElement (7 , "div" ,
77+ createElementAttr (8 , "span" , map [string ]string {"itemprop" : "author" }),
78+ ),
79+ ),
80+ ),
81+ ),
82+ ),
83+ )
84+
85+ // Find elements marked as "author" property whose closest "itemscope" ancestor is of "Comment" type.
86+ // This should find "span" elements on lines 6 and 8, but not line 4 since that one is under "Article".
87+ test_xpath_elements (t , doc , `//*[@itemprop="author"][ancestor::*[@itemscope][1][@itemtype="Comment"]]` , 6 , 8 )
88+ }
89+
6890func Test_ancestor_or_self (t * testing.T ) {
6991 // Expected the value is [2, 3, 8, 13], but got [3, 2, 8, 13]
7092 test_xpath_elements (t , employee_example , `//employee/ancestor-or-self::*` , 3 , 2 , 8 , 13 )
0 commit comments