summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-18 12:06:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-18 12:06:20 +0000
commit49a272d728c2003064182869cfdbca140f3acc81 (patch)
treeb536a525ef19abb3416888c1348ad939ec32a224 /test/ruby
parent38c0bdccdbc15ea460a4602bc3eefdbe0dee201f (diff)
string.c: Symbol#match
* string.c (sym_match_m): delegate to String#match but not String#=~. [ruby-core:72864] [Bug #11991] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_symbol.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index 5d42a5f..7ed4788 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -246,6 +246,30 @@ class TestSymbol < Test::Unit::TestCase
assert_equal(:fOo, :FoO.swapcase)
end
+ def test_MATCH # '=~'
+ assert_equal(10, :"FeeFieFoo-Fum" =~ /Fum$/)
+ assert_equal(nil, "FeeFieFoo-Fum" =~ /FUM$/)
+
+ o = Object.new
+ def o.=~(x); x + "bar"; end
+ assert_equal("foobar", :"foo" =~ o)
+
+ assert_raise(TypeError) { :"foo" =~ "foo" }
+ end
+
+ def test_match_method
+ assert_equal("bar", :"foobarbaz".match(/bar/).to_s)
+
+ o = Regexp.new('foo')
+ def o.match(x, y, z); x + y + z; end
+ assert_equal("foobarbaz", :"foo".match(o, "bar", "baz"))
+ x = nil
+ :"foo".match(o, "bar", "baz") {|y| x = y }
+ assert_equal("foobarbaz", x)
+
+ assert_raise(ArgumentError) { :"foo".match }
+ end
+
def test_symbol_poped
assert_nothing_raised { eval('a = 1; :"#{ a }"; 1') }
end