diff options
author | Benoit Daloze <[email protected]> | 2020-02-28 19:07:17 +0100 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2020-02-28 19:07:17 +0100 |
commit | a0f5ff4c3cd05f8717be2bf1d79f0817f288d398 (patch) | |
tree | 441f409cf816cf8a61dacdbaf204ae9f5cbe2f18 /spec/ruby/core/string/shared | |
parent | 5d210501825e1682e68cbfc2be424fc339f382fa (diff) |
Update to ruby/spec@41bf282
Diffstat (limited to 'spec/ruby/core/string/shared')
-rw-r--r-- | spec/ruby/core/string/shared/slice.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb index b192005369..1c438bc48d 100644 --- a/spec/ruby/core/string/shared/slice.rb +++ b/spec/ruby/core/string/shared/slice.rb @@ -121,6 +121,8 @@ describe :string_slice_index_length, shared: true do "x".send(@method, -2,0).should == nil "x".send(@method, -2,1).should == nil + + "x".send(@method, fixnum_max, 1).should == nil end it "returns nil if the length is negative" do @@ -293,6 +295,24 @@ describe :string_slice_range, shared: true do "hello world".send(@method, 6..5).send(@method, -1..-1).should == nil "hello world".send(@method, 6..5).send(@method, 1..1).should == nil end + + it "raises a type error if a range is passed with a length" do + ->{ "hello".send(@method, 1..2, 1) }.should raise_error(TypeError) + end + + it "raises a RangeError if one of the bound is too big" do + -> { "hello".send(@method, bignum_value..(bignum_value + 1)) }.should raise_error(RangeError) + -> { "hello".send(@method, 0..bignum_value) }.should raise_error(RangeError) + end + + ruby_version_is "2.6" do + it "works with endless ranges" do + "hello there".send(@method, eval("(2..)")).should == "llo there" + "hello there".send(@method, eval("(2...)")).should == "llo there" + "hello there".send(@method, eval("(-4..)")).should == "here" + "hello there".send(@method, eval("(-4...)")).should == "here" + end + end end describe :string_slice_regexp, shared: true do |