* re.c (match_values_at): MatchData#values_at supports named captures

[Feature #9179]

* re.c (namev_to_backref_number): separeted.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2016-05-17 17:10:01 +00:00
parent 0f621628a9
commit 92f8d74a3e
4 changed files with 59 additions and 30 deletions

View file

@ -383,6 +383,13 @@ class TestRegexp < Test::Unit::TestCase
def test_match_values_at
m = /(...)(...)(...)(...)?/.match("foobarbaz")
assert_equal(["foo", "bar", "baz"], m.values_at(1, 2, 3))
m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2")
assert_equal(["1", "2", "+"], m.values_at(:a, 'b', :op))
idx = Object.new
def idx.to_int; 2; end
assert_equal(["+"], m.values_at(idx))
assert_raise(TypeError){ m.values_at(nil) }
end
def test_match_string