Skip to content

Commit 94d9b67

Browse files
committed
Add a MatchData#named_captures spec that exercises capture name reuse with optional patterns.
1 parent 5ad3c71 commit 94d9b67

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

spec/ruby/core/matchdata/named_captures_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
it 'prefers later captures' do
1010
/\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)\z/.match('0123').named_captures.should == { 'a' => '3', 'b' => '2' }
1111
end
12+
13+
it 'returns the latest matched capture, even if a later one that does not match exists' do
14+
/\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)?\z/.match('012').named_captures.should == { 'a' => '0', 'b' => '2' }
15+
end
1216
end
1317
end

0 commit comments

Comments
 (0)