Skip to content

Commit

Permalink
Update to ruby/spec@4ce9f41
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Dec 27, 2020
1 parent 267bed0 commit 727c97d
Show file tree
Hide file tree
Showing 108 changed files with 1,320 additions and 265 deletions.
4 changes: 2 additions & 2 deletions spec/ruby/CONTRIBUTING.md
Expand Up @@ -124,8 +124,8 @@ If an exception is raised, it will fail the example anyway.

```ruby
-> {
Integer
}.should complain(/constant ::Integer is deprecated/) # Expect a warning
Fixnum
}.should complain(/constant ::Fixnum is deprecated/) # Expect a warning
```

### Guards
Expand Down
3 changes: 2 additions & 1 deletion spec/ruby/README.md
Expand Up @@ -34,7 +34,8 @@ More precisely, every latest stable MRI release should [pass](https://travis-ci.

### Synchronization with Ruby Implementations

The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby.
The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby,
using [this script](https://github.com/ruby/mspec/blob/master/tool/sync/sync-rubyspec.rb).
Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
Any of these repositories can be used to add or edit specs, use what is most convenient for you.

Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/core/argf/bytes_spec.rb
Expand Up @@ -3,6 +3,14 @@

ruby_version_is ''...'3.0' do
describe "ARGF.bytes" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end

after :each do
$VERBOSE = @verbose
end

it_behaves_like :argf_each_byte, :bytes
end
end
8 changes: 8 additions & 0 deletions spec/ruby/core/argf/chars_spec.rb
Expand Up @@ -3,6 +3,14 @@

ruby_version_is ''...'3.0' do
describe "ARGF.chars" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end

after :each do
$VERBOSE = @verbose
end

it_behaves_like :argf_each_char, :chars
end
end
8 changes: 8 additions & 0 deletions spec/ruby/core/argf/codepoints_spec.rb
Expand Up @@ -3,6 +3,14 @@

ruby_version_is ''...'3.0' do
describe "ARGF.codepoints" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end

after :each do
$VERBOSE = @verbose
end

it_behaves_like :argf_each_codepoint, :codepoints
end
end
8 changes: 8 additions & 0 deletions spec/ruby/core/argf/lines_spec.rb
Expand Up @@ -3,6 +3,14 @@

ruby_version_is ''...'3.0' do
describe "ARGF.lines" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end

after :each do
$VERBOSE = @verbose
end

it_behaves_like :argf_each_line, :lines
end
end
48 changes: 47 additions & 1 deletion spec/ruby/core/array/element_set_spec.rb
Expand Up @@ -439,7 +439,6 @@ def obj.to_ary() [1, 2, 3] 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
Expand Down Expand Up @@ -476,6 +475,53 @@ def obj.to_ary() [1, 2, 3] end
end
end

ruby_version_is "2.7" do
describe "Array#[]= with [..n] and [...n]" 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 == [nil, 4, 5]
a[eval("(...2)")] = nil
a.should == [nil, 5]
end

it "just sets the section defined by range to nil if n < 0 and the rhs is nil" do
a = [1, 2, 3, 4, 5]
a[eval("(..-3)")] = nil
a.should == [nil, 4, 5]
a[eval("(...-1)")] = [nil, 5]
end

it "replaces the section defined by range" do
a = [6, 5, 4, 3, 2, 1]
a[eval("(...3)")] = 9
a.should == [9, 3, 2, 1]
a[eval("(..2)")] = [7, 7, 7, 7, 7]
a.should == [7, 7, 7, 7, 7, 1]
end

it "replaces the section if n < 0" do
a = [1, 2, 3, 4, 5]
a[eval("(..-2)")] = [7, 8, 9]
a.should == [7, 8, 9, 5]
end

it "replaces everything if n > the array size" do
a = [1, 2, 3]
a[eval("(...7)")] = [4]
a.should == [4]
end

it "inserts at the beginning if n < negative the array size" do
a = [1, 2, 3]
a[eval("(..-7)")] = [4]
a.should == [4, 1, 2, 3]
a[eval("(...-10)")] = [6]
a.should == [6, 4, 1, 2, 3]
end
end
end

describe "Array#[] after a shift" do
it "works for insertion" do
a = [1,2]
Expand Down
7 changes: 7 additions & 0 deletions spec/ruby/core/array/fill_spec.rb
Expand Up @@ -324,4 +324,11 @@ def obj.<=>(rhs); rhs == self ? 0 : nil end
[1, 2, 3, 4].fill(eval("(3...)")) { |x| x + 2 }.should == [1, 2, 3, 5]
end
end

ruby_version_is "2.7" do
it "works with beginless ranges" do
[1, 2, 3, 4].fill('x', eval("(..2)")).should == ["x", "x", "x", 4]
[1, 2, 3, 4].fill(eval("(...2)")) { |x| x + 2 }.should == [2, 3, 3, 4]
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/array/first_spec.rb
Expand Up @@ -33,7 +33,7 @@
-> { [1, 2].first(-1) }.should raise_error(ArgumentError)
end

it "raises a RangeError when count is an Integer" do
it "raises a RangeError when count is a Bignum" do
-> { [].first(bignum_value) }.should raise_error(RangeError)
end

Expand Down
41 changes: 39 additions & 2 deletions spec/ruby/core/array/shared/slice.rb
Expand Up @@ -486,7 +486,7 @@ def to.to_int() -2 end
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)
Expand All @@ -502,7 +502,7 @@ def to.to_int() -2 end
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)
Expand All @@ -520,4 +520,41 @@ def to.to_int() -2 end
-> { "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
20 changes: 20 additions & 0 deletions spec/ruby/core/array/slice_spec.rb
Expand Up @@ -163,6 +163,26 @@ def to.to_int() -2 end
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
end

ruby_version_is "2.7" do
it "works with beginless ranges" do
a = [0,1,2,3,4]
a.slice!(eval("(..3)")).should == [0, 1, 2, 3]
a.should == [4]

a = [0,1,2,3,4]
a.slice!(eval("(...-2)")).should == [0, 1, 2]
a.should == [3, 4]
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/ruby/core/array/values_at_spec.rb
Expand Up @@ -67,4 +67,11 @@ def to.to_int() -2 end
[1, 2, 3, 4].values_at(eval("(3...)")).should == [4]
end
end

ruby_version_is "2.7" do
it "works when given beginless ranges" do
[1, 2, 3, 4].values_at(eval("(..2)")).should == [1, 2, 3]
[1, 2, 3, 4].values_at(eval("(...2)")).should == [1, 2]
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/complex/coerce_spec.rb
Expand Up @@ -19,7 +19,7 @@
result.last.should be_kind_of(Complex)
end

it "returns an array containing other and self as Complex when other is an Integer" do
it "returns an array containing other and self as Complex when other is a Bignum" do
result = @one.coerce(4294967296)
result.should == [4294967296, 1]
result.first.should be_kind_of(Complex)
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/complex/shared/divide.rb
Expand Up @@ -12,7 +12,7 @@
end
end

describe "with Integer" do
describe "with Fixnum" do
it "divides both parts of the Complex number" do
Complex(20, 40).send(@method, 2).should == Complex(10, 20)
Complex(30, 30).send(@method, 10).should == Complex(3, 3)
Expand All @@ -27,7 +27,7 @@
end
end

describe "with Integer" do
describe "with Bignum" do
it "divides both parts of the Complex number" do
Complex(20, 40).send(@method, 2).should == Complex(10, 20)
Complex(15, 16).send(@method, 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/core/data/constants_spec.rb
Expand Up @@ -13,3 +13,11 @@
end
end
end

ruby_version_is '3.0' do
describe "Data" do
it "does not exist anymore" do
Object.should_not have_constant(:Data)
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerable/first_spec.rb
Expand Up @@ -17,7 +17,7 @@
EnumerableSpecs::YieldsMixed2.new.to_enum.first.should == nil
end

it "raises a RangeError when passed an Integer" do
it "raises a RangeError when passed a Bignum" do
enum = EnumerableSpecs::Empty.new
-> { enum.first(bignum_value) }.should raise_error(RangeError)
end
Expand Down
27 changes: 26 additions & 1 deletion spec/ruby/core/enumerable/shared/collect.rb
Expand Up @@ -51,7 +51,20 @@ def numerous.each(&block)
ScratchPad.recorded.should == [1]
end

it "yields 2 arguments for a Hash" do
it "yields an Array of 2 elements for a Hash when block arity is 1" do
c = Class.new do
def register(a)
ScratchPad << a
end
end
m = c.new.method(:register)

ScratchPad.record []
{ 1 => 'a', 2 => 'b' }.map(&m)
ScratchPad.recorded.should == [[1, 'a'], [2, 'b']]
end

it "yields 2 arguments for a Hash when block arity is 2" do
c = Class.new do
def register(a, b)
ScratchPad << [a, b]
Expand All @@ -64,5 +77,17 @@ def register(a, b)
ScratchPad.recorded.should == [[1, 'a'], [2, 'b']]
end

it "raises an error for a Hash when an arity enforcing block of arity >2 is passed in" do
c = Class.new do
def register(a, b, c)
end
end
m = c.new.method(:register)

-> do
{ 1 => 'a', 2 => 'b' }.map(&m)
end.should raise_error(ArgumentError)
end

it_should_behave_like :enumerable_enumeratorized_with_origin_size
end
4 changes: 3 additions & 1 deletion spec/ruby/core/enumerator/initialize_spec.rb
Expand Up @@ -13,7 +13,9 @@

ruby_version_is ''...'3.0' do
it "returns self when given an object" do
@uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
suppress_warning do
@uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
end
end
end

Expand Down

0 comments on commit 727c97d

Please sign in to comment.