@@ -582,18 +582,45 @@ def test_nested_predicates
582582 matches = XPath . match ( doc , '(/div/div/test[3])' ) . map ( &:text )
583583 assert_equal [ ] , matches
584584
585+ matches = XPath . match ( doc , '/div/div/test[1][1]' ) . map ( &:text )
586+ assert_equal [ "ab" , "ef" , "hi" ] , matches
585587 matches = XPath . match ( doc , '(/div/div/test[1])[1]' ) . map ( &:text )
586588 assert_equal [ "ab" ] , matches
589+ matches = XPath . match ( doc , '/div/div/test[1][2]' ) . map ( &:text )
590+ assert_equal [ ] , matches
587591 matches = XPath . match ( doc , '(/div/div/test[1])[2]' ) . map ( &:text )
588592 assert_equal [ "ef" ] , matches
589593 matches = XPath . match ( doc , '(/div/div/test[1])[3]' ) . map ( &:text )
590594 assert_equal [ "hi" ] , matches
595+ matches = XPath . match ( doc , '/div/div/test[2][1]' ) . map ( &:text )
596+ assert_equal [ "cd" , "gh" ] , matches
591597 matches = XPath . match ( doc , '(/div/div/test[2])[1]' ) . map ( &:text )
592598 assert_equal [ "cd" ] , matches
599+ matches = XPath . match ( doc , '/div/div/test[2][2]' ) . map ( &:text )
600+ assert_equal [ ] , matches
593601 matches = XPath . match ( doc , '(/div/div/test[2])[2]' ) . map ( &:text )
594602 assert_equal [ "gh" ] , matches
595603 matches = XPath . match ( doc , '(/div/div/test[2])[3]' ) . map ( &:text )
596604 assert_equal [ ] , matches
605+ matches = XPath . match ( doc , '//div[1]/test|//div[2]/test[2]' ) . map ( &:text )
606+ assert_equal [ "ab" , "cd" , "gh" ] , matches
607+ matches = XPath . match ( doc , '(//div[1]/test|//div[2]/test)[2]' ) . map ( &:text )
608+ assert_equal [ "cd" ] , matches
609+
610+ xpath = '/div/div/test/preceding::*'
611+ without_parentheses = XPath . match ( doc , xpath ) . map ( &:text )
612+ with_parentheses = XPath . match ( doc , "(#{ xpath } )" ) . map ( &:text )
613+ assert_equal without_parentheses , with_parentheses
614+
615+ xpath = '/div/div/test/preceding-sibling::*'
616+ without_parentheses = XPath . match ( doc , xpath ) . map ( &:text )
617+ with_parentheses = XPath . match ( doc , "(#{ xpath } )" ) . map ( &:text )
618+ assert_equal without_parentheses , with_parentheses
619+
620+ xpath = '/div/div/test/ancestor::*'
621+ without_parentheses = XPath . match ( doc , xpath ) . map ( &:text )
622+ with_parentheses = XPath . match ( doc , "(#{ xpath } )" ) . map ( &:text )
623+ assert_equal without_parentheses , with_parentheses
597624 end
598625
599626 # Contributed by Mike Stok
0 commit comments