1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-04-28 19:50:06 +00:00
parent b864bd05bf
commit 4fbb9aa3cb
145 changed files with 2847 additions and 2596 deletions

View file

@ -1,86 +1,84 @@
require_relative '../../spec_helper'
require_relative '../enumerable/shared/enumeratorized'
ruby_version_is "2.3" do
describe "Array#bsearch_index" do
context "when not passed a block" do
before :each do
@enum = [1, 2, 42, 100, 666].bsearch_index
end
it "returns an Enumerator" do
@enum.should be_an_instance_of(Enumerator)
end
it "returns an Enumerator with unknown size" do
@enum.size.should be_nil
end
it "returns index of element when block condition is satisfied" do
@enum.each { |x| x >= 33 }.should == 2
end
describe "Array#bsearch_index" do
context "when not passed a block" do
before :each do
@enum = [1, 2, 42, 100, 666].bsearch_index
end
it "raises a TypeError when block returns a String" do
lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError)
it "returns an Enumerator" do
@enum.should be_an_instance_of(Enumerator)
end
it "returns nil when block is empty" do
[1, 2, 3].bsearch_index {}.should be_nil
it "returns an Enumerator with unknown size" do
@enum.size.should be_nil
end
context "minimum mode" do
before :each do
@array = [0, 4, 7, 10, 12]
end
it "returns index of element when block condition is satisfied" do
@enum.each { |x| x >= 33 }.should == 2
end
end
it "returns index of first element which satisfies the block" do
@array.bsearch_index { |x| x >= 4 }.should == 1
@array.bsearch_index { |x| x >= 6 }.should == 2
@array.bsearch_index { |x| x >= -1 }.should == 0
end
it "raises a TypeError when block returns a String" do
lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError)
end
it "returns nil when block condition is never satisfied" do
@array.bsearch_index { false }.should be_nil
@array.bsearch_index { |x| x >= 100 }.should be_nil
end
it "returns nil when block is empty" do
[1, 2, 3].bsearch_index {}.should be_nil
end
context "minimum mode" do
before :each do
@array = [0, 4, 7, 10, 12]
end
context "find any mode" do
before :each do
@array = [0, 4, 7, 10, 12]
end
it "returns index of first element which satisfies the block" do
@array.bsearch_index { |x| x >= 4 }.should == 1
@array.bsearch_index { |x| x >= 6 }.should == 2
@array.bsearch_index { |x| x >= -1 }.should == 0
end
it "returns the index of any matched elements where element is between 4 <= x < 8" do
[1, 2].should include(@array.bsearch_index { |x| 1 - x / 4 })
end
it "returns nil when block condition is never satisfied" do
@array.bsearch_index { false }.should be_nil
@array.bsearch_index { |x| x >= 100 }.should be_nil
end
end
it "returns the index of any matched elements where element is between 8 <= x < 10" do
@array.bsearch_index { |x| 4 - x / 2 }.should be_nil
context "find any mode" do
before :each do
@array = [0, 4, 7, 10, 12]
end
it "returns the index of any matched elements where element is between 4 <= x < 8" do
[1, 2].should include(@array.bsearch_index { |x| 1 - x / 4 })
end
it "returns the index of any matched elements where element is between 8 <= x < 10" do
@array.bsearch_index { |x| 4 - x / 2 }.should be_nil
end
it "returns nil when block never returns 0" do
@array.bsearch_index { |x| 1 }.should be_nil
@array.bsearch_index { |x| -1 }.should be_nil
end
it "returns the middle element when block always returns zero" do
@array.bsearch_index { |x| 0 }.should == 2
end
context "magnitude does not effect the result" do
it "returns the index of any matched elements where element is between 4n <= xn < 8n" do
[1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) })
end
it "returns nil when block never returns 0" do
@array.bsearch_index { |x| 1 }.should be_nil
@array.bsearch_index { |x| -1 }.should be_nil
@array.bsearch_index { |x| 1 * (2**100) }.should be_nil
@array.bsearch_index { |x| (-1) * (2**100) }.should be_nil
end
it "returns the middle element when block always returns zero" do
@array.bsearch_index { |x| 0 }.should == 2
end
context "magnitude does not effect the result" do
it "returns the index of any matched elements where element is between 4n <= xn < 8n" do
[1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) })
end
it "returns nil when block never returns 0" do
@array.bsearch_index { |x| 1 * (2**100) }.should be_nil
@array.bsearch_index { |x| (-1) * (2**100) }.should be_nil
end
it "handles values from Bignum#coerce" do
[1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first })
end
it "handles values from Bignum#coerce" do
[1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first })
end
end
end

