@@ -575,18 +575,45 @@ def test_nested_predicates
575575 matches = XPath . match ( doc , '(/div/div/test[3])' ) . map ( &:text )
576576 assert_equal [ ] , matches
577577
578+ matches = XPath . match ( doc , '/div/div/test[1][1]' ) . map ( &:text )
579+ assert_equal [ "ab" , "ef" , "hi" ] , matches
578580 matches = XPath . match ( doc , '(/div/div/test[1])[1]' ) . map ( &:text )
579581 assert_equal [ "ab" ] , matches
582+ matches = XPath . match ( doc , '/div/div/test[1][2]' ) . map ( &:text )
583+ assert_equal [ ] , matches
580584 matches = XPath . match ( doc , '(/div/div/test[1])[2]' ) . map ( &:text )
581585 assert_equal [ "ef" ] , matches
582586 matches = XPath . match ( doc , '(/div/div/test[1])[3]' ) . map ( &:text )
583587 assert_equal [ "hi" ] , matches
588+ matches = XPath . match ( doc , '/div/div/test[2][1]' ) . map ( &:text )
589+ assert_equal [ "cd" , "gh" ] , matches
584590 matches = XPath . match ( doc , '(/div/div/test[2])[1]' ) . map ( &:text )
585591 assert_equal [ "cd" ] , matches
592+ matches = XPath . match ( doc , '/div/div/test[2][2]' ) . map ( &:text )
593+ assert_equal [ ] , matches
586594 matches = XPath . match ( doc , '(/div/div/test[2])[2]' ) . map ( &:text )
587595 assert_equal [ "gh" ] , matches
588596 matches = XPath . match ( doc , '(/div/div/test[2])[3]' ) . map ( &:text )
589597 assert_equal [ ] , matches
598+ matches = XPath . match ( doc , '//div[1]/test|//div[2]/test[2]' ) . map ( &:text )
599+ assert_equal [ "ab" , "cd" , "gh" ] , matches
600+ matches = XPath . match ( doc , '(//div[1]/test|//div[2]/test)[2]' ) . map ( &:text )
601+ assert_equal [ "cd" ] , matches
602+
603+ xpath = '/div/div/test/preceding::*'
604+ without_parentheses = XPath . match ( doc , xpath ) . map ( &:text )
605+ with_parentheses = XPath . match ( doc , "(#{ xpath } )" ) . map ( &:text )
606+ assert_equal without_parentheses , with_parentheses
607+
608+ xpath = '/div/div/test/preceding-sibling::*'
609+ without_parentheses = XPath . match ( doc , xpath ) . map ( &:text )
610+ with_parentheses = XPath . match ( doc , "(#{ xpath } )" ) . map ( &:text )
611+ assert_equal without_parentheses , with_parentheses
612+
613+ xpath = '/div/div/test/ancestor::*'
614+ without_parentheses = XPath . match ( doc , xpath ) . map ( &:text )
615+ with_parentheses = XPath . match ( doc , "(#{ xpath } )" ) . map ( &:text )
616+ assert_equal without_parentheses , with_parentheses
590617 end
591618
592619 # Contributed by Mike Stok
0 commit comments