summaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-18 11:26:24 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-18 11:26:24 +0000
commit1ad46f322fbd9e82f0f3af000e6623d89c53fb75 (patch)
tree1215b85f64867a4e7470eee5125df935c662976f /test/ruby
parentc7c1a7b8c1fc2f03506b41c9d1314aa35580a749 (diff)
downloadruby-1ad46f322fbd9e82f0f3af000e6623d89c53fb75.tar.gz
ruby-1ad46f322fbd9e82f0f3af000e6623d89c53fb75.tar.xz
ruby-1ad46f322fbd9e82f0f3af000e6623d89c53fb75.zip
* parse.y (arg tMATCH arg): call reg_named_capture_assign_gen if regexp
literal is used. (reg_named_capture_assign_gen): assign the result of named capture into local variables. [ruby-dev:32588] * re.c: document the assignment by named captures. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_regexp.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 5cb6c810d..b415c03aa 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -95,6 +95,13 @@ class TestRegexp < Test::Unit::TestCase
assert_equal({}, /(.)(.)/.named_captures)
end
+ def test_assign_named_capture
+ assert_equal("a", eval('/(?<foo>.)/ =~ "a"; foo'))
+ assert_equal("a", eval('foo = 1; /(?<foo>.)/ =~ "a"; foo'))
+ assert_equal("a", eval('1.times {|foo| /(?<foo>.)/ =~ "a"; break foo }'))
+ assert_raise(SyntaxError) { eval('/(?<Foo>.)/ =~ "a"') }
+ end
+
def test_match_regexp
r = /./
m = r.match("a")