Skip to content

Commit 545313d

Browse files
authored
Merge pull request #8231 from andrykonchin/update-specs
Update ruby/specs
2 parents d7358ea + dafcb99 commit 545313d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+583
-44
lines changed

spec/ruby/core/binding/dup_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
eval("b = 2", bind2)
2424
-> { eval("b", bind1) }.should raise_error(NameError)
2525
eval("b", bind2).should == 2
26-
26+
2727
bind1.local_variables.sort.should == [:a, :bind1, :bind2]
2828
bind2.local_variables.sort.should == [:a, :b, :bind1, :bind2]
2929
end

spec/ruby/core/binding/irb_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
IO.popen([envs, *ruby_exe, irb_fixture, chdir: dir], "r+") do |pipe|
1111
pipe.puts "a ** 2"
1212
pipe.puts "exit"
13-
pipe.readlines.map(&:chomp)
13+
pipe.readlines.map(&:chomp).reject(&:empty?)
1414
end
1515
end
1616

spec/ruby/core/encoding/inspect_spec.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,23 @@
55
Encoding::UTF_8.inspect.should be_an_instance_of(String)
66
end
77

8-
it "returns #<Encoding:name> for a non-dummy encoding named 'name'" do
9-
Encoding.list.to_a.reject {|e| e.dummy? }.each do |enc|
10-
enc.inspect.should =~ /#<Encoding:#{enc.name}>/
8+
ruby_version_is ""..."3.4" do
9+
it "returns #<Encoding:name> for a non-dummy encoding named 'name'" do
10+
Encoding.list.to_a.reject {|e| e.dummy? }.each do |enc|
11+
enc.inspect.should =~ /#<Encoding:#{enc.name}>/
12+
end
13+
end
14+
end
15+
16+
ruby_version_is "3.4" do
17+
it "returns #<Encoding:name> for a non-dummy encoding named 'name'" do
18+
Encoding.list.to_a.reject {|e| e.dummy? }.each do |enc|
19+
if enc.name == "ASCII-8BIT"
20+
enc.inspect.should == "#<Encoding:BINARY (ASCII-8BIT)>"
21+
else
22+
enc.inspect.should =~ /#<Encoding:#{enc.name}>/
23+
end
24+
end
1125
end
1226
end
1327

spec/ruby/core/fiber/raise_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,40 @@
9191

9292
fiber_two.resume.should == [:yield_one, :rescued]
9393
end
94+
95+
ruby_version_is "3.4" do
96+
it "raises on the resumed fiber" do
97+
root_fiber = Fiber.current
98+
f1 = Fiber.new { root_fiber.transfer }
99+
f2 = Fiber.new { f1.resume }
100+
f2.transfer
101+
102+
-> do
103+
f2.raise(RuntimeError, "Expected error")
104+
end.should raise_error(RuntimeError, "Expected error")
105+
end
106+
107+
it "raises on itself" do
108+
-> do
109+
Fiber.current.raise(RuntimeError, "Expected error")
110+
end.should raise_error(RuntimeError, "Expected error")
111+
end
112+
113+
it "should raise on parent fiber" do
114+
f2 = nil
115+
f1 = Fiber.new do
116+
# This is equivalent to Kernel#raise:
117+
f2.raise(RuntimeError, "Expected error")
118+
end
119+
f2 = Fiber.new do
120+
f1.resume
121+
end
122+
123+
-> do
124+
f2.resume
125+
end.should raise_error(RuntimeError, "Expected error")
126+
end
127+
end
94128
end
95129

96130

spec/ruby/core/io/pread_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
it "accepts a length, an offset, and an output buffer" do
2424
buffer = +"foo"
25-
@file.pread(3, 4, buffer)
25+
@file.pread(3, 4, buffer).should.equal?(buffer)
2626
buffer.should == "567"
2727
end
2828

@@ -38,6 +38,13 @@
3838
buffer.should == "12345"
3939
end
4040

41+
it "preserves the encoding of the given buffer" do
42+
buffer = ''.encode(Encoding::ISO_8859_1)
43+
@file.pread(10, 0, buffer)
44+
45+
buffer.encoding.should == Encoding::ISO_8859_1
46+
end
47+
4148
it "does not advance the file pointer" do
4249
@file.pread(4, 0).should == "1234"
4350
@file.read.should == "1234567890"

spec/ruby/core/io/read_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,21 @@
376376
buf.should == @contents[0..4]
377377
end
378378

379+
it "preserves the encoding of the given buffer" do
380+
buffer = ''.encode(Encoding::ISO_8859_1)
381+
@io.read(10, buffer)
382+
383+
buffer.encoding.should == Encoding::ISO_8859_1
384+
end
385+
386+
# https://bugs.ruby-lang.org/issues/20416
387+
it "does not preserve the encoding of the given buffer when max length is not provided" do
388+
buffer = ''.encode(Encoding::ISO_8859_1)
389+
@io.read(nil, buffer)
390+
391+
buffer.encoding.should_not == Encoding::ISO_8859_1
392+
end
393+
379394
it "returns the given buffer" do
380395
buf = +""
381396

