Skip to content

Commit 505d56f

Browse files
committed
Expand specs for String#[Regexp, Integer]
1 parent a6d2e0b commit 505d56f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spec/ruby/core/string/shared/slice.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,20 @@
375375
"hello there".send(@method, /(what?)/, 1).should == nil
376376
end
377377

378+
it "returns nil if the index is larger than the number of captures" do
379+
"hello there".send(@method, /hello (.)/, 2).should == nil
380+
# You can't refer to 0 using negative indices
381+
"hello there".send(@method, /hello (.)/, -2).should == nil
382+
end
383+
378384
it "returns nil if there is no capture for the given index" do
379385
"hello there".send(@method, /[aeiou](.)\1/, 2).should == nil
380-
# You can't refer to 0 using negative indices
381-
"hello there".send(@method, /[aeiou](.)\1/, -2).should == nil
386+
end
387+
388+
it "returns nil if the given capture group was not matched but still sets $~" do
389+
"test".send(@method, /te(z)?/, 1).should == nil
390+
$~[0].should == "te"
391+
$~[1].should == nil
382392
end
383393

384394
it "calls to_int on the given index" do

0 commit comments

Comments
 (0)