summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-18 04:56:02 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-18 04:56:02 +0000
commitb8fde968619cb9116fb765c70b3295460645652f (patch)
treefec5b77dd1d82f2ed196841de77cdaae86ebb805 /test
parent3f991534d47cea95e90c50be82e79f90cf1f14a7 (diff)
* re.c (match_ary_subseq): get subseq of match array without creating
temporary array. * re.c (match_ary_aref): get element(s) of match array without creating temporary array. * re.c (match_aref): Use match_ary_subseq with handling irregulars. * re.c (match_values_at): Use match_ary_aref. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_regexp.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index a8a120c..0562785 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -374,23 +374,46 @@ class TestRegexp < Test::Unit::TestCase
def test_match_aref
m = /(...)(...)(...)(...)?/.match("foobarbaz")
+ assert_equal("foobarbaz", m[0])
assert_equal("foo", m[1])
+ assert_equal("foo", m[-4])
+ assert_nil(m[-1])
+ assert_nil(m[-11])
+ assert_nil(m[-11, 1])
+ assert_nil(m[-11..1])
+ assert_nil(m[5])
+ assert_nil(m[9])
assert_equal(["foo", "bar", "baz"], m[1..3])
+ assert_equal(["foo", "bar", "baz"], m[1, 3])
+ assert_equal([], m[3..1])
+ assert_equal([], m[3, 0])
+ assert_equal(nil, m[3, -1])
+ assert_equal(nil, m[9, 1])
+ assert_equal(["baz"], m[3, 1])
+ assert_equal(["baz", nil], m[3, 5])
assert_nil(m[5])
assert_raise(IndexError) { m[:foo] }
+ assert_raise(TypeError) { m[nil] }
end
def test_match_values_at
+ idx = Object.new
+ def idx.to_int; 2; end
m = /(...)(...)(...)(...)?/.match("foobarbaz")
assert_equal(["foo", "bar", "baz"], m.values_at(1, 2, 3))
assert_equal(["foo", "bar", "baz"], m.values_at(1..3))
+ assert_equal(["foo", "bar", "baz", nil, nil], m.values_at(1..5))
+ assert_equal([], m.values_at(3..1))
+ assert_equal([nil, nil, nil, nil, nil], m.values_at(5..9))
+ assert_equal(["bar"], m.values_at(idx))
+ assert_raise(RangeError){ m.values_at(-11..1) }
+ assert_raise(TypeError){ m.values_at(nil) }
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) }
+ assert_raise(IndexError){ m.values_at(:foo) }
end
def test_match_string