* re.c (rb_reg_match_m_p): Introduce Regexp#match?, which returns

bool and doesn't save backref.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2016-05-18 10:37:13 +00:00
parent 898aeb8779
commit f09574c879
4 changed files with 98 additions and 0 deletions

View file

@ -526,6 +526,19 @@ class TestRegexp < Test::Unit::TestCase
$_ = nil; assert_nil(~/./)
end
def test_match_p
/backref/ =~ 'backref'
assert_nil(//.match?(nil))
assert_equal(true, /.../.match?(:abc))
assert_raise(TypeError) { /.../.match?(Object.new) }
assert_equal(true, /../.match?('abc', 1))
assert_equal(true, /../.match?('abc', -2))
assert_nil(/../.match?("abc", -4))
assert_nil(/../.match?("abc", 4))
assert_equal(true, /../n.match?("\u3042" + '\x', 1))
assert_equal('backref', $&)
end
def test_eqq
assert_equal(false, /../ === nil)
end