@@ -416,12 +416,89 @@ def test_preceding
416
416
assert_equal ( 4 , cs . length )
417
417
end
418
418
419
- def test_preceding_sibling
420
- d = REXML ::Document . new ( "<a><b><c/><d/><x/></b><b><e/><x/></b></a>" )
419
+ def test_preceding_multiple
420
+ d = REXML ::Document . new ( "
421
+ <a>
422
+ <b/><c/><d/><d/><e/><f/>
423
+ </a>" )
424
+ matches = REXML ::XPath . match ( d , "a/d/preceding::node()" )
425
+ assert_equal ( [ "d" , "c" , "b" ] , matches . map ( &:name ) )
426
+ end
427
+
428
+ def test_following_multiple
429
+ d = REXML ::Document . new ( "
430
+ <a>
431
+ <b/><c/><d/><d/><e/><f/>
432
+ </a>" )
433
+ matches = REXML ::XPath . match ( d , "a/d/following::node()" )
434
+ assert_equal ( [ "d" , "e" , "f" ] , matches . map ( &:name ) )
435
+ end
436
+
437
+ def test_following_sibling_across_multiple_nodes
438
+ d = REXML ::Document . new ( "
439
+ <a>
440
+ <b>
441
+ <x/><c/><d/>
442
+ </b>
443
+ <b>
444
+ <x/><e/>
445
+ </b>
446
+ </a>" )
447
+ matches = REXML ::XPath . match ( d , "a/b/x/following-sibling::node()" )
448
+ assert_equal ( [ "c" , "d" , "e" ] , matches . map ( &:name ) )
449
+ end
450
+
451
+ def test_following_sibling_within_single_node
452
+ d = REXML ::Document . new ( "
453
+ <a>
454
+ <b>
455
+ <x/><c/><d/><x/><e/>
456
+ </b>
457
+ </a>" )
458
+ matches = REXML ::XPath . match ( d , "a/b/x/following-sibling::node()" )
459
+ assert_equal ( [ "c" , "d" , "x" , "e" ] , matches . map ( &:name ) )
460
+ end
461
+
462
+ def test_following_sibling_predicates
463
+ d = REXML ::Document . new ( "
464
+ <div>
465
+ <div>
466
+ <a/><w/>
467
+ </div>
468
+ <a/><x/>
469
+ <a/><y/>
470
+ <a/><z/>
471
+ </div>" )
472
+ # Finds a node flowing <a/>
473
+ matches = REXML ::XPath . match ( d , "//a/following-sibling::*[1]" )
474
+ assert_equal ( [ "w" , "x" , "y" , "z" ] , matches . map ( &:name ) )
475
+ end
476
+
477
+ def test_preceding_sibling_across_multiple_nodes
478
+ d = REXML ::Document . new ( "
479
+ <a>
480
+ <b>
481
+ <c/><d/><x/>
482
+ </b>
483
+ <b>
484
+ <e/><x/>
485
+ </b>
486
+ </a>" )
421
487
matches = REXML ::XPath . match ( d , "a/b/x/preceding-sibling::node()" )
422
488
assert_equal ( [ "e" , "d" , "c" ] , matches . map ( &:name ) )
423
489
end
424
490
491
+ def test_preceding_sibling_within_single_node
492
+ d = REXML ::Document . new ( "
493
+ <a>
494
+ <b>
495
+ <c/><d/><x/><e/><x/>
496
+ </b>
497
+ </a>" )
498
+ matches = REXML ::XPath . match ( d , "a/b/x/preceding-sibling::node()" )
499
+ assert_equal ( [ "e" , "x" , "d" , "c" ] , matches . map ( &:name ) )
500
+ end
501
+
425
502
def test_following
426
503
d = Document . new "<a><b id='0'/><b/><b><c id='1'/><c id='2'/></b><b id='1'/></a>"
427
504
start = XPath . first ( d , "/a/b[@id='0']" )
0 commit comments