@@ -393,6 +393,26 @@ def test_step_ruby_core_35753
393
393
assert_equal ( 4 , ( 1.0 ...5.6 ) . step ( 1.5 ) . to_a . size )
394
394
end
395
395
396
+ def test_step_with_succ
397
+ c = Struct . new ( :i ) do
398
+ def succ ; self . class . new ( i +1 ) ; end
399
+ def <=>( other ) i <=> other . i ; end
400
+ end . new ( 0 )
401
+
402
+ result = [ ]
403
+ ( c ..c . succ ) . step ( 2 ) do |d |
404
+ result << d . i
405
+ end
406
+ assert_equal ( [ 0 ] , result )
407
+
408
+ result = [ ]
409
+ ( c ..) . step ( 2 ) do |d |
410
+ result << d . i
411
+ break if d . i >= 4
412
+ end
413
+ assert_equal ( [ 0 , 2 , 4 ] , result )
414
+ end
415
+
396
416
def test_each
397
417
a = [ ]
398
418
( 0 ..10 ) . each { |x | a << x }
@@ -457,6 +477,26 @@ def <=>(other) to_str <=> other end
457
477
assert_equal ( [ "a" , "b" , "c" ] , a )
458
478
end
459
479
480
+ def test_each_with_succ
481
+ c = Struct . new ( :i ) do
482
+ def succ ; self . class . new ( i +1 ) ; end
483
+ def <=>( other ) i <=> other . i ; end
484
+ end . new ( 0 )
485
+
486
+ result = [ ]
487
+ ( c ..c . succ ) . each do |d |
488
+ result << d . i
489
+ end
490
+ assert_equal ( [ 0 , 1 ] , result )
491
+
492
+ result = [ ]
493
+ ( c ..) . each do |d |
494
+ result << d . i
495
+ break if d . i >= 4
496
+ end
497
+ assert_equal ( [ 0 , 1 , 2 , 3 , 4 ] , result )
498
+ end
499
+
460
500
def test_begin_end
461
501
assert_equal ( 0 , ( 0 ..1 ) . begin )
462
502
assert_equal ( 1 , ( 0 ..1 ) . end )
0 commit comments