aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-09 07:12:44 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-09 07:12:44 +0000
commit18d8fbac5484411bc7194c408edf0a3e17ea640d (patch)
tree004add4115b2e4bb10a0691ebd42f935baf6da53 /test
parenta44f38ff52e3d828173e0719bc27ef7a5f381cf4 (diff)
downloadruby-18d8fbac5484411bc7194c408edf0a3e17ea640d.tar.gz
* 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.rb23
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 &amp; 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 &amp; yyy".sub(/&(?<foo>.*?);/, '[\k<foo>]'))
+
+ assert_equal('#<MatchData "&amp; y" foo:"amp">',
+ /&(?<foo>.*?); (y)/.match("aaa &amp; yyy").inspect)
+ assert_equal('#<MatchData "&amp; y" 1:"amp" 2:"y">',
+ /&(.*?); (y)/.match("aaa &amp; yyy").inspect)
+ assert_equal('#<MatchData "&amp; y" foo:"amp" bar:"y">',
+ /&(?<foo>.*?); (?<bar>y)/.match("aaa &amp; yyy").inspect)
+ assert_equal('#<MatchData "&amp; y" foo:"amp" foo:"y">',
+ /&(?<foo>.*?); (?<foo>y)/.match("aaa &amp; yyy").inspect)
+
+ # MatchData#keys
+ end
end