View file

@ -1,54 +1,52 @@
require_relative '../../spec_helper'
ruby_version_is '2.3' do
describe "Array#dig" do
it "returns #at with one arg" do
['a'].dig(0).should == 'a'
['a'].dig(1).should be_nil
end
it "recurses array elements" do
a = [ [ 1, [2, '3'] ] ]
a.dig(0, 0).should == 1
a.dig(0, 1, 1).should == '3'
a.dig(0, -1, 0).should == 2
end
it "returns the nested value specified if the sequence includes a key" do
a = [42, { foo: :bar }]
a.dig(1, :foo).should == :bar
end
it "raises a TypeError for a non-numeric index" do
lambda {
['a'].dig(:first)
}.should raise_error(TypeError)
end
it "raises a TypeError if any intermediate step does not respond to #dig" do
a = [1, 2]
lambda {
a.dig(0, 1)
}.should raise_error(TypeError)
end
it "raises an ArgumentError if no arguments provided" do
lambda {
[10].dig()
}.should raise_error(ArgumentError)
end
it "returns nil if any intermediate step is nil" do
a = [[1, [2, 3]]]
a.dig(1, 2, 3).should == nil
end
it "calls #dig on the result of #at with the remaining arguments" do
h = [[nil, [nil, nil, 42]]]
h[0].should_receive(:dig).with(1, 2).and_return(42)
h.dig(0, 1, 2).should == 42
end
describe "Array#dig" do
it "returns #at with one arg" do
['a'].dig(0).should == 'a'
['a'].dig(1).should be_nil
end
it "recurses array elements" do
a = [ [ 1, [2, '3'] ] ]
a.dig(0, 0).should == 1
a.dig(0, 1, 1).should == '3'
a.dig(0, -1, 0).should == 2
end
it "returns the nested value specified if the sequence includes a key" do
a = [42, { foo: :bar }]
a.dig(1, :foo).should == :bar
end
it "raises a TypeError for a non-numeric index" do
lambda {
['a'].dig(:first)
}.should raise_error(TypeError)
end
it "raises a TypeError if any intermediate step does not respond to #dig" do
a = [1, 2]
lambda {
a.dig(0, 1)
}.should raise_error(TypeError)
end
it "raises an ArgumentError if no arguments provided" do
lambda {
[10].dig()
}.should raise_error(ArgumentError)
end
it "returns nil if any intermediate step is nil" do
a = [[1, [2, 3]]]
a.dig(1, 2, 3).should == nil
end
it "calls #dig on the result of #at with the remaining arguments" do
h = [[nil, [nil, nil, 42]]]
h[0].should_receive(:dig).with(1, 2).and_return(42)
h.dig(0, 1, 2).should == 42
end
end

View file

@ -69,12 +69,10 @@ describe "Array#flatten" do
[1, z, 6].flatten.should == [1, 2, 3, 4, 5, 6]
end
ruby_version_is "2.3" do
it "does not call #to_ary on elements beyond the given level" do
obj = mock("1")
obj.should_not_receive(:to_ary)
[[obj]].flatten(1)
end
it "does not call #to_ary on elements beyond the given level" do
obj = mock("1")
obj.should_not_receive(:to_ary)
[[obj]].flatten(1)
end
it "returns subclass instance for Array subclasses" do

View file

