aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/array/shared/slice.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/array/shared/slice.rb')
-rw-r--r--spec/ruby/core/array/shared/slice.rb41
1 files changed, 39 insertions, 2 deletions
diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb
index 820047cdb2..6818badeda 100644
--- a/spec/ruby/core/array/shared/slice.rb
+++ b/spec/ruby/core/array/shared/slice.rb
@@ -486,7 +486,7 @@ describe :array_slice, shared: true do
end
end
- it "raises a RangeError when the start index is out of range of Integer" do
+ it "raises a RangeError when the start index is out of range of Fixnum" do
array = [1, 2, 3, 4, 5, 6]
obj = mock('large value')
obj.should_receive(:to_int).and_return(bignum_value)
@@ -502,7 +502,7 @@ describe :array_slice, shared: true do
array.send(@method, max_long.to_f.prev_float).should == nil
end
- it "raises a RangeError when the length is out of range of Integer" do
+ it "raises a RangeError when the length is out of range of Fixnum" do
array = [1, 2, 3, 4, 5, 6]
obj = mock('large value')
obj.should_receive(:to_int).and_return(bignum_value)
@@ -520,4 +520,41 @@ describe :array_slice, shared: true 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 "can accept endless ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a.send(@method, eval("(2..)")).should == [2, 3, 4, 5]
+ a.send(@method, eval("(2...)")).should == [2, 3, 4, 5]
+ a.send(@method, eval("(-2..)")).should == [4, 5]
+ a.send(@method, eval("(-2...)")).should == [4, 5]
+ a.send(@method, eval("(9..)")).should == nil
+ a.send(@method, eval("(9...)")).should == nil
+ a.send(@method, eval("(-9..)")).should == nil
+ a.send(@method, eval("(-9...)")).should == nil
+ end
+ end
+
+ ruby_version_is "2.7" do
+ it "can accept beginless ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a.send(@method, eval("(..3)")).should == [0, 1, 2, 3]
+ a.send(@method, eval("(...3)")).should == [0, 1, 2]
+ a.send(@method, eval("(..-3)")).should == [0, 1, 2, 3]
+ a.send(@method, eval("(...-3)")).should == [0, 1, 2]
+ a.send(@method, eval("(..0)")).should == [0]
+ a.send(@method, eval("(...0)")).should == []
+ a.send(@method, eval("(..9)")).should == [0, 1, 2, 3, 4, 5]
+ a.send(@method, eval("(...9)")).should == [0, 1, 2, 3, 4, 5]
+ a.send(@method, eval("(..-9)")).should == []
+ a.send(@method, eval("(...-9)")).should == []
+ end
+
+ it "can accept nil...nil ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a.send(@method, eval("(nil...nil)")).should == a
+ a.send(@method, eval("(...nil)")).should == a
+ a.send(@method, eval("(nil..)")).should == a
+ end
+ end
end