Skip to content

Commit 5c6ddc7

Browse files
committed
[GR-14806] Update specs
PullRequest: truffleruby/3470
2 parents ea16721 + 5c9baa9 commit 5c6ddc7

File tree

21 files changed

+396
-26
lines changed

21 files changed

+396
-26
lines changed

spec/ruby/CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ end
175175

176176
#### Guard for bug
177177

178-
In case there is a bug in MRI but the expected behavior is obvious.
178+
In case there is a bug in MRI and the fix will be backported to previous versions.
179+
If it is not backported or not likely, use `ruby_version_is` instead.
179180
First, file a bug at https://bugs.ruby-lang.org/.
180-
It is better to use a `ruby_version_is` guard if there was a release with the fix.
181+
The problem is `ruby_bug` would make non-MRI implementations fail this spec while MRI itself does not pass it, so it should only be used if the bug is/will be fixed and backported.
181182

182183
```ruby
183184
ruby_bug '#13669', ''...'3.2' do

spec/ruby/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,9 @@ The file `/etc/services` is required for socket specs (package `netbase` on Debi
144144

145145
### Socket specs from rubysl-socket
146146

147-
Most specs under `library/socket` were imported from [the rubysl-socket project](https://github.com/rubysl/rubysl-socket).
147+
Most specs under `library/socket` were imported from the rubysl-socket project (which is no longer on GitHub).
148148
The 3 copyright holders of rubysl-socket, Yorick Peterse, Chuck Remes and
149-
Brian Shirai, [agreed to relicense those specs](https://github.com/rubysl/rubysl-socket/issues/15)
150-
under the MIT license in ruby/spec.
149+
Brian Shirai, agreed to relicense those specs under the MIT license in ruby/spec.
151150

152151
### History and RubySpec
153152

spec/ruby/core/array/shared/slice.rb

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,102 @@ def to.to_int() -2 end
784784
a.send(@method, (...-9)).should == []
785785
end
786786

787+
ruby_version_is "3.2" do
788+
describe "can be sliced with Enumerator::ArithmeticSequence" do
789+
it "with infinite/inverted ranges and negative steps" do
790+
@array = [0, 1, 2, 3, 4, 5]
791+
@array.send(@method, (2..).step(-1)).should == [2, 1, 0]
792+
@array.send(@method, (2..).step(-2)).should == [2, 0]
793+
@array.send(@method, (2..).step(-3)).should == [2]
794+
@array.send(@method, (2..).step(-4)).should == [2]
795+
796+
@array.send(@method, (-3..).step(-1)).should == [3, 2, 1, 0]
797+
@array.send(@method, (-3..).step(-2)).should == [3, 1]
798+
@array.send(@method, (-3..).step(-3)).should == [3, 0]
799+
@array.send(@method, (-3..).step(-4)).should == [3]
800+
@array.send(@method, (-3..).step(-5)).should == [3]
801+
802+
@array.send(@method, (..0).step(-1)).should == [5, 4, 3, 2, 1, 0]
803+
@array.send(@method, (..0).step(-2)).should == [5, 3, 1]
804+
@array.send(@method, (..0).step(-3)).should == [5, 2]
805+
@array.send(@method, (..0).step(-4)).should == [5, 1]
806+
@array.send(@method, (..0).step(-5)).should == [5, 0]
807+
@array.send(@method, (..0).step(-6)).should == [5]
808+
@array.send(@method, (..0).step(-7)).should == [5]
809+
810+
@array.send(@method, (...0).step(-1)).should == [5, 4, 3, 2, 1]
811+
@array.send(@method, (...0).step(-2)).should == [5, 3, 1]
812+
@array.send(@method, (...0).step(-3)).should == [5, 2]
813+
@array.send(@method, (...0).step(-4)).should == [5, 1]
814+
@array.send(@method, (...0).step(-5)).should == [5]
815+
@array.send(@method, (...0).step(-6)).should == [5]
816+
817+
@array.send(@method, (...1).step(-1)).should == [5, 4, 3, 2]
818+
@array.send(@method, (...1).step(-2)).should == [5, 3]
819+
@array.send(@method, (...1).step(-3)).should == [5, 2]
820+
@array.send(@method, (...1).step(-4)).should == [5]
821+
@array.send(@method, (...1).step(-5)).should == [5]
822+
823+
@array.send(@method, (..-5).step(-1)).should == [5, 4, 3, 2, 1]
824+
@array.send(@method, (..-5).step(-2)).should == [5, 3, 1]
825+
@array.send(@method, (..-5).step(-3)).should == [5, 2]
826+
@array.send(@method, (..-5).step(-4)).should == [5, 1]
827+
@array.send(@method, (..-5).step(-5)).should == [5]
828+
@array.send(@method, (..-5).step(-6)).should == [5]
829+
830+
@array.send(@method, (...-5).step(-1)).should == [5, 4, 3, 2]
831+
@array.send(@method, (...-5).step(-2)).should == [5, 3]
832+
@array.send(@method, (...-5).step(-3)).should == [5, 2]
833+
@array.send(@method, (...-5).step(-4)).should == [5]
834+
@array.send(@method, (...-5).step(-5)).should == [5]
835+
836+
@array.send(@method, (4..1).step(-1)).should == [4, 3, 2, 1]
837+
@array.send(@method, (4..1).step(-2)).should == [4, 2]
838+
@array.send(@method, (4..1).step(-3)).should == [4, 1]
839+
@array.send(@method, (4..1).step(-4)).should == [4]
840+
@array.send(@method, (4..1).step(-5)).should == [4]
841+
842+
@array.send(@method, (4...1).step(-1)).should == [4, 3, 2]
843+
@array.send(@method, (4...1).step(-2)).should == [4, 2]
844+
@array.send(@method, (4...1).step(-3)).should == [4]
845+
@array.send(@method, (4...1).step(-4)).should == [4]
846+
847+
@array.send(@method, (-2..1).step(-1)).should == [4, 3, 2, 1]
848+
@array.send(@method, (-2..1).step(-2)).should == [4, 2]
849+
@array.send(@method, (-2..1).step(-3)).should == [4, 1]
850+
@array.send(@method, (-2..1).step(-4)).should == [4]
851+
@array.send(@method, (-2..1).step(-5)).should == [4]
852+
853+
@array.send(@method, (-2...1).step(-1)).should == [4, 3, 2]
854+
@array.send(@method, (-2...1).step(-2)).should == [4, 2]
855+
@array.send(@method, (-2...1).step(-3)).should == [4]
856+
@array.send(@method, (-2...1).step(-4)).should == [4]
857+
858+
@array.send(@method, (4..-5).step(-1)).should == [4, 3, 2, 1]
859+
@array.send(@method, (4..-5).step(-2)).should == [4, 2]
860+
@array.send(@method, (4..-5).step(-3)).should == [4, 1]
861+
@array.send(@method, (4..-5).step(-4)).should == [4]
862+
@array.send(@method, (4..-5).step(-5)).should == [4]
863+
864+
@array.send(@method, (4...-5).step(-1)).should == [4, 3, 2]
865+
@array.send(@method, (4...-5).step(-2)).should == [4, 2]
866+
@array.send(@method, (4...-5).step(-3)).should == [4]
867+
@array.send(@method, (4...-5).step(-4)).should == [4]
868+
869+
@array.send(@method, (-2..-5).step(-1)).should == [4, 3, 2, 1]
870+
@array.send(@method, (-2..-5).step(-2)).should == [4, 2]
871+
@array.send(@method, (-2..-5).step(-3)).should == [4, 1]
872+
@array.send(@method, (-2..-5).step(-4)).should == [4]
873+
@array.send(@method, (-2..-5).step(-5)).should == [4]
874+
875+
@array.send(@method, (-2...-5).step(-1)).should == [4, 3, 2]
876+
@array.send(@method, (-2...-5).step(-2)).should == [4, 2]
877+
@array.send(@method, (-2...-5).step(-3)).should == [4]
878+
@array.send(@method, (-2...-5).step(-4)).should == [4]
879+
end
880+
end
881+
end
882+
787883
it "can accept nil...nil ranges" do
788884
a = [0, 1, 2, 3, 4, 5]
789885
a.send(@method, eval("(nil...nil)")).should == a

spec/ruby/core/io/read_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@
104104
str = IO.read(@fname, encoding: Encoding::ISO_8859_1)
105105
str.encoding.should == Encoding::ISO_8859_1
106106
end
107+
108+
platform_is :windows do
109+
it "reads the file in text mode" do
110+
# 0x1A is CTRL+Z and is EOF in Windows text mode.
111+
File.binwrite(@fname, "\x1Abbb")
112+
IO.read(@fname).should.empty?
113+
end
114+
end
107115
end
108116

109117
describe "IO.read from a pipe" do

spec/ruby/core/kernel/fixtures/warn_core_method.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
raise 'should be run without RubyGems' if defined?(Gem)
22

3-
def deprecated(n=1)
3+
public def deprecated(n=1)
44
# puts nil, caller(0), nil
55
warn "use X instead", uplevel: n
66
end

spec/ruby/core/kernel/shared/sprintf.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,28 @@ def obj.to_i; 10; end
289289
@method.call("%c", "a").should == "a"
290290
end
291291

292-
it "raises ArgumentError if argument is a string of several characters" do
293-
-> {
294-
@method.call("%c", "abc")
295-
}.should raise_error(ArgumentError, /%c requires a character/)
292+
ruby_version_is ""..."3.2" do
293+
it "raises ArgumentError if argument is a string of several characters" do
294+
-> {
295+
@method.call("%c", "abc")
296+
}.should raise_error(ArgumentError, /%c requires a character/)
297+
end
298+
299+
it "raises ArgumentError if argument is an empty string" do
300+
-> {
301+
@method.call("%c", "")
302+
}.should raise_error(ArgumentError, /%c requires a character/)
303+
end
296304
end
297305

298-
it "raises ArgumentError if argument is an empty string" do
299-
-> {
300-
@method.call("%c", "")
301-
}.should raise_error(ArgumentError, /%c requires a character/)
306+
ruby_version_is "3.2" do
307+
it "displays only the first character if argument is a string of several characters" do
308+
@method.call("%c", "abc").should == "a"
309+
end
310+
311+
it "displays no characters if argument is an empty string" do
312+
@method.call("%c", "").should == ""
313+
end
302314
end
303315

304316
it "raises TypeError if argument is not String or Integer and cannot be converted to them" do

spec/ruby/core/regexp/new_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
describe "Regexp.new given a non-String/Regexp" do
1818
it_behaves_like :regexp_new_non_string_or_regexp, :new
19-
end
19+
end

spec/ruby/core/string/modulo_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,16 @@ def universal.to_f() 0.0 end
368368
("%c" % 'A').should == "A"
369369
end
370370

371-
it "raises an exception for multiple character strings as argument for %c" do
372-
-> { "%c" % 'AA' }.should raise_error(ArgumentError)
371+
ruby_version_is ""..."3.2" do
372+
it "raises an exception for multiple character strings as argument for %c" do
373+
-> { "%c" % 'AA' }.should raise_error(ArgumentError)
374+
end
375+
end
376+
377+
ruby_version_is "3.2" do
378+
it "supports only the first character as argument for %c" do
379+
("%c" % 'AA').should == "A"
380+
end
373381
end
374382

375383
it "calls to_str on argument for %c formats" do

spec/ruby/core/symbol/to_proc_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@
4646
end
4747
end
4848

49+
ruby_version_is "3.2" do
50+
it "only calls public methods" do
51+
body = proc do
52+
public def pub; @a << :pub end
53+
protected def pro; @a << :pro end
54+
private def pri; @a << :pri end
55+
attr_reader :a
56+
end
57+
58+
@a = []
59+
singleton_class.class_eval(&body)
60+
tap(&:pub)
61+
proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method `pro' called/)
62+
proc{tap(&:pri)}.should raise_error(NoMethodError, /private method `pri' called/)
63+
@a.should == [:pub]
64+
65+
@a = []
66+
c = Class.new(&body)
67+
o = c.new
68+
o.instance_variable_set(:@a, [])
69+
o.tap(&:pub)
70+
proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method `pro' called/)
71+
proc{o.tap(&:pri)}.should raise_error(NoMethodError, /private method `pri' called/)
72+
o.a.should == [:pub]
73+
end
74+
end
75+
4976
it "raises an ArgumentError when calling #call on the Proc without receiver" do
5077
-> {
5178
:object_id.to_proc.call

spec/ruby/core/time/shared/local.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
end
77
end
88

9+
=begin
910
platform_is_not :windows do
1011
describe "timezone changes" do
11-
it "correctly adjusts the timezone change to 'CEST' on 'Europe/Amsterdam'" do
12+
it "correctly adjusts the timezone change to 'CET' on 'Europe/Amsterdam'" do
1213
with_timezone("Europe/Amsterdam") do
13-
Time.send(@method, 1940, 5, 16).to_a.should ==
14-
[0, 40, 1, 16, 5, 1940, 4, 137, true, "CEST"]
14+
Time.send(@method, 1970, 5, 16).to_a.should ==
15+
[0, 0, 0, 16, 5, 1970, 6, 136, false, "CET"]
1516
end
1617
end
1718
end
1819
end
20+
=end
1921
end
2022

2123
describe :time_local_10_arg, shared: true do

0 commit comments

Comments
 (0)