Skip to content

Commit 67a1e22

Browse files
committed
1 parent e6d93a2 commit 67a1e22

Some content is hidden

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

62 files changed

+656
-59
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,30 @@ def to.to_int() -2 end
743743
@array.send(@method, eval("(-2..-4).step(10)")).should == []
744744
@array.send(@method, eval("(-2...-4).step(10)")).should == []
745745
end
746+
747+
it "has range with bounds outside of array" do
748+
# end is equal to array's length
749+
@array.send(@method, (0..6).step(1)).should == [0, 1, 2, 3, 4, 5]
750+
-> { @array.send(@method, (0..6).step(2)) }.should raise_error(RangeError)
751+
752+
# end is greater than length with positive steps
753+
@array.send(@method, (1..6).step(2)).should == [1, 3, 5]
754+
@array.send(@method, (2..7).step(2)).should == [2, 4]
755+
-> { @array.send(@method, (2..8).step(2)) }.should raise_error(RangeError)
756+
757+
# begin is greater than length with negative steps
758+
@array.send(@method, (6..1).step(-2)).should == [5, 3, 1]
759+
@array.send(@method, (7..2).step(-2)).should == [5, 3]
760+
-> { @array.send(@method, (8..2).step(-2)) }.should raise_error(RangeError)
761+
end
762+
763+
it "has endless range with start outside of array's bounds" do
764+
@array.send(@method, eval("(6..).step(1)")).should == []
765+
@array.send(@method, eval("(7..).step(1)")).should == nil
766+
767+
@array.send(@method, eval("(6..).step(2)")).should == []
768+
-> { @array.send(@method, eval("(7..).step(2)")) }.should raise_error(RangeError)
769+
end
746770
end
747771
end
748772

spec/ruby/core/dir/shared/glob.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,24 @@
5555
end
5656
end
5757

58+
ruby_version_is "3.0"..."3.1" do
59+
it "result is sorted with any non false value of sort:" do
60+
result = Dir.send(@method, '*', sort: 0)
61+
result.should == result.sort
62+
63+
result = Dir.send(@method, '*', sort: nil)
64+
result.should == result.sort
65+
66+
result = Dir.send(@method, '*', sort: 'false')
67+
result.should == result.sort
68+
end
69+
end
70+
5871
ruby_version_is "3.1" do
59-
it "true or false is expected as sort:" do
60-
-> {Dir.send(@method, '*', sort: nil)}.should raise_error ArgumentError, /true or false/
61-
-> {Dir.send(@method, '*', sort: 0)}.should raise_error ArgumentError, /true or false/
62-
-> {Dir.send(@method, '*', sort: "")}.should raise_error ArgumentError, /true or false/
63-
-> {Dir.send(@method, '*', sort: Object.new)}.should raise_error ArgumentError, /true or false/
72+
it "raises an ArgumentError if sort: is not true or false" do
73+
-> { Dir.send(@method, '*', sort: 0) }.should raise_error ArgumentError, /expected true or false/
74+
-> { Dir.send(@method, '*', sort: nil) }.should raise_error ArgumentError, /expected true or false/
75+
-> { Dir.send(@method, '*', sort: 'false') }.should raise_error ArgumentError, /expected true or false/
6476
end
6577
end
6678

spec/ruby/core/encoding/compatible_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
it "returns nil if the second's Encoding is not ASCII compatible" do
5656
a = "abc".force_encoding("UTF-8")
57-
b = "123".force_encoding("UTF-16LE")
57+
b = "1234".force_encoding("UTF-16LE")
5858
Encoding.compatible?(a, b).should be_nil
5959
end
6060
end

spec/ruby/core/encoding/converter/putback_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,23 @@
3434
@ec.putback.should == ""
3535
end
3636

37+
it "returns the problematic bytes for UTF-16LE" do
38+
ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
39+
src = "\x00\xd8\x61\x00"
40+
dst = ""
41+
ec.primitive_convert(src, dst).should == :invalid_byte_sequence
42+
ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
43+
ec.putback.should == "a\x00".force_encoding("utf-16le")
44+
ec.putback.should == ""
45+
end
46+
3747
it "accepts an integer argument corresponding to the number of bytes to be put back" do
3848
ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
3949
src = "\x00\xd8\x61\x00"
4050
dst = ""
4151
ec.primitive_convert(src, dst).should == :invalid_byte_sequence
4252
ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
43-
ec.putback(1).should == "\x00".force_encoding("utf-16le")
44-
ec.putback.should == "a".force_encoding("utf-16le")
53+
ec.putback(2).should == "a\x00".force_encoding("utf-16le")
4554
ec.putback.should == ""
4655
end
4756
end

spec/ruby/core/enumerable/grep_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ class EnumerableSpecGrep2; def ===(obj); /^ca/ =~ obj; end; end
6565
["abc", "def"].grep(/b/).should == ["abc"]
6666
Regexp.last_match[0].should == "z"
6767
end
68+
69+
it "correctly handles non-string elements" do
70+
'set last match' =~ /set last (.*)/
71+
[:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c]
72+
$1.should == 'match'
73+
74+
o = Object.new
75+
def o.to_str
76+
'hello'
77+
end
78+
[o].grep(/ll/).first.should.equal?(o)
79+
end
6880
end
6981

7082
describe "with a block" do

spec/ruby/core/enumerable/grep_v_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ def (@odd_matcher = BasicObject.new).===(obj)
4545
["abc", "def"].grep_v(/e/).should == ["abc"]
4646
Regexp.last_match[0].should == "z"
4747
end
48+
49+
it "correctly handles non-string elements" do
50+
'set last match' =~ /set last (.*)/
51+
[:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil]
52+
$1.should == 'match'
53+
54+
o = Object.new
55+
def o.to_str
56+
'hello'
57+
end
58+
[o].grep_v(/mm/).first.should.equal?(o)
59+
end
4860
end
4961

5062
describe "without block" do

spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@
66
(1..10).step.begin.should == 1
77
(1...10).step.begin.should == 1
88
end
9+
10+
ruby_version_is "2.7" do
11+
context "with beginless" do
12+
it "returns nil as begin of the sequence" do
13+
eval("(..10).step(1)").begin.should == nil
14+
eval("(...10).step(1)").begin.should == nil
15+
end
16+
end
17+
end
918
end

spec/ruby/core/enumerator/arithmetic_sequence/end_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@
66
(1..10).step.end.should == 10
77
(1...10).step(17).end.should == 10
88
end
9+
10+
context "with endless" do
11+
it "returns nil as end of the sequence" do
12+
(1..).step(1).end.should == nil
13+
(1...).step(1).end.should == nil
14+
end
15+
end
916
end

spec/ruby/core/exception/errno_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,12 @@
5656
end
5757
end
5858
end
59+
60+
describe "Errno::ENOENT" do
61+
it "lets subclasses inherit the default error message" do
62+
c = Class.new(Errno::ENOENT)
63+
raise c, "custom message"
64+
rescue => e
65+
e.message.should == "No such file or directory - custom message"
66+
end
67+
end

spec/ruby/core/gc/auto_compact_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
original = GC.auto_compact
1313
begin
1414
GC.auto_compact = !original
15+
rescue NotImplementedError # platform does not support autocompact
16+
skip
17+
end
18+
19+
begin
1520
GC.auto_compact.should == !original
1621
ensure
1722
GC.auto_compact = original

0 commit comments

Comments
 (0)