@@ -416,10 +416,49 @@ def test_preceding
416
416
assert_equal ( 4 , cs . length )
417
417
end
418
418
419
+ def test_preceding_multiple
420
+ d = REXML ::Document . new ( "<a><b/><c/><d/><d/><e/><f/></a>" )
421
+ matches = REXML ::XPath . match ( d , "a/d/preceding::node()" )
422
+ assert_equal ( [ "d" , "c" , "b" ] , matches . map ( &:name ) )
423
+ end
424
+
425
+ def test_following_multiple
426
+ d = REXML ::Document . new ( "<a><b/><c/><d/><d/><e/><f/></a>" )
427
+ matches = REXML ::XPath . match ( d , "a/d/following::node()" )
428
+ assert_equal ( [ "d" , "e" , "f" ] , matches . map ( &:name ) )
429
+ end
430
+
431
+ def test_following_sibling
432
+ d = REXML ::Document . new ( "<a><b><x/><c/><d/></b><b><x/><e/></b></a>" )
433
+ matches = REXML ::XPath . match ( d , "a/b/x/following-sibling::node()" )
434
+ assert_equal ( [ "c" , "d" , "e" ] , matches . map ( &:name ) )
435
+
436
+ d = REXML ::Document . new ( "
437
+ <div>
438
+ <div>
439
+ <a/><w/>
440
+ </div>
441
+ <a/><x/>
442
+ <a/><y/>
443
+ <a/><z/>
444
+ </div>" )
445
+ # Finds a node flowing <a/>
446
+ matches = REXML ::XPath . match ( d , "//a/following-sibling::*[1]" )
447
+ assert_equal ( [ "w" , "x" , "y" , "z" ] , matches . map ( &:name ) )
448
+
449
+ d = REXML ::Document . new ( "<a><b><x/><c/><d/><x/><e/></b></a>" )
450
+ matches = REXML ::XPath . match ( d , "a/b/x/following-sibling::node()" )
451
+ assert_equal ( [ "c" , "d" , "x" , "e" ] , matches . map ( &:name ) )
452
+ end
453
+
419
454
def test_preceding_sibling
420
455
d = REXML ::Document . new ( "<a><b><c/><d/><x/></b><b><e/><x/></b></a>" )
421
456
matches = REXML ::XPath . match ( d , "a/b/x/preceding-sibling::node()" )
422
457
assert_equal ( [ "e" , "d" , "c" ] , matches . map ( &:name ) )
458
+
459
+ d = REXML ::Document . new ( "<a><b><c/><d/><x/><e/><x/></b></a>" )
460
+ matches = REXML ::XPath . match ( d , "a/b/x/preceding-sibling::node()" )
461
+ assert_equal ( [ "e" , "x" , "d" , "c" ] , matches . map ( &:name ) )
423
462
end
424
463
425
464
def test_following
0 commit comments