diff options
author | Vladimir Dementyev <dementiev.vm@gmail.com> | 2023-04-18 19:19:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 11:19:31 +1200 |
commit | b09f5c7bf79d347aa6ed92964cff16d7da008ad9 (patch) | |
tree | 7166e834c07ed543bd9c1b86578748b718fddcf8 /test | |
parent | 2dff1d4fdabd0fafeeac675baaaf7b06bb3150f9 (diff) | |
download | ruby-b09f5c7bf79d347aa6ed92964cff16d7da008ad9.tar.gz |
MatchData#named_captures: add optional symbolize_names keyword (#6952)
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_regexp.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 6ec77a41a3..d50e481d2d 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -304,6 +304,9 @@ class TestRegexp < Test::Unit::TestCase assert_equal({'a' => '1', 'b' => '2', 'c' => '3'}, /^(?<a>.)(?<b>.)(?<c>.)?/.match('123').named_captures) assert_equal({'a' => '1', 'b' => '2', 'c' => ''}, /^(?<a>.)(?<b>.)(?<c>.?)/.match('12').named_captures) + assert_equal({a: '1', b: '2', c: ''}, /^(?<a>.)(?<b>.)(?<c>.?)/.match('12').named_captures(symbolize_names: true)) + assert_equal({'a' => '1', 'b' => '2', 'c' => ''}, /^(?<a>.)(?<b>.)(?<c>.?)/.match('12').named_captures(symbolize_names: false)) + assert_equal({'a' => 'x'}, /(?<a>x)|(?<a>y)/.match('x').named_captures) assert_equal({'a' => 'y'}, /(?<a>x)|(?<a>y)/.match('y').named_captures) |