summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2022-08-19 13:19:03 -0700
committerJeremy Evans <code@jeremyevans.net>2022-11-24 15:18:44 -0800
commit04a92a6764bf678919cf4b68a27496a39d6b886a (patch)
tree19a5548772dd56562e44f29e99f9e445f2a53eff /test
parentd15de2f0d73d452d1db582ab9634c3edcf77bb41 (diff)
Raise TypeError for endless non-numeric range include?
Beginless ranges previously raised TypeError for this case, except for string ranges, which had unexpected behavior: ('a'..'z').include?('ww') # false (..'z').include?('ww') # previously true, now TypeError Use of include? with endless ranges could previously result in an infinite loop. This splits off a range_string_cover_internal function from range_include_internal. Fixes [Bug #18580]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6261
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_range.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 2c07cef96e..bb5ef6df8f 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -546,7 +546,7 @@ class TestRange < Test::Unit::TestCase
assert_not_operator('A'..'Z', :===, 'ana')
assert_operator('A'.., :===, 'ANA')
assert_operator(..'Z', :===, 'ANA')
- assert_operator(nil..nil, :===, 'ANA')
+ assert_raise(TypeError) {(nil..nil) === 'ANA'}
end
def test_eqq_time
@@ -599,13 +599,14 @@ class TestRange < Test::Unit::TestCase
assert_include("a"..."z", "y")
assert_not_include("a"..."z", "z")
assert_not_include("a".."z", "cc")
- assert_include("a".., "c")
- assert_not_include("a".., "5")
+ assert_raise(TypeError) {("a"..).include?("c")}
+ assert_raise(TypeError) {("a"..).include?("5")}
+
assert_include(0...10, 5)
assert_include(5..., 10)
assert_not_include(5..., 0)
- assert_include(.."z", "z")
- assert_not_include(..."z", "z")
+ assert_raise(TypeError) {(.."z").include?("z")}
+ assert_raise(TypeError) {(..."z").include?("z")}
assert_include(..10, 10)
assert_not_include(...10, 10)
end