summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKenichi Kamiya <kachick1@gmail.com>2019-10-17 17:44:46 +0900
committerKazuhiro NISHIYAMA <znz@users.noreply.github.com>2019-10-17 17:44:46 +0900
commit2a22a6b2d8465934e75520a7fdcf522d50890caf (patch)
tree49135af238d55ebe13195dc1fd36c3604749adb3 /test
parent41457dcbe050a698c357b516d0a012b1b584643a (diff)
Regexp#match{?} with nil raises TypeError as String, Symbol (#1506)
* {String|Symbol}#match{?} with nil returns falsy To improve consistency with Regexp#match{?} * String#match(nil) returns `nil` instead of TypeError * String#match?(nil) returns `false` instead of TypeError * Symbol#match(nil) returns `nil` instead of TypeError * Symbol#match?(nil) returns `false` instead of TypeError * Prefer exception * Follow empty ENV * Drop outdated specs * Write ruby/spec for above https://github.com/ruby/ruby/pull/1506/files#r183242981 * Fix merge miss
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_regexp.rb4
-rw-r--r--test/ruby/test_string.rb5
-rw-r--r--test/ruby/test_symbol.rb5
3 files changed, 12 insertions, 2 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 6cfd7df824..03e94a7464 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -539,7 +539,7 @@ class TestRegexp < Test::Unit::TestCase
end
def test_match
- assert_nil(//.match(nil))
+ assert_raise(TypeError) { //.match(nil) }
assert_equal("abc", /.../.match(:abc)[0])
assert_raise(TypeError) { /.../.match(Object.new)[0] }
assert_equal("bc", /../.match('abc', 1)[0])
@@ -561,10 +561,10 @@ class TestRegexp < Test::Unit::TestCase
/backref/ =~ 'backref'
# must match here, but not in a separate method, e.g., assert_send,
# to check if $~ is affected or not.
- assert_equal(false, //.match?(nil))
assert_equal(true, //.match?(""))
assert_equal(true, /.../.match?(:abc))
assert_raise(TypeError) { /.../.match?(Object.new) }
+ assert_raise(TypeError) { //.match?(nil) }
assert_equal(true, /b/.match?('abc'))
assert_equal(true, /b/.match?('abc', 1))
assert_equal(true, /../.match?('abc', 1))
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index dd403bf9d9..41d4871379 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -2512,6 +2512,7 @@ CODE
def test_match_method
assert_equal("bar", "foobarbaz".match(/bar/).to_s)
+ assert_raise(TypeError) { "".match(nil) }
o = Regexp.new('foo')
def o.match(x, y, z); x + y + z; end
@@ -2567,6 +2568,10 @@ CODE
assert_equal('backref', $&)
end
+ def test_match_p_nil
+ assert_raise(TypeError) { ''.match?(nil) }
+ end
+
def test_clear
s = "foo" * 100
s.clear
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index 13d7cc9d57..d657f1aae6 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -367,6 +367,7 @@ class TestSymbol < Test::Unit::TestCase
def test_match_method
assert_equal("bar", :"foobarbaz".match(/bar/).to_s)
+ assert_raise(TypeError) { :"".match(nil) }
o = Regexp.new('foo')
def o.match(x, y, z); x + y + z; end
@@ -420,6 +421,10 @@ class TestSymbol < Test::Unit::TestCase
assert_equal('backref', $&)
end
+ def test_match_p_nil
+ assert_raise(TypeError) { :''.match?(nil) }
+ end
+
def test_symbol_popped
assert_nothing_raised { eval('a = 1; :"#{ a }"; 1') }
end