summaryrefslogtreecommitdiff
path: root/spec/ruby/core/array
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-07-29 22:11:21 +0200
committerBenoit Daloze <eregontp@gmail.com>2021-07-29 22:11:21 +0200
commit6998d758248d778fa95b008c78d05473e48b8428 (patch)
tree8abc6926f647ea5f374a5b34c3a4820c5861e32e /spec/ruby/core/array
parent15d05f8120745a121b93fab9fd2addf5f094e8d2 (diff)
Update to ruby/spec@b65d01f
Diffstat (limited to 'spec/ruby/core/array')
-rw-r--r--spec/ruby/core/array/difference_spec.rb28
-rw-r--r--spec/ruby/core/array/element_set_spec.rb60
-rw-r--r--spec/ruby/core/array/fill_spec.rb12
-rw-r--r--spec/ruby/core/array/filter_spec.rb18
-rw-r--r--spec/ruby/core/array/shared/slice.rb22
-rw-r--r--spec/ruby/core/array/slice_spec.rb34
-rw-r--r--spec/ruby/core/array/to_h_spec.rb72
-rw-r--r--spec/ruby/core/array/union_spec.rb26
-rw-r--r--spec/ruby/core/array/values_at_spec.rb8
9 files changed, 131 insertions, 149 deletions
diff --git a/spec/ruby/core/array/difference_spec.rb b/spec/ruby/core/array/difference_spec.rb
index a357657967..9f7d4c4a1a 100644
--- a/spec/ruby/core/array/difference_spec.rb
+++ b/spec/ruby/core/array/difference_spec.rb
@@ -2,23 +2,21 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'shared/difference'
-ruby_version_is "2.6" do
- describe "Array#difference" do
- it_behaves_like :array_binary_difference, :difference
+describe "Array#difference" do
+ it_behaves_like :array_binary_difference, :difference
- it "returns a copy when called without any parameter" do
- x = [1, 2, 3, 2]
- x.difference.should == x
- x.difference.should_not equal x
- end
+ it "returns a copy when called without any parameter" do
+ x = [1, 2, 3, 2]
+ x.difference.should == x
+ x.difference.should_not equal x
+ end
- it "does not return subclass instances for Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].difference.should be_an_instance_of(Array)
- end
+ it "does not return subclass instances for Array subclasses" do
+ ArraySpecs::MyArray[1, 2, 3].difference.should be_an_instance_of(Array)
+ end
- it "accepts multiple arguments" do
- x = [1, 2, 3, 1]
- x.difference([], [0, 1], [3, 4], [3]).should == [2]
- end
+ it "accepts multiple arguments" do
+ x = [1, 2, 3, 1]
+ x.difference([], [0, 1], [3, 4], [3]).should == [2]
end
end
diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb
index 07c64b919e..1e192c100f 100644
--- a/spec/ruby/core/array/element_set_spec.rb
+++ b/spec/ruby/core/array/element_set_spec.rb
@@ -445,41 +445,39 @@ describe "Array#[]= with [m..n]" do
end
end
-ruby_version_is "2.6" do
- describe "Array#[]= with [m..]" do
- it "just sets the section defined by range to nil even if the rhs is nil" do
- a = [1, 2, 3, 4, 5]
- a[eval("(2..)")] = nil
- a.should == [1, 2, nil]
- end
+describe "Array#[]= with [m..]" do
+ it "just sets the section defined by range to nil even if the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[eval("(2..)")] = nil
+ a.should == [1, 2, nil]
+ end
- it "just sets the section defined by range to nil if m and n < 0 and the rhs is nil" do
- a = [1, 2, 3, 4, 5]
- a[eval("(-3..)")] = nil
- a.should == [1, 2, nil]
- end
+ it "just sets the section defined by range to nil if m and n < 0 and the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[eval("(-3..)")] = nil
+ a.should == [1, 2, nil]
+ end
- it "replaces the section defined by range" do
- a = [6, 5, 4, 3, 2, 1]
- a[eval("(3...)")] = 9
- a.should == [6, 5, 4, 9]
- a[eval("(2..)")] = [7, 7, 7]
- a.should == [6, 5, 7, 7, 7]
- end
+ it "replaces the section defined by range" do
+ a = [6, 5, 4, 3, 2, 1]
+ a[eval("(3...)")] = 9
+ a.should == [6, 5, 4, 9]
+ a[eval("(2..)")] = [7, 7, 7]
+ a.should == [6, 5, 7, 7, 7]
+ end
- it "replaces the section if m and n < 0" do
- a = [1, 2, 3, 4, 5]
- a[eval("(-3..)")] = [7, 8, 9]
- a.should == [1, 2, 7, 8, 9]
- end
+ it "replaces the section if m and n < 0" do
+ a = [1, 2, 3, 4, 5]
+ a[eval("(-3..)")] = [7, 8, 9]
+ a.should == [1, 2, 7, 8, 9]
+ end
- it "inserts at the end if m > the array size" do
- a = [1, 2, 3]
- a[eval("(3..)")] = [4]
- a.should == [1, 2, 3, 4]
- a[eval("(5..)")] = [6]
- a.should == [1, 2, 3, 4, nil, 6]
- end
+ it "inserts at the end if m > the array size" do
+ a = [1, 2, 3]
+ a[eval("(3..)")] = [4]
+ a.should == [1, 2, 3, 4]
+ a[eval("(5..)")] = [6]
+ a.should == [1, 2, 3, 4, nil, 6]
end
end
diff --git a/spec/ruby/core/array/fill_spec.rb b/spec/ruby/core/array/fill_spec.rb
index 8f0814a5da..bfa8db551b 100644
--- a/spec/ruby/core/array/fill_spec.rb
+++ b/spec/ruby/core/array/fill_spec.rb
@@ -316,13 +316,11 @@ describe "Array#fill with (filler, range)" do
-> { [].fill('a', obj..obj) }.should raise_error(TypeError)
end
- ruby_version_is "2.6" do
- it "works with endless ranges" do
- [1, 2, 3, 4].fill('x', eval("(1..)")).should == [1, 'x', 'x', 'x']
- [1, 2, 3, 4].fill('x', eval("(3...)")).should == [1, 2, 3, 'x']
- [1, 2, 3, 4].fill(eval("(1..)")) { |x| x + 2 }.should == [1, 3, 4, 5]
- [1, 2, 3, 4].fill(eval("(3...)")) { |x| x + 2 }.should == [1, 2, 3, 5]
- end
+ it "works with endless ranges" do
+ [1, 2, 3, 4].fill('x', eval("(1..)")).should == [1, 'x', 'x', 'x']
+ [1, 2, 3, 4].fill('x', eval("(3...)")).should == [1, 2, 3, 'x']
+ [1, 2, 3, 4].fill(eval("(1..)")) { |x| x + 2 }.should == [1, 3, 4, 5]
+ [1, 2, 3, 4].fill(eval("(3...)")) { |x| x + 2 }.should == [1, 2, 3, 5]
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/array/filter_spec.rb b/spec/ruby/core/array/filter_spec.rb
index ee4f71ca28..156ad14f9c 100644
--- a/spec/ruby/core/array/filter_spec.rb
+++ b/spec/ruby/core/array/filter_spec.rb
@@ -1,16 +1,14 @@
require_relative '../../spec_helper'
require_relative 'shared/select'
-ruby_version_is "2.6" do
- describe "Array#filter" do
- it_behaves_like :array_select, :filter
- end
-
- describe "Array#filter!" do
- it "returns nil if no changes were made in the array" do
- [1, 2, 3].filter! { true }.should be_nil
- end
+describe "Array#filter" do
+ it_behaves_like :array_select, :filter
+end
- it_behaves_like :keep_if, :filter!
+describe "Array#filter!" do
+ it "returns nil if no changes were made in the array" do
+ [1, 2, 3].filter! { true }.should be_nil
end
+
+ it_behaves_like :keep_if, :filter!
end
diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb
index 6818badeda..19e1a3ee2b 100644
--- a/spec/ruby/core/array/shared/slice.rb
+++ b/spec/ruby/core/array/shared/slice.rb
@@ -521,18 +521,16 @@ describe :array_slice, shared: true do
-> { "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
+ 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
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/array/slice_spec.rb b/spec/ruby/core/array/slice_spec.rb
index 2f98df9488..8c276f9084 100644
--- a/spec/ruby/core/array/slice_spec.rb
+++ b/spec/ruby/core/array/slice_spec.rb
@@ -154,24 +154,22 @@ describe "Array#slice!" do
-> { ArraySpecs.frozen_array.slice!(0, 0) }.should raise_error(FrozenError)
end
- ruby_version_is "2.6" do
- it "works with endless ranges" do
- a = [1, 2, 3]
- a.slice!(eval("(1..)")).should == [2, 3]
- a.should == [1]
-
- a = [1, 2, 3]
- a.slice!(eval("(2...)")).should == [3]
- a.should == [1, 2]
-
- a = [1, 2, 3]
- a.slice!(eval("(-2..)")).should == [2, 3]
- a.should == [1]
-
- a = [1, 2, 3]
- a.slice!(eval("(-1...)")).should == [3]
- a.should == [1, 2]
- end
+ it "works with endless ranges" do
+ a = [1, 2, 3]
+ a.slice!(eval("(1..)")).should == [2, 3]
+ a.should == [1]
+
+ a = [1, 2, 3]
+ a.slice!(eval("(2...)")).should == [3]
+ a.should == [1, 2]
+
+ a = [1, 2, 3]
+ a.slice!(eval("(-2..)")).should == [2, 3]
+ a.should == [1]
+
+ a = [1, 2, 3]
+ a.slice!(eval("(-1...)")).should == [3]
+ a.should == [1, 2]
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/array/to_h_spec.rb b/spec/ruby/core/array/to_h_spec.rb
index 46a79ba58b..f5a7e546e6 100644
--- a/spec/ruby/core/array/to_h_spec.rb
+++ b/spec/ruby/core/array/to_h_spec.rb
@@ -39,43 +39,41 @@ describe "Array#to_h" do
[[:a, 1], [:b, 2]].to_h[:c].should be_nil
end
- ruby_version_is "2.6" do
- context "with block" do
- it "converts [key, value] pairs returned by the block to a Hash" do
- [:a, :b].to_h { |k| [k, k.to_s] }.should == { a: 'a', b: 'b' }
- end
-
- it "raises ArgumentError if block returns longer or shorter array" do
- -> do
- [:a, :b].to_h { |k| [k, k.to_s, 1] }
- end.should raise_error(ArgumentError, /wrong array length at 0/)
-
- -> do
- [:a, :b].to_h { |k| [k] }
- end.should raise_error(ArgumentError, /wrong array length at 0/)
- end
-
- it "raises TypeError if block returns something other than Array" do
- -> do
- [:a, :b].to_h { |k| "not-array" }
- end.should raise_error(TypeError, /wrong element type String at 0/)
- end
-
- it "coerces returned pair to Array with #to_ary" do
- x = mock('x')
- x.stub!(:to_ary).and_return([:b, 'b'])
-
- [:a].to_h { |k| x }.should == { :b => 'b' }
- end
-
- it "does not coerce returned pair to Array with #to_a" do
- x = mock('x')
- x.stub!(:to_a).and_return([:b, 'b'])
-
- -> do
- [:a].to_h { |k| x }
- end.should raise_error(TypeError, /wrong element type MockObject at 0/)
- end
+ context "with block" do
+ it "converts [key, value] pairs returned by the block to a Hash" do
+ [:a, :b].to_h { |k| [k, k.to_s] }.should == { a: 'a', b: 'b' }
+ end
+
+ it "raises ArgumentError if block returns longer or shorter array" do
+ -> do
+ [:a, :b].to_h { |k| [k, k.to_s, 1] }
+ end.should raise_error(ArgumentError, /wrong array length at 0/)
+
+ -> do
+ [:a, :b].to_h { |k| [k] }
+ end.should raise_error(ArgumentError, /wrong array length at 0/)
+ end
+
+ it "raises TypeError if block returns something other than Array" do
+ -> do
+ [:a, :b].to_h { |k| "not-array" }
+ end.should raise_error(TypeError, /wrong element type String at 0/)
+ end
+
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+
+ [:a].to_h { |k| x }.should == { :b => 'b' }
+ end
+
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+
+ -> do
+ [:a].to_h { |k| x }
+ end.should raise_error(TypeError, /wrong element type MockObject at 0/)
end
end
end
diff --git a/spec/ruby/core/array/union_spec.rb b/spec/ruby/core/array/union_spec.rb
index 1dca47696d..ba2cc0d6b7 100644
--- a/spec/ruby/core/array/union_spec.rb
+++ b/spec/ruby/core/array/union_spec.rb
@@ -6,22 +6,20 @@ describe "Array#|" do
it_behaves_like :array_binary_union, :|
end
-ruby_version_is "2.6" do
- describe "Array#union" do
- it_behaves_like :array_binary_union, :union
+describe "Array#union" do
+ it_behaves_like :array_binary_union, :union
- it "returns unique elements when given no argument" do
- x = [1, 2, 3, 2]
- x.union.should == [1, 2, 3]
- end
+ it "returns unique elements when given no argument" do
+ x = [1, 2, 3, 2]
+ x.union.should == [1, 2, 3]
+ end
- it "does not return subclass instances for Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].union.should be_an_instance_of(Array)
- end
+ it "does not return subclass instances for Array subclasses" do
+ ArraySpecs::MyArray[1, 2, 3].union.should be_an_instance_of(Array)
+ end
- it "accepts multiple arguments" do
- x = [1, 2, 3]
- x.union(x, x, x, x, [3, 4], x).should == [1, 2, 3, 4]
- end
+ it "accepts multiple arguments" do
+ x = [1, 2, 3]
+ x.union(x, x, x, x, [3, 4], x).should == [1, 2, 3, 4]
end
end
diff --git a/spec/ruby/core/array/values_at_spec.rb b/spec/ruby/core/array/values_at_spec.rb
index 019152c51c..f1522e0bfe 100644
--- a/spec/ruby/core/array/values_at_spec.rb
+++ b/spec/ruby/core/array/values_at_spec.rb
@@ -61,11 +61,9 @@ describe "Array#values_at" do
ArraySpecs::MyArray[1, 2, 3].values_at(0, 1..2, 1).should be_an_instance_of(Array)
end
- ruby_version_is "2.6" do
- it "works when given endless ranges" do
- [1, 2, 3, 4].values_at(eval("(1..)")).should == [2, 3, 4]
- [1, 2, 3, 4].values_at(eval("(3...)")).should == [4]
- end
+ it "works when given endless ranges" do
+ [1, 2, 3, 4].values_at(eval("(1..)")).should == [2, 3, 4]
+ [1, 2, 3, 4].values_at(eval("(3...)")).should == [4]
end
ruby_version_is "2.7" do