From 61b762d89109bcddd38f0a181a07a9189987c0cc Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 9 Dec 2007 07:12:44 +0000 Subject: * re.c (match_backref_number): new function for converting a backref name/number to an integer. (match_offset): use match_backref_number. (match_begin): ditto. (match_end): ditto. (name_to_backref_number): raise IndexError instead of RuntimeError. (match_inspect): show capture index. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_regexp.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 84710bb44..f052b946c 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -49,4 +49,27 @@ class TestRegexp < Test::Unit::TestCase :ok end end + + def test_named_capture + m = /&(?.*?);/.match("aaa & yyy") + assert_equal("amp", m["foo"]) + assert_equal("amp", m[:foo]) + assert_equal(5, m.begin(:foo)) + assert_equal(8, m.end(:foo)) + assert_equal([5,8], m.offset(:foo)) + #assert_equal(["amp"], m.values_at(:foo)) + + assert_equal("aaa [amp] yyy", "aaa & yyy".sub(/&(?.*?);/, '[\k]')) + + assert_equal('#', + /&(?.*?); (y)/.match("aaa & yyy").inspect) + assert_equal('#', + /&(.*?); (y)/.match("aaa & yyy").inspect) + assert_equal('#', + /&(?.*?); (?y)/.match("aaa & yyy").inspect) + assert_equal('#', + /&(?.*?); (?y)/.match("aaa & yyy").inspect) + + # MatchData#keys + end end -- cgit