spec/ruby/core/io/readpartial_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
buffer = +"existing content"
6363
@wr.write("hello world")
6464
@wr.close
65-
@rd.readpartial(11, buffer)
65+
@rd.readpartial(11, buffer).should.equal?(buffer)
6666
buffer.should == "hello world"
6767
end
6868

@@ -106,6 +106,7 @@
106106
@wr.write("abc")
107107
@wr.close
108108
@rd.readpartial(10, buffer)
109+
109110
buffer.encoding.should == Encoding::ISO_8859_1
110111
end
111112
end

spec/ruby/core/io/sysread_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
it "discards the existing buffer content upon successful read" do
9999
buffer = +"existing content"
100-
@file.sysread(11, buffer)
100+
@file.sysread(11, buffer).should.equal?(buffer)
101101
buffer.should == "01234567890"
102102
end
103103

@@ -107,6 +107,13 @@
107107
-> { @file.sysread(1, buffer) }.should raise_error(EOFError)
108108
buffer.should be_empty
109109
end
110+
111+
it "preserves the encoding of the given buffer" do
112+
buffer = ''.encode(Encoding::ISO_8859_1)
113+
string = @file.sysread(10, buffer)
114+
115+
buffer.encoding.should == Encoding::ISO_8859_1
116+
end
110117
end
111118

112119
describe "IO#sysread" do

