diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-09 07:12:44 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-09 07:12:44 +0000 |
commit | 18d8fbac5484411bc7194c408edf0a3e17ea640d (patch) | |
tree | 004add4115b2e4bb10a0691ebd42f935baf6da53 /test | |
parent | a44f38ff52e3d828173e0719bc27ef7a5f381cf4 (diff) |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@14158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_regexp.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 84710bb449..f052b946c0 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 = /&(?<foo>.*?);/.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(/&(?<foo>.*?);/, '[\k<foo>]')) + + assert_equal('#<MatchData "& y" foo:"amp">', + /&(?<foo>.*?); (y)/.match("aaa & yyy").inspect) + assert_equal('#<MatchData "& y" 1:"amp" 2:"y">', + /&(.*?); (y)/.match("aaa & yyy").inspect) + assert_equal('#<MatchData "& y" foo:"amp" bar:"y">', + /&(?<foo>.*?); (?<bar>y)/.match("aaa & yyy").inspect) + assert_equal('#<MatchData "& y" foo:"amp" foo:"y">', + /&(?<foo>.*?); (?<foo>y)/.match("aaa & yyy").inspect) + + # MatchData#keys + end end |