@@ -451,6 +451,46 @@ def test_following
451
451
# puts results
452
452
#end
453
453
454
+ def test_nested_predicates
455
+ doc = Document . new <<-EOF
456
+ <div>
457
+ <div>
458
+ <test>ab</test>
459
+ <test>cd</test>
460
+ </div>
461
+ <div>
462
+ <test>ef</test>
463
+ <test>gh</test>
464
+ </div>
465
+ <div>
466
+ <test>hi</test>
467
+ </div>
468
+ </div>
469
+ EOF
470
+
471
+ matches = XPath . match ( doc , '(/div/div/test[0])' ) . map ( &:text )
472
+ assert_equal [ ] , matches
473
+ matches = XPath . match ( doc , '(/div/div/test[1])' ) . map ( &:text )
474
+ assert_equal [ "ab" , "ef" , "hi" ] , matches
475
+ matches = XPath . match ( doc , '(/div/div/test[2])' ) . map ( &:text )
476
+ assert_equal [ "cd" , "gh" ] , matches
477
+ matches = XPath . match ( doc , '(/div/div/test[3])' ) . map ( &:text )
478
+ assert_equal [ ] , matches
479
+
480
+ matches = XPath . match ( doc , '(/div/div/test[1])[1]' ) . map ( &:text )
481
+ assert_equal [ "ab" ] , matches
482
+ matches = XPath . match ( doc , '(/div/div/test[1])[2]' ) . map ( &:text )
483
+ assert_equal [ "ef" ] , matches
484
+ matches = XPath . match ( doc , '(/div/div/test[1])[3]' ) . map ( &:text )
485
+ assert_equal [ "hi" ] , matches
486
+ matches = XPath . match ( doc , '(/div/div/test[2])[1]' ) . map ( &:text )
487
+ assert_equal [ "cd" ] , matches
488
+ matches = XPath . match ( doc , '(/div/div/test[2])[2]' ) . map ( &:text )
489
+ assert_equal [ "gh" ] , matches
490
+ matches = XPath . match ( doc , '(/div/div/test[2])[3]' ) . map ( &:text )
491
+ assert_equal [ ] , matches
492
+ end
493
+
454
494
# Contributed by Mike Stok
455
495
def test_starts_with
456
496
source = <<-EOF
0 commit comments