spec/ruby/core/module/include_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ def self.append_features(mod)
4747
-> { ModuleSpecs::SubclassSpec.include(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError)
4848
end
4949

50+
ruby_version_is ""..."3.2" do
51+
it "raises ArgumentError when the argument is a refinement" do
52+
refinement = nil
53+
54+
Module.new do
55+
refine String do
56+
refinement = self
57+
end
58+
end
59+
60+
-> { ModuleSpecs::Basic.include(refinement) }.should raise_error(ArgumentError, "refinement module is not allowed")
61+
end
62+
end
63+
64+
ruby_version_is "3.2" do
65+
it "raises a TypeError when the argument is a refinement" do
66+
refinement = nil
67+
68+
Module.new do
69+
refine String do
70+
refinement = self
71+
end
72+
end
73+
74+
-> { ModuleSpecs::Basic.include(refinement) }.should raise_error(TypeError, "Cannot include refinement")
75+
end
76+
end
77+
5078
it "imports constants to modules and classes" do
5179
ModuleSpecs::A.constants.should include(:CONSTANT_A)
5280
ModuleSpecs::B.constants.should include(:CONSTANT_A, :CONSTANT_B)

spec/ruby/core/module/prepend_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ def foo
7575
foo.call.should == 'm'
7676
end
7777

78+
it "updates the optimized method when a prepended module is updated" do
79+
out = ruby_exe(<<~RUBY)
80+
module M; end
81+
class Integer
82+
prepend M
83+
end
84+
l = -> { 1 + 2 }
85+
p l.call
86+
M.module_eval do
87+
def +(o)
88+
$called = true
89+
super(o)
90+
end
91+
end
92+
p l.call
93+
p $called
94+
RUBY
95+
out.should == "3\n3\ntrue\n"
96+
end
97+
7898
it "updates the method when there is a base included method and the prepended module overrides it" do
7999
base_module = Module.new do
80100
def foo
@@ -415,6 +435,34 @@ module M
415435
-> { ModuleSpecs::SubclassSpec.prepend(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError)
416436
end
417437

438+
ruby_version_is ""..."3.2" do
439+
it "raises ArgumentError when the argument is a refinement" do
440+
refinement = nil
441+
442+
Module.new do
443+
refine String do
444+
refinement = self
445+
end
446+
end
447+
448+
-> { ModuleSpecs::Basic.prepend(refinement) }.should raise_error(ArgumentError, "refinement module is not allowed")
449+
end
450+
end
451+
452+
ruby_version_is "3.2" do
453+
it "raises a TypeError when the argument is a refinement" do
454+
refinement = nil
455+
456+
Module.new do
457+
refine String do
458+
refinement = self
459+
end
460+
end
461+
462+
-> { ModuleSpecs::Basic.prepend(refinement) }.should raise_error(TypeError, "Cannot prepend refinement")
463+
end
464+
end
465+
418466
it "imports constants" do
419467
m1 = Module.new
420468
m1::MY_CONSTANT = 1

spec/ruby/core/range/size_spec.rb

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,22 @@
44
it "returns the number of elements in the range" do
55
(1..16).size.should == 16
66
(1...16).size.should == 15
7-
8-
(1.0..16.0).size.should == 16
9-
(1.0...16.0).size.should == 15
10-
(1.0..15.9).size.should == 15
11-
(1.1..16.0).size.should == 15
12-
(1.1..15.9).size.should == 15
137
end
148

159
it "returns 0 if last is less than first" do
1610
(16..0).size.should == 0
17-
(16.0..0.0).size.should == 0
18-
(Float::INFINITY..0).size.should == 0
1911
end
2012

2113
it 'returns Float::INFINITY for increasing, infinite ranges' do
2214
(0..Float::INFINITY).size.should == Float::INFINITY
23-
(-Float::INFINITY..0).size.should == Float::INFINITY
24-
(-Float::INFINITY..Float::INFINITY).size.should == Float::INFINITY
2515
end
2616

2717
it 'returns Float::INFINITY for endless ranges if the start is numeric' do
2818
eval("(1..)").size.should == Float::INFINITY
29-
eval("(0.5...)").size.should == Float::INFINITY
3019
end
3120

3221
it 'returns nil for endless ranges if the start is not numeric' do
3322
eval("('z'..)").size.should == nil
34-
eval("([]...)").size.should == nil
3523
end
3624

3725
ruby_version_is ""..."3.2" do
@@ -43,7 +31,7 @@
4331
end
4432
end
4533

46-
ruby_version_is "3.2" do
34+
ruby_version_is "3.2"..."3.4" do
4735
it 'returns Float::INFINITY for all beginless ranges if the end is numeric' do
4836
(..1).size.should == Float::INFINITY
4937
(...0.5).size.should == Float::INFINITY
@@ -58,6 +46,54 @@
5846
end
5947
end
6048

49+
ruby_version_is ""..."3.4" do
50+
it "returns the number of elements in the range" do
51+
(1.0..16.0).size.should == 16
52+
(1.0...16.0).size.should == 15
53+
(1.0..15.9).size.should == 15
54+
(1.1..16.0).size.should == 15
55+
(1.1..15.9).size.should == 15
56+
end
57+
58+
it "returns 0 if last is less than first" do
59+
(16.0..0.0).size.should == 0
60+
(Float::INFINITY..0).size.should == 0
61+
end
62+
63+
it 'returns Float::INFINITY for increasing, infinite ranges' do
64+
(-Float::INFINITY..0).size.should == Float::INFINITY
65+
(-Float::INFINITY..Float::INFINITY).size.should == Float::INFINITY
66+
end
67+
68+
it 'returns Float::INFINITY for endless ranges if the start is numeric' do
69+
eval("(0.5...)").size.should == Float::INFINITY
70+
end
71+
72+
it 'returns nil for endless ranges if the start is not numeric' do
73+
eval("([]...)").size.should == nil
74+
end
75+
end
76+
77+
ruby_version_is "3.4" do
78+
it 'raises TypeError if a range is not iterable' do
79+
-> { (1.0..16.0).size }.should raise_error(TypeError, /can't iterate from/)
80+
-> { (1.0...16.0).size }.should raise_error(TypeError, /can't iterate from/)
81+
-> { (1.0..15.9).size }.should raise_error(TypeError, /can't iterate from/)
82+
-> { (1.1..16.0).size }.should raise_error(TypeError, /can't iterate from/)
83+
-> { (1.1..15.9).size }.should raise_error(TypeError, /can't iterate from/)
84+
-> { (16.0..0.0).size }.should raise_error(TypeError, /can't iterate from/)
85+
-> { (Float::INFINITY..0).size }.should raise_error(TypeError, /can't iterate from/)
86+
-> { (-Float::INFINITY..0).size }.should raise_error(TypeError, /can't iterate from/)
87+
-> { (-Float::INFINITY..Float::INFINITY).size }.should raise_error(TypeError, /can't iterate from/)
88+
-> { (..1).size }.should raise_error(TypeError, /can't iterate from/)
89+
-> { (...0.5).size }.should raise_error(TypeError, /can't iterate from/)
90+
-> { (..nil).size }.should raise_error(TypeError, /can't iterate from/)
91+
-> { (...'o').size }.should raise_error(TypeError, /can't iterate from/)
92+
-> { eval("(0.5...)").size }.should raise_error(TypeError, /can't iterate from/)
93+
-> { eval("([]...)").size }.should raise_error(TypeError, /can't iterate from/)
94+
end
95+
end
96+
6197
it "returns nil if first and last are not Numeric" do
6298
(:a..:z).size.should be_nil
6399
('a'..'z').size.should be_nil

spec/ruby/core/string/index_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@
231231
$~.should == nil
232232
end
233233

234+
ruby_bug "#20421", ""..."3.3" do
235+
it "always clear $~" do
236+
"a".index(/a/)
237+
$~.should_not == nil
238+
239+
string = "blablabla"
240+
string.index(/bla/, string.length + 1)
241+
$~.should == nil
242+
end
243+
end
244+
234245
it "starts the search at the given offset" do
235246
"blablabla".index(/.{0}/, 5).should == 5
236247
"blablabla".index(/.{1}/, 5).should == 5

spec/ruby/core/thread/each_caller_location_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
}.should raise_error(LocalJumpError, "no block given")
4141
end
4242

43-
it "doesn't accept positional and keyword arguments" do
43+
it "doesn't accept keyword arguments" do
4444
-> {
4545
Thread.each_caller_location(12, foo: 10) {}
46-
}.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 0)")
46+
}.should raise_error(ArgumentError);
4747
end
4848
end
4949
end

0 commit comments

Comments
 (0)