summaryrefslogtreecommitdiff
path: root/test/ruby/test_range.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2025-01-13 02:07:05 +0900
committerNobuyoshi Nakada <[email protected]>2025-01-13 02:07:05 +0900
commitf56f3eaae55cc6f8d9e79862ee73a9ffb53d6077 (patch)
treea151966f5017d91f6904d0dcbf634ccb52ff207d /test/ruby/test_range.rb
parentd9e1a7cdf8a6e8327cd09a891fd45d6af357f926 (diff)
[Bug #21030] Fix step for non-numeric range
When the end points of an inclusive range equal, `Range#step` should yields the element once.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12559
Diffstat (limited to 'test/ruby/test_range.rb')
-rw-r--r--test/ruby/test_range.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 480f213029..10d69ea2df 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -594,6 +594,22 @@ class TestRange < Test::Unit::TestCase
assert_equal(4, (1.0...5.6).step(1.5).to_a.size)
end
+ def test_step_with_nonnumeric_endpoint
+ num = Data.define(:value) do
+ def coerce(o); [o, 100]; end
+ def <=>(o) value<=>o; end
+ def +(o) with(value: value + o) end
+ end
+ i = num.new(100)
+
+ assert_equal([100], (100..100).step(10).to_a)
+ assert_equal([], (100...100).step(10).to_a)
+ assert_equal([100], (100..i).step(10).to_a)
+ assert_equal([i], (i..100).step(10).to_a)
+ assert_equal([], (100...i).step(10).to_a)
+ assert_equal([], (i...100).step(10).to_a)
+ end
+
def test_each
a = []
(0..10).each {|x| a << x }