summaryrefslogtreecommitdiff
path: root/spec/ruby/core/array
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/array')
-rw-r--r--spec/ruby/core/array/drop_spec.rb2
-rw-r--r--spec/ruby/core/array/fetch_values_spec.rb11
-rw-r--r--spec/ruby/core/array/intersect_spec.rb92
-rw-r--r--spec/ruby/core/array/pack/a_spec.rb6
-rw-r--r--spec/ruby/core/array/pack/at_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/b_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/c_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/comment_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/h_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/m_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/shared/basic.rb27
-rw-r--r--spec/ruby/core/array/pack/shared/float.rb2
-rw-r--r--spec/ruby/core/array/pack/shared/integer.rb2
-rw-r--r--spec/ruby/core/array/pack/shared/string.rb2
-rw-r--r--spec/ruby/core/array/pack/u_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/w_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/x_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/z_spec.rb4
-rw-r--r--spec/ruby/core/array/sample_spec.rb7
-rw-r--r--spec/ruby/core/array/shared/slice.rb184
-rw-r--r--spec/ruby/core/array/shared/unshift.rb2
-rw-r--r--spec/ruby/core/array/shuffle_spec.rb13
22 files changed, 189 insertions, 183 deletions
diff --git a/spec/ruby/core/array/drop_spec.rb b/spec/ruby/core/array/drop_spec.rb
index 0ea748e47d..5926c291b8 100644
--- a/spec/ruby/core/array/drop_spec.rb
+++ b/spec/ruby/core/array/drop_spec.rb
@@ -7,7 +7,7 @@ describe "Array#drop" do
end
it "raises an ArgumentError if the number of elements specified is negative" do
- -> { [1, 2].drop(-3) }.should raise_error(ArgumentError)
+ -> { [1, 2].drop(-3) }.should raise_error(ArgumentError)
end
it "returns an empty Array if all elements are dropped" do
diff --git a/spec/ruby/core/array/fetch_values_spec.rb b/spec/ruby/core/array/fetch_values_spec.rb
index 559b6c2b2f..cf377b3b71 100644
--- a/spec/ruby/core/array/fetch_values_spec.rb
+++ b/spec/ruby/core/array/fetch_values_spec.rb
@@ -11,6 +11,7 @@ describe "Array#fetch_values" do
it "returns the values for indexes" do
@array.fetch_values(0).should == [:a]
@array.fetch_values(0, 2).should == [:a, :c]
+ @array.fetch_values(-1).should == [:c]
end
it "returns the values for indexes ordered in the order of the requested indexes" do
@@ -20,7 +21,7 @@ describe "Array#fetch_values" do
describe "with unmatched indexes" do
it "raises a index error if no block is provided" do
- -> { @array.fetch_values(0, 1, 44) }.should raise_error(IndexError)
+ -> { @array.fetch_values(0, 1, 44) }.should raise_error(IndexError, "index 44 outside of array bounds: -3...3")
end
it "returns the default value from block" do
@@ -41,8 +42,14 @@ describe "Array#fetch_values" do
@array.fetch_values(obj).should == [:c]
end
+ it "does not support a Range object as argument" do
+ -> {
+ @array.fetch_values(1..2)
+ }.should raise_error(TypeError, "no implicit conversion of Range into Integer")
+ end
+
it "raises a TypeError when the passed argument can't be coerced to Integer" do
- -> { [].fetch_values("cat") }.should raise_error(TypeError)
+ -> { [].fetch_values("cat") }.should raise_error(TypeError, "no implicit conversion of String into Integer")
end
end
end
diff --git a/spec/ruby/core/array/intersect_spec.rb b/spec/ruby/core/array/intersect_spec.rb
index 62ac157278..456aa26c6e 100644
--- a/spec/ruby/core/array/intersect_spec.rb
+++ b/spec/ruby/core/array/intersect_spec.rb
@@ -2,65 +2,63 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe 'Array#intersect?' do
- ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/15198
- describe 'when at least one element in two Arrays is the same' do
- it 'returns true' do
- [1, 2].intersect?([2, 3, 4]).should == true
- [2, 3, 4].intersect?([1, 2]).should == true
- end
+ describe 'when at least one element in two Arrays is the same' do
+ it 'returns true' do
+ [1, 2].intersect?([2, 3, 4]).should == true
+ [2, 3, 4].intersect?([1, 2]).should == true
end
+ end
- describe 'when there are no elements in common between two Arrays' do
- it 'returns false' do
- [0, 1, 2].intersect?([3, 4]).should == false
- [3, 4].intersect?([0, 1, 2]).should == false
- [3, 4].intersect?([]).should == false
- [].intersect?([0, 1, 2]).should == false
- end
+ describe 'when there are no elements in common between two Arrays' do
+ it 'returns false' do
+ [0, 1, 2].intersect?([3, 4]).should == false
+ [3, 4].intersect?([0, 1, 2]).should == false
+ [3, 4].intersect?([]).should == false
+ [].intersect?([0, 1, 2]).should == false
end
+ end
- it "tries to convert the passed argument to an Array using #to_ary" do
- obj = mock('[1,2,3]')
- obj.should_receive(:to_ary).and_return([1, 2, 3])
+ it "tries to convert the passed argument to an Array using #to_ary" do
+ obj = mock('[1,2,3]')
+ obj.should_receive(:to_ary).and_return([1, 2, 3])
- [1, 2].intersect?(obj).should == true
- end
+ [1, 2].intersect?(obj).should == true
+ end
- it "determines equivalence between elements in the sense of eql?" do
- obj1 = mock('1')
- obj2 = mock('2')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj1.stub!(:eql?).and_return(true)
- obj2.stub!(:eql?).and_return(true)
+ it "determines equivalence between elements in the sense of eql?" do
+ obj1 = mock('1')
+ obj2 = mock('2')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.stub!(:eql?).and_return(true)
+ obj2.stub!(:eql?).and_return(true)
- [obj1].intersect?([obj2]).should == true
+ [obj1].intersect?([obj2]).should == true
- obj1 = mock('3')
- obj2 = mock('4')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj1.stub!(:eql?).and_return(false)
- obj2.stub!(:eql?).and_return(false)
+ obj1 = mock('3')
+ obj2 = mock('4')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.stub!(:eql?).and_return(false)
+ obj2.stub!(:eql?).and_return(false)
- [obj1].intersect?([obj2]).should == false
- end
+ [obj1].intersect?([obj2]).should == false
+ end
- it "does not call to_ary on array subclasses" do
- [5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true
- end
+ it "does not call to_ary on array subclasses" do
+ [5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true
+ end
- it "properly handles an identical item even when its #eql? isn't reflexive" do
- x = mock('x')
- x.stub!(:hash).and_return(42)
- x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+ it "properly handles an identical item even when its #eql? isn't reflexive" do
+ x = mock('x')
+ x.stub!(:hash).and_return(42)
+ x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
- [x].intersect?([x]).should == true
- end
+ [x].intersect?([x]).should == true
+ end
- it "has semantic of !(a & b).empty?" do
- [].intersect?([]).should == false
- [nil].intersect?([nil]).should == true
- end
+ it "has semantic of !(a & b).empty?" do
+ [].intersect?([]).should == false
+ [nil].intersect?([nil]).should == true
end
end
diff --git a/spec/ruby/core/array/pack/a_spec.rb b/spec/ruby/core/array/pack/a_spec.rb
index f4a40502c2..8245cd5470 100644
--- a/spec/ruby/core/array/pack/a_spec.rb
+++ b/spec/ruby/core/array/pack/a_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
@@ -27,7 +27,7 @@ describe "Array#pack with format 'A'" do
["abc"].pack("A*").should == "abc"
end
- it "padds the output with spaces when the count exceeds the size of the String" do
+ it "pads the output with spaces when the count exceeds the size of the String" do
["abc"].pack("A6").should == "abc "
end
@@ -55,7 +55,7 @@ describe "Array#pack with format 'a'" do
["abc"].pack("a*").should == "abc"
end
- it "padds the output with NULL bytes when the count exceeds the size of the String" do
+ it "pads the output with NULL bytes when the count exceeds the size of the String" do
["abc"].pack("a6").should == "abc\x00\x00\x00"
end
diff --git a/spec/ruby/core/array/pack/at_spec.rb b/spec/ruby/core/array/pack/at_spec.rb
index 3942677913..bb9801440a 100644
--- a/spec/ruby/core/array/pack/at_spec.rb
+++ b/spec/ruby/core/array/pack/at_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/b_spec.rb b/spec/ruby/core/array/pack/b_spec.rb
index ec82b7d1ab..247a9ca023 100644
--- a/spec/ruby/core/array/pack/b_spec.rb
+++ b/spec/ruby/core/array/pack/b_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/c_spec.rb b/spec/ruby/core/array/pack/c_spec.rb
index ac133ff9b6..47b71b663d 100644
--- a/spec/ruby/core/array/pack/c_spec.rb
+++ b/spec/ruby/core/array/pack/c_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/array/pack/comment_spec.rb b/spec/ruby/core/array/pack/comment_spec.rb
index 254c827ccc..daf1cff06a 100644
--- a/spec/ruby/core/array/pack/comment_spec.rb
+++ b/spec/ruby/core/array/pack/comment_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/array/pack/h_spec.rb b/spec/ruby/core/array/pack/h_spec.rb
index 2c1dac8d4a..ba188874ba 100644
--- a/spec/ruby/core/array/pack/h_spec.rb
+++ b/spec/ruby/core/array/pack/h_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/m_spec.rb b/spec/ruby/core/array/pack/m_spec.rb
index c6364af12d..a80f91275c 100644
--- a/spec/ruby/core/array/pack/m_spec.rb
+++ b/spec/ruby/core/array/pack/m_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb
index 5e3eea55f9..a63f64d296 100644
--- a/spec/ruby/core/array/pack/shared/basic.rb
+++ b/spec/ruby/core/array/pack/shared/basic.rb
@@ -32,34 +32,21 @@ describe :array_pack_basic_non_float, shared: true do
[@obj, @obj, @obj, @obj].pack("aa #{pack_format} # some comment \n#{pack_format}").should be_an_instance_of(String)
end
- ruby_version_is ""..."3.2" do
- it "warns in verbose mode that a directive is unknown" do
- # additional directive ('a') is required for the X directive
- -> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/, verbose: true)
- -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/, verbose: true)
- -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/, verbose: true)
- end
- end
-
- ruby_version_is "3.2"..."3.3" do
- # https://bugs.ruby-lang.org/issues/19150
- # NOTE: it's just a plan of the Ruby core team
+ ruby_version_is ""..."3.3" do
it "warns that a directive is unknown" do
# additional directive ('a') is required for the X directive
- -> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/)
- -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/)
- -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/)
+ -> { [@obj, @obj].pack("a K" + pack_format) }.should complain(/unknown pack directive 'K' in 'a K#{pack_format}'/)
+ -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0' in 'a 0#{pack_format}'/)
+ -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':' in 'a :#{pack_format}'/)
end
end
ruby_version_is "3.3" do
- # https://bugs.ruby-lang.org/issues/19150
- # NOTE: Added this case just to not forget about the decision in the ticket
it "raise ArgumentError when a directive is unknown" do
# additional directive ('a') is required for the X directive
- -> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError)
- -> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError)
- -> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError)
+ -> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)
+ -> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive '0'/)
+ -> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive ':'/)
end
end
diff --git a/spec/ruby/core/array/pack/shared/float.rb b/spec/ruby/core/array/pack/shared/float.rb
index 1780d7635e..76c800b74d 100644
--- a/spec/ruby/core/array/pack/shared/float.rb
+++ b/spec/ruby/core/array/pack/shared/float.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :array_pack_float_le, shared: true do
it "encodes a positive Float" do
diff --git a/spec/ruby/core/array/pack/shared/integer.rb b/spec/ruby/core/array/pack/shared/integer.rb
index a89b5b733b..61f7cca184 100644
--- a/spec/ruby/core/array/pack/shared/integer.rb
+++ b/spec/ruby/core/array/pack/shared/integer.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :array_pack_16bit_le, shared: true do
it "encodes the least significant 16 bits of a positive number" do
diff --git a/spec/ruby/core/array/pack/shared/string.rb b/spec/ruby/core/array/pack/shared/string.rb
index 2f70dc3951..805f78b53b 100644
--- a/spec/ruby/core/array/pack/shared/string.rb
+++ b/spec/ruby/core/array/pack/shared/string.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :array_pack_string, shared: true do
it "adds count bytes of a String to the output" do
["abc"].pack(pack_format(2)).should == "ab"
diff --git a/spec/ruby/core/array/pack/u_spec.rb b/spec/ruby/core/array/pack/u_spec.rb
index b20093a647..1f84095ac4 100644
--- a/spec/ruby/core/array/pack/u_spec.rb
+++ b/spec/ruby/core/array/pack/u_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/w_spec.rb b/spec/ruby/core/array/pack/w_spec.rb
index 48ed4496a5..e770288d67 100644
--- a/spec/ruby/core/array/pack/w_spec.rb
+++ b/spec/ruby/core/array/pack/w_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/x_spec.rb b/spec/ruby/core/array/pack/x_spec.rb
index 86c3ad1aa4..012fe4567f 100644
--- a/spec/ruby/core/array/pack/x_spec.rb
+++ b/spec/ruby/core/array/pack/x_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/z_spec.rb b/spec/ruby/core/array/pack/z_spec.rb
index 5ad3afd69e..60f8f7bf10 100644
--- a/spec/ruby/core/array/pack/z_spec.rb
+++ b/spec/ruby/core/array/pack/z_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
@@ -26,7 +26,7 @@ describe "Array#pack with format 'Z'" do
["abc"].pack("Z*").should == "abc\x00"
end
- it "padds the output with NULL bytes when the count exceeds the size of the String" do
+ it "pads the output with NULL bytes when the count exceeds the size of the String" do
["abc"].pack("Z6").should == "abc\x00\x00\x00"
end
diff --git a/spec/ruby/core/array/sample_spec.rb b/spec/ruby/core/array/sample_spec.rb
index 6ef78594f0..d4e945152d 100644
--- a/spec/ruby/core/array/sample_spec.rb
+++ b/spec/ruby/core/array/sample_spec.rb
@@ -114,6 +114,13 @@ describe "Array#sample" do
-> { [1, 2].sample(random: random) }.should raise_error(RangeError)
end
+
+ it "raises a RangeError if the value is greater than the Array size" do
+ random = mock("array_sample_random")
+ random.should_receive(:rand).and_return(3)
+
+ -> { [1, 2].sample(random: random) }.should raise_error(RangeError)
+ end
end
end
diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb
index d2866970a5..b80261d32f 100644
--- a/spec/ruby/core/array/shared/slice.rb
+++ b/spec/ruby/core/array/shared/slice.rb
@@ -754,99 +754,97 @@ describe :array_slice, shared: true do
a.send(@method, (...-9)).should == []
end
- ruby_version_is "3.2" do
- describe "can be sliced with Enumerator::ArithmeticSequence" do
- it "with infinite/inverted ranges and negative steps" do
- @array = [0, 1, 2, 3, 4, 5]
- @array.send(@method, (2..).step(-1)).should == [2, 1, 0]
- @array.send(@method, (2..).step(-2)).should == [2, 0]
- @array.send(@method, (2..).step(-3)).should == [2]
- @array.send(@method, (2..).step(-4)).should == [2]
-
- @array.send(@method, (-3..).step(-1)).should == [3, 2, 1, 0]
- @array.send(@method, (-3..).step(-2)).should == [3, 1]
- @array.send(@method, (-3..).step(-3)).should == [3, 0]
- @array.send(@method, (-3..).step(-4)).should == [3]
- @array.send(@method, (-3..).step(-5)).should == [3]
-
- @array.send(@method, (..0).step(-1)).should == [5, 4, 3, 2, 1, 0]
- @array.send(@method, (..0).step(-2)).should == [5, 3, 1]
- @array.send(@method, (..0).step(-3)).should == [5, 2]
- @array.send(@method, (..0).step(-4)).should == [5, 1]
- @array.send(@method, (..0).step(-5)).should == [5, 0]
- @array.send(@method, (..0).step(-6)).should == [5]
- @array.send(@method, (..0).step(-7)).should == [5]
-
- @array.send(@method, (...0).step(-1)).should == [5, 4, 3, 2, 1]
- @array.send(@method, (...0).step(-2)).should == [5, 3, 1]
- @array.send(@method, (...0).step(-3)).should == [5, 2]
- @array.send(@method, (...0).step(-4)).should == [5, 1]
- @array.send(@method, (...0).step(-5)).should == [5]
- @array.send(@method, (...0).step(-6)).should == [5]
-
- @array.send(@method, (...1).step(-1)).should == [5, 4, 3, 2]
- @array.send(@method, (...1).step(-2)).should == [5, 3]
- @array.send(@method, (...1).step(-3)).should == [5, 2]
- @array.send(@method, (...1).step(-4)).should == [5]
- @array.send(@method, (...1).step(-5)).should == [5]
-
- @array.send(@method, (..-5).step(-1)).should == [5, 4, 3, 2, 1]
- @array.send(@method, (..-5).step(-2)).should == [5, 3, 1]
- @array.send(@method, (..-5).step(-3)).should == [5, 2]
- @array.send(@method, (..-5).step(-4)).should == [5, 1]
- @array.send(@method, (..-5).step(-5)).should == [5]
- @array.send(@method, (..-5).step(-6)).should == [5]
-
- @array.send(@method, (...-5).step(-1)).should == [5, 4, 3, 2]
- @array.send(@method, (...-5).step(-2)).should == [5, 3]
- @array.send(@method, (...-5).step(-3)).should == [5, 2]
- @array.send(@method, (...-5).step(-4)).should == [5]
- @array.send(@method, (...-5).step(-5)).should == [5]
-
- @array.send(@method, (4..1).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (4..1).step(-2)).should == [4, 2]
- @array.send(@method, (4..1).step(-3)).should == [4, 1]
- @array.send(@method, (4..1).step(-4)).should == [4]
- @array.send(@method, (4..1).step(-5)).should == [4]
-
- @array.send(@method, (4...1).step(-1)).should == [4, 3, 2]
- @array.send(@method, (4...1).step(-2)).should == [4, 2]
- @array.send(@method, (4...1).step(-3)).should == [4]
- @array.send(@method, (4...1).step(-4)).should == [4]
-
- @array.send(@method, (-2..1).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (-2..1).step(-2)).should == [4, 2]
- @array.send(@method, (-2..1).step(-3)).should == [4, 1]
- @array.send(@method, (-2..1).step(-4)).should == [4]
- @array.send(@method, (-2..1).step(-5)).should == [4]
-
- @array.send(@method, (-2...1).step(-1)).should == [4, 3, 2]
- @array.send(@method, (-2...1).step(-2)).should == [4, 2]
- @array.send(@method, (-2...1).step(-3)).should == [4]
- @array.send(@method, (-2...1).step(-4)).should == [4]
-
- @array.send(@method, (4..-5).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (4..-5).step(-2)).should == [4, 2]
- @array.send(@method, (4..-5).step(-3)).should == [4, 1]
- @array.send(@method, (4..-5).step(-4)).should == [4]
- @array.send(@method, (4..-5).step(-5)).should == [4]
-
- @array.send(@method, (4...-5).step(-1)).should == [4, 3, 2]
- @array.send(@method, (4...-5).step(-2)).should == [4, 2]
- @array.send(@method, (4...-5).step(-3)).should == [4]
- @array.send(@method, (4...-5).step(-4)).should == [4]
-
- @array.send(@method, (-2..-5).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (-2..-5).step(-2)).should == [4, 2]
- @array.send(@method, (-2..-5).step(-3)).should == [4, 1]
- @array.send(@method, (-2..-5).step(-4)).should == [4]
- @array.send(@method, (-2..-5).step(-5)).should == [4]
-
- @array.send(@method, (-2...-5).step(-1)).should == [4, 3, 2]
- @array.send(@method, (-2...-5).step(-2)).should == [4, 2]
- @array.send(@method, (-2...-5).step(-3)).should == [4]
- @array.send(@method, (-2...-5).step(-4)).should == [4]
- end
+ describe "can be sliced with Enumerator::ArithmeticSequence" do
+ it "with infinite/inverted ranges and negative steps" do
+ @array = [0, 1, 2, 3, 4, 5]
+ @array.send(@method, (2..).step(-1)).should == [2, 1, 0]
+ @array.send(@method, (2..).step(-2)).should == [2, 0]
+ @array.send(@method, (2..).step(-3)).should == [2]
+ @array.send(@method, (2..).step(-4)).should == [2]
+
+ @array.send(@method, (-3..).step(-1)).should == [3, 2, 1, 0]
+ @array.send(@method, (-3..).step(-2)).should == [3, 1]
+ @array.send(@method, (-3..).step(-3)).should == [3, 0]
+ @array.send(@method, (-3..).step(-4)).should == [3]
+ @array.send(@method, (-3..).step(-5)).should == [3]
+
+ @array.send(@method, (..0).step(-1)).should == [5, 4, 3, 2, 1, 0]
+ @array.send(@method, (..0).step(-2)).should == [5, 3, 1]
+ @array.send(@method, (..0).step(-3)).should == [5, 2]
+ @array.send(@method, (..0).step(-4)).should == [5, 1]
+ @array.send(@method, (..0).step(-5)).should == [5, 0]
+ @array.send(@method, (..0).step(-6)).should == [5]
+ @array.send(@method, (..0).step(-7)).should == [5]
+
+ @array.send(@method, (...0).step(-1)).should == [5, 4, 3, 2, 1]
+ @array.send(@method, (...0).step(-2)).should == [5, 3, 1]
+ @array.send(@method, (...0).step(-3)).should == [5, 2]
+ @array.send(@method, (...0).step(-4)).should == [5, 1]
+ @array.send(@method, (...0).step(-5)).should == [5]
+ @array.send(@method, (...0).step(-6)).should == [5]
+
+ @array.send(@method, (...1).step(-1)).should == [5, 4, 3, 2]
+ @array.send(@method, (...1).step(-2)).should == [5, 3]
+ @array.send(@method, (...1).step(-3)).should == [5, 2]
+ @array.send(@method, (...1).step(-4)).should == [5]
+ @array.send(@method, (...1).step(-5)).should == [5]
+
+ @array.send(@method, (..-5).step(-1)).should == [5, 4, 3, 2, 1]
+ @array.send(@method, (..-5).step(-2)).should == [5, 3, 1]
+ @array.send(@method, (..-5).step(-3)).should == [5, 2]
+ @array.send(@method, (..-5).step(-4)).should == [5, 1]
+ @array.send(@method, (..-5).step(-5)).should == [5]
+ @array.send(@method, (..-5).step(-6)).should == [5]
+
+ @array.send(@method, (...-5).step(-1)).should == [5, 4, 3, 2]
+ @array.send(@method, (...-5).step(-2)).should == [5, 3]
+ @array.send(@method, (...-5).step(-3)).should == [5, 2]
+ @array.send(@method, (...-5).step(-4)).should == [5]
+ @array.send(@method, (...-5).step(-5)).should == [5]
+
+ @array.send(@method, (4..1).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (4..1).step(-2)).should == [4, 2]
+ @array.send(@method, (4..1).step(-3)).should == [4, 1]
+ @array.send(@method, (4..1).step(-4)).should == [4]
+ @array.send(@method, (4..1).step(-5)).should == [4]
+
+ @array.send(@method, (4...1).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (4...1).step(-2)).should == [4, 2]
+ @array.send(@method, (4...1).step(-3)).should == [4]
+ @array.send(@method, (4...1).step(-4)).should == [4]
+
+ @array.send(@method, (-2..1).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (-2..1).step(-2)).should == [4, 2]
+ @array.send(@method, (-2..1).step(-3)).should == [4, 1]
+ @array.send(@method, (-2..1).step(-4)).should == [4]
+ @array.send(@method, (-2..1).step(-5)).should == [4]
+
+ @array.send(@method, (-2...1).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (-2...1).step(-2)).should == [4, 2]
+ @array.send(@method, (-2...1).step(-3)).should == [4]
+ @array.send(@method, (-2...1).step(-4)).should == [4]
+
+ @array.send(@method, (4..-5).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (4..-5).step(-2)).should == [4, 2]
+ @array.send(@method, (4..-5).step(-3)).should == [4, 1]
+ @array.send(@method, (4..-5).step(-4)).should == [4]
+ @array.send(@method, (4..-5).step(-5)).should == [4]
+
+ @array.send(@method, (4...-5).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (4...-5).step(-2)).should == [4, 2]
+ @array.send(@method, (4...-5).step(-3)).should == [4]
+ @array.send(@method, (4...-5).step(-4)).should == [4]
+
+ @array.send(@method, (-2..-5).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (-2..-5).step(-2)).should == [4, 2]
+ @array.send(@method, (-2..-5).step(-3)).should == [4, 1]
+ @array.send(@method, (-2..-5).step(-4)).should == [4]
+ @array.send(@method, (-2..-5).step(-5)).should == [4]
+
+ @array.send(@method, (-2...-5).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (-2...-5).step(-2)).should == [4, 2]
+ @array.send(@method, (-2...-5).step(-3)).should == [4]
+ @array.send(@method, (-2...-5).step(-4)).should == [4]
end
end
diff --git a/spec/ruby/core/array/shared/unshift.rb b/spec/ruby/core/array/shared/unshift.rb
index 4941e098f6..9e0fe7556a 100644
--- a/spec/ruby/core/array/shared/unshift.rb
+++ b/spec/ruby/core/array/shared/unshift.rb
@@ -49,7 +49,7 @@ describe :array_unshift, shared: true do
-> { ArraySpecs.frozen_array.send(@method) }.should raise_error(FrozenError)
end
- # https://github.com/oracle/truffleruby/issues/2772
+ # https://github.com/truffleruby/truffleruby/issues/2772
it "doesn't rely on Array#[]= so it can be overridden" do
subclass = Class.new(Array) do
def []=(*)
diff --git a/spec/ruby/core/array/shuffle_spec.rb b/spec/ruby/core/array/shuffle_spec.rb
index 1d528c124f..b84394bcb5 100644
--- a/spec/ruby/core/array/shuffle_spec.rb
+++ b/spec/ruby/core/array/shuffle_spec.rb
@@ -69,9 +69,18 @@ describe "Array#shuffle" do
-> { [1, 2].shuffle(random: random) }.should raise_error(RangeError)
end
- it "raises a RangeError if the value is equal to one" do
+ it "raises a RangeError if the value is equal to the Array size" do
value = mock("array_shuffle_random_value")
- value.should_receive(:to_int).at_least(1).times.and_return(1)
+ value.should_receive(:to_int).at_least(1).times.and_return(2)
+ random = mock("array_shuffle_random")
+ random.should_receive(:rand).at_least(1).times.and_return(value)
+
+ -> { [1, 2].shuffle(random: random) }.should raise_error(RangeError)
+ end
+
+ it "raises a RangeError if the value is greater than the Array size" do
+ value = mock("array_shuffle_random_value")
+ value.should_receive(:to_int).at_least(1).times.and_return(3)
random = mock("array_shuffle_random")
random.should_receive(:rand).at_least(1).times.and_return(value)