summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-27 11:14:32 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-27 11:14:32 +0000
commitf82b0a39eaa1ac262db0093f441289678530e351 (patch)
tree2f8f736ae18699fb620d2bc9f76920a3ed17df73 /test
parent33b3645611cf7bee83d8d5ac9d4373b33f7fff85 (diff)
merge revision(s) 57123: [Backport #13054]
re.c: consider the case of RMatch::regexp is nil Follow r49675, r57098 and r57110. Don't assume RMatch::regexp always contains a valid Regexp instance; it will be Qnil if the MatchData is created by rb_backref_set_string(). [ruby-core:78741] [Bug #13054] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@57221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_regexp.rb27
1 files changed, 22 insertions, 5 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 39ba6dc760..25f6e69abb 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -559,16 +559,33 @@ class TestRegexp < Test::Unit::TestCase
end
def test_match_without_regexp
+ # create a MatchData for each assertion because the internal state may change
+ test = proc {|&blk| "abc".sub("a", ""); blk.call($~) }
+
bug10877 = '[ruby-core:68209] [Bug #10877]'
- "abc".sub("a", "")
- assert_raise_with_message(IndexError, /foo/, bug10877) {$~["foo"]}
+ test.call {|m| assert_raise_with_message(IndexError, /foo/, bug10877) {m["foo"]} }
key = "\u{3042}"
[Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc|
idx = key.encode(enc)
- EnvUtil.with_default_external(enc) do
- assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]}
- end
+ test.call {|m|
+ EnvUtil.with_default_external(enc) do
+ assert_raise_with_message(IndexError, /#{idx}/, bug10877) {m[idx]}
+ end
+ }
end
+ test.call {|m| assert_equal(/a/, m.regexp) }
+ test.call {|m| assert_equal("abc", m.string) }
+ test.call {|m| assert_equal(1, m.size) }
+ test.call {|m| assert_equal(0, m.begin(0)) }
+ test.call {|m| assert_equal(1, m.end(0)) }
+ test.call {|m| assert_equal([0, 1], m.offset(0)) }
+ test.call {|m| assert_equal([], m.captures) }
+ test.call {|m| assert_equal([], m.names) }
+ test.call {|m| assert_equal(/a/.match("abc"), m) }
+ test.call {|m| assert_equal(/a/.match("abc").hash, m.hash) }
+ test.call {|m| assert_equal("bc", m.post_match) }
+ test.call {|m| assert_equal("", m.pre_match) }
+ test.call {|m| assert_equal(["a", nil], m.values_at(0, 1)) }
end
def test_last_match