@ -4,216 +4,214 @@ require_relative 'shared/basic'
require_relative 'shared/numeric_basic'
require_relative 'shared/integer'
ruby_version_is '2.3' do
platform_is pointer_size: 64 do
platform_is pointer_size: 64 do
describe "Array#pack with format 'J'" do
it_behaves_like :array_pack_basic, 'J'
it_behaves_like :array_pack_basic_non_float, 'J'
it_behaves_like :array_pack_arguments, 'J'
it_behaves_like :array_pack_numeric_basic, 'J'
it_behaves_like :array_pack_integer, 'J'
end
describe "Array#pack with format 'j'" do
it_behaves_like :array_pack_basic, 'j'
it_behaves_like :array_pack_basic_non_float, 'j'
it_behaves_like :array_pack_arguments, 'j'
it_behaves_like :array_pack_numeric_basic, 'j'
it_behaves_like :array_pack_integer, 'j'
end
little_endian do
describe "Array#pack with format 'J'" do
it_behaves_like :array_pack_basic, 'J'
it_behaves_like :array_pack_basic_non_float, 'J'
it_behaves_like :array_pack_arguments, 'J'
it_behaves_like :array_pack_numeric_basic, 'J'
it_behaves_like :array_pack_integer, 'J'
end
describe "Array#pack with format 'j'" do
it_behaves_like :array_pack_basic, 'j'
it_behaves_like :array_pack_basic_non_float, 'j'
it_behaves_like :array_pack_arguments, 'j'
it_behaves_like :array_pack_numeric_basic, 'j'
it_behaves_like :array_pack_integer, 'j'
end
little_endian do
describe "Array#pack with format 'J'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'J_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'J!'
end
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'J_'
end
describe "Array#pack with format 'j'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'j_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'j!'
end
end
end
big_endian do
describe "Array#pack with format 'J'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'J_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'J!'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'j_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'j!'
end
end
end
describe "Array#pack with format 'J'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'J<_'
it_behaves_like :array_pack_64bit_le, 'J_<'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'J<!'
it_behaves_like :array_pack_64bit_le, 'J!<'
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'J>_'
it_behaves_like :array_pack_64bit_be, 'J_>'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'J>!'
it_behaves_like :array_pack_64bit_be, 'J!>'
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'J!'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'j<_'
it_behaves_like :array_pack_64bit_le, 'j_<'
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'j_'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'j<!'
it_behaves_like :array_pack_64bit_le, 'j!<'
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'j>_'
it_behaves_like :array_pack_64bit_be, 'j_>'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'j>!'
it_behaves_like :array_pack_64bit_be, 'j!>'
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'j!'
end
end
end
platform_is pointer_size: 32 do
big_endian do
describe "Array#pack with format 'J'" do
it_behaves_like :array_pack_basic, 'J'
it_behaves_like :array_pack_basic_non_float, 'J'
it_behaves_like :array_pack_arguments, 'J'
it_behaves_like :array_pack_numeric_basic, 'J'
it_behaves_like :array_pack_integer, 'J'
end
describe "Array#pack with format 'j'" do
it_behaves_like :array_pack_basic, 'j'
it_behaves_like :array_pack_basic_non_float, 'j'
it_behaves_like :array_pack_arguments, 'j'
it_behaves_like :array_pack_numeric_basic, 'j'
it_behaves_like :array_pack_integer, 'j'
end
big_endian do
describe "Array#pack with format 'J'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'J_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_be, 'J!'
end
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'J_'
end
describe "Array#pack with format 'j'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'j_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_be, 'j!'
end
end
end
little_endian do
describe "Array#pack with format 'J'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'J_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_le, 'J!'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'j_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_le, 'j!'
end
end
end
describe "Array#pack with format 'J'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'J<_'
it_behaves_like :array_pack_32bit_le, 'J_<'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_32bit_le, 'J<!'
it_behaves_like :array_pack_32bit_le, 'J!<'
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_32bit_be, 'J>_'
it_behaves_like :array_pack_32bit_be, 'J_>'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_32bit_be, 'J>!'
it_behaves_like :array_pack_32bit_be, 'J!>'
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'J!'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'j<_'
it_behaves_like :array_pack_32bit_le, 'j_<'
describe "with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'j_'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_32bit_le, 'j<!'
it_behaves_like :array_pack_32bit_le, 'j!<'
describe "with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'j!'
end
end
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_32bit_be, 'j>_'
it_behaves_like :array_pack_32bit_be, 'j_>'
end
describe "Array#pack with format 'J'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'J<_'
it_behaves_like :array_pack_64bit_le, 'J_<'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_32bit_be, 'j>!'
it_behaves_like :array_pack_32bit_be, 'j!>'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'J<!'
it_behaves_like :array_pack_64bit_le, 'J!<'
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'J>_'
it_behaves_like :array_pack_64bit_be, 'J_>'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'J>!'
it_behaves_like :array_pack_64bit_be, 'J!>'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'j<_'
it_behaves_like :array_pack_64bit_le, 'j_<'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'j<!'
it_behaves_like :array_pack_64bit_le, 'j!<'
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'j>_'
it_behaves_like :array_pack_64bit_be, 'j_>'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'j>!'
it_behaves_like :array_pack_64bit_be, 'j!>'
end
end
end
platform_is pointer_size: 32 do
describe "Array#pack with format 'J'" do
it_behaves_like :array_pack_basic, 'J'
it_behaves_like :array_pack_basic_non_float, 'J'
it_behaves_like :array_pack_arguments, 'J'
it_behaves_like :array_pack_numeric_basic, 'J'
it_behaves_like :array_pack_integer, 'J'
end
describe "Array#pack with format 'j'" do
it_behaves_like :array_pack_basic, 'j'
it_behaves_like :array_pack_basic_non_float, 'j'
it_behaves_like :array_pack_arguments, 'j'
it_behaves_like :array_pack_numeric_basic, 'j'
it_behaves_like :array_pack_integer, 'j'
end
big_endian do
describe "Array#pack with format 'J'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'J_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_be, 'J!'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'j_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_be, 'j!'
end
end
end
little_endian do
describe "Array#pack with format 'J'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'J_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_le, 'J!'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'j_'
end
describe "with modifier '!'" do
it_behaves_like :array_pack_32bit_le, 'j!'
end
end
end
describe "Array#pack with format 'J'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'J<_'
it_behaves_like :array_pack_32bit_le, 'J_<'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_32bit_le, 'J<!'
it_behaves_like :array_pack_32bit_le, 'J!<'
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_32bit_be, 'J>_'
it_behaves_like :array_pack_32bit_be, 'J_>'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_32bit_be, 'J>!'
it_behaves_like :array_pack_32bit_be, 'J!>'
end
end
describe "Array#pack with format 'j'" do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'j<_'
it_behaves_like :array_pack_32bit_le, 'j_<'
end
describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_32bit_le, 'j<!'
it_behaves_like :array_pack_32bit_le, 'j!<'
end
describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_32bit_be, 'j>_'
it_behaves_like :array_pack_32bit_be, 'j_>'
end
describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_32bit_be, 'j>!'
it_behaves_like :array_pack_32bit_be, 'j!>'
end
end
end

View file

@ -3,25 +3,11 @@ describe :delete_if, shared: true do
@object = [1,2,3]
end
ruby_version_is "2.3" do
it "updates the receiver after all blocks" do
@object.send(@method) do |e|
@object.length.should == 3
true
end
@object.length.should == 0
end
end
ruby_version_is ""..."2.3" do
it "updates the receiver after each true block" do
count = 0
@object.send(@method) do |e|
@object.length.should == (3 - count)
count += 1
true
end
@object.length.should == 0
it "updates the receiver after all blocks" do
@object.send(@method) do |e|
@object.length.should == 3
true
end
@object.length.should == 0
end
end

View file

@ -121,24 +121,11 @@ describe :array_inspect, shared: true do
array.send(@method).encoding.name.should == "US-ASCII"
end
ruby_version_is ''...'2.3' do
it "raises if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
lambda {
[utf_16be].send(@method)
}.should raise_error(Encoding::CompatibilityError)
end
end
ruby_version_is '2.3' do
it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
[utf_16be].send(@method).should == '["utf_16be \u3042"]'
end
[utf_16be].send(@method).should == '["utf_16be \u3042"]'
end
end
end