summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/shared
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-06-26 14:50:14 +0200
committerBenoit Daloze <eregontp@gmail.com>2022-06-26 14:50:14 +0200
commitd3d5ef0cca160fca538c7f556c5a6e08df5847e6 (patch)
tree57358b4b9cdd6f429d0383005ac393cb74dd3bff /spec/ruby/core/string/shared
parentf616e816372d14e605879d2e43c7fbdda29ef837 (diff)
Update to ruby/spec@ab32a1a
Diffstat (limited to 'spec/ruby/core/string/shared')
-rw-r--r--spec/ruby/core/string/shared/slice.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb
index 228af5f824..713234fffd 100644
--- a/spec/ruby/core/string/shared/slice.rb
+++ b/spec/ruby/core/string/shared/slice.rb
@@ -375,10 +375,20 @@ describe :string_slice_regexp_index, shared: true do
"hello there".send(@method, /(what?)/, 1).should == nil
end
+ it "returns nil if the index is larger than the number of captures" do
+ "hello there".send(@method, /hello (.)/, 2).should == nil
+ # You can't refer to 0 using negative indices
+ "hello there".send(@method, /hello (.)/, -2).should == nil
+ end
+
it "returns nil if there is no capture for the given index" do
"hello there".send(@method, /[aeiou](.)\1/, 2).should == nil
- # You can't refer to 0 using negative indices
- "hello there".send(@method, /[aeiou](.)\1/, -2).should == nil
+ end
+
+ it "returns nil if the given capture group was not matched but still sets $~" do
+ "test".send(@method, /te(z)?/, 1).should == nil
+ $~[0].should == "te"
+ $~[1].should == nil
end
it "calls to_int on the given index" do