aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_regexp.rb
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-11-16 19:52:02 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-11-19 13:55:50 +0000
commit39cf3c0a381399f8bf4c7eda89af1caae33078e6 (patch)
tree4267a1feda35d17e463a6c64c94070eb3406c0e6 /test/ruby/test_regexp.rb
parentacbaa8c4269263f05a90c959533b5199841b4b1e (diff)
downloadruby-39cf3c0a381399f8bf4c7eda89af1caae33078e6.tar.gz
re.c: fix for RMatch::regexp == Qniltopic/re-matchdata-fixes
So, don't blindly assume RMatch::regexp contains an instance of Regexp and do check properly, because it may be nil as of r45451.
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r--test/ruby/test_regexp.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index b0da247f4f..7c09467014 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -639,14 +639,30 @@ 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)
- assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]}
+ test.call {|m| assert_raise_with_message(IndexError, /#{idx}/, bug10877) {m[idx]} }
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({}, m.named_captures) }
+ 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