diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-01-16 11:25:43 +0900 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2020-01-16 15:26:28 +0900 |
commit | db4d136889afbf59e69efcfd495fd91cd401f378 (patch) | |
tree | 671483d357c34c6a5aad0fb089832a8bd6787a0d /test/ruby/test_regexp.rb | |
parent | 8e8841f6bf58031a1fe5b0dbacb5a1fb442102df (diff) |
`Regexp` in `MatchData` can be `nil`
`String#sub` with a string pattern defers creating a `Regexp`
until `MatchData#regexp` creates a `Regexp` from the matched
string. `Regexp#last_match(group_name)` accessed its content
without creating the `Regexp` though. [Bug #16508]
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r-- | test/ruby/test_regexp.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index a1d49c595a..b469d643f2 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -161,6 +161,10 @@ class TestRegexp < Test::Unit::TestCase s = "foo" s[/(?<bar>o)/, "bar"] = "baz" assert_equal("fbazo", s) + + /.*/ =~ "abc" + "a".sub("a", "") + assert_raise(IndexError) {Regexp.last_match(:_id)} end def test_named_capture_with_nul |