ruby-changes:64632
From: Benoit <ko1@a...>
Date: Mon, 28 Dec 2020 01:39:14 +0900 (JST)
Subject: [ruby-changes:64632] 727c97da19 (master): Update to ruby/spec@4ce9f41
https://git.ruby-lang.org/ruby.git/commit/?id=727c97da19 From 727c97da1977544c91b9b3677811da3a44af7d53 Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Sun, 27 Dec 2020 17:35:32 +0100 Subject: Update to ruby/spec@4ce9f41 diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md index 56e1273..e470a81 100644 --- a/spec/ruby/CONTRIBUTING.md +++ b/spec/ruby/CONTRIBUTING.md @@ -124,8 +124,8 @@ If an exception is raised, it will fail the example anyway. https://github.com/ruby/ruby/blob/trunk/spec/ruby/CONTRIBUTING.md#L124 ```ruby -> { - Integer -}.should complain(/constant ::Integer is deprecated/) # Expect a warning + Fixnum +}.should complain(/constant ::Fixnum is deprecated/) # Expect a warning ``` ### Guards diff --git a/spec/ruby/README.md b/spec/ruby/README.md index 932cd83..8bdba2c 100644 --- a/spec/ruby/README.md +++ b/spec/ruby/README.md @@ -34,7 +34,8 @@ More precisely, every latest stable MRI release should [pass](https://travis-ci. https://github.com/ruby/ruby/blob/trunk/spec/ruby/README.md#L34 ### 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. diff --git a/spec/ruby/core/argf/bytes_spec.rb b/spec/ruby/core/argf/bytes_spec.rb index 3e11a4f..bf35ded 100644 --- a/spec/ruby/core/argf/bytes_spec.rb +++ b/spec/ruby/core/argf/bytes_spec.rb @@ -3,6 +3,14 @@ require_relative 'shared/each_byte' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/argf/bytes_spec.rb#L3 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 diff --git a/spec/ruby/core/argf/chars_spec.rb b/spec/ruby/core/argf/chars_spec.rb index a864ce6..6af73cd 100644 --- a/spec/ruby/core/argf/chars_spec.rb +++ b/spec/ruby/core/argf/chars_spec.rb @@ -3,6 +3,14 @@ require_relative 'shared/each_char' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/argf/chars_spec.rb#L3 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 diff --git a/spec/ruby/core/argf/codepoints_spec.rb b/spec/ruby/core/argf/codepoints_spec.rb index d3007c4..bb28c17 100644 --- a/spec/ruby/core/argf/codepoints_spec.rb +++ b/spec/ruby/core/argf/codepoints_spec.rb @@ -3,6 +3,14 @@ require_relative 'shared/each_codepoint' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/argf/codepoints_spec.rb#L3 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 diff --git a/spec/ruby/core/argf/lines_spec.rb b/spec/ruby/core/argf/lines_spec.rb index 0bf5bb0..e964dbd 100644 --- a/spec/ruby/core/argf/lines_spec.rb +++ b/spec/ruby/core/argf/lines_spec.rb @@ -3,6 +3,14 @@ require_relative 'shared/each_line' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/argf/lines_spec.rb#L3 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 diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb index 2e01e83..1c143f3 100644 --- a/spec/ruby/core/array/element_set_spec.rb +++ b/spec/ruby/core/array/element_set_spec.rb @@ -439,7 +439,6 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/element_set_spec.rb#L439 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 @@ -476,6 +475,53 @@ ruby_version_is "2.6" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/element_set_spec.rb#L475 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] diff --git a/spec/ruby/core/array/fill_spec.rb b/spec/ruby/core/array/fill_spec.rb index 6745bc8..8f0814a 100644 --- a/spec/ruby/core/array/fill_spec.rb +++ b/spec/ruby/core/array/fill_spec.rb @@ -324,4 +324,11 @@ describe "Array#fill with (filler, range)" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/fill_spec.rb#L324 [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 diff --git a/spec/ruby/core/array/first_spec.rb b/spec/ruby/core/array/first_spec.rb index 463da82..66eeba6 100644 --- a/spec/ruby/core/array/first_spec.rb +++ b/spec/ruby/core/array/first_spec.rb @@ -33,7 +33,7 @@ describe "Array#first" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/first_spec.rb#L33 -> { [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 diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb index 820047c..6818bad 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/shared/slice.rb#L486 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/shared/slice.rb#L502 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/shared/slice.rb#L520 -> { "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 (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/