diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-07-16 10:11:35 -0700 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2020-07-19 10:25:55 -0400 |
commit | 05bf811c2839628aaef3d565daedb28be80d47ef (patch) | |
tree | 7d698b91dbd823306db5efc752e9cae3e4f6b569 /test/ruby/test_range.rb | |
parent | d637208abd0ae7ccf0539679ca52df1caada4db7 (diff) |
Special case Range#max for integer beginning and Float::Infinity end
Popular Ruby libraries such as Rails and Rubocop relying on the
previous behavior, even though it is technically a bug. The
correct behavior is probably raising RangeError, since that is what
an endless range raises.
Related to [Bug #17017]
Diffstat (limited to 'test/ruby/test_range.rb')
-rw-r--r-- | test/ruby/test_range.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 0b3f6c68f6..0dc66445e9 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -131,6 +131,9 @@ class TestRange < Test::Unit::TestCase assert_equal(2, (..2).max) assert_raise(TypeError) { (...2).max } assert_raise(TypeError) { (...2.0).max } + + assert_equal(Float::INFINITY, (1..Float::INFINITY).max) + assert_nil((1..-Float::INFINITY).max) end def test_minmax @@ -157,6 +160,9 @@ class TestRange < Test::Unit::TestCase assert_equal(['a', 'c'], ('a'..'c').minmax) assert_equal(['a', 'b'], ('a'...'c').minmax) + + assert_equal([1, Float::INFINITY], (1..Float::INFINITY).minmax) + assert_equal([nil, nil], (1..-Float::INFINITY).minmax) end def test_initialize_twice |