1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@14297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2007-12-18 11:26:24 +00:00
parent 400009cac2
commit 2d01290cfd
4 changed files with 130 additions and 0 deletions

View file

@ -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")