File tree Expand file tree Collapse file tree 8 files changed +94
-4
lines changed Expand file tree Collapse file tree 8 files changed +94
-4
lines changed Original file line number Diff line number Diff line change
1
+ require_relative '../../spec_helper'
2
+
3
+ describe "Range#count" do
4
+ ruby_version_is "2.6" do
5
+ it "returns Infinity for endless ranges without arguments or blocks" do
6
+ inf = Float ::INFINITY
7
+ eval ( "('a'...)" ) . count . should == inf
8
+ eval ( "(7..)" ) . count . should == inf
9
+ end
10
+ end
11
+
12
+ ruby_version_is "2.7" do
13
+ it "returns Infinity for beginless ranges without arguments or blocks" do
14
+ inf = Float ::INFINITY
15
+ eval ( "(...'a')" ) . count . should == inf
16
+ eval ( "(...nil)" ) . count . should == inf
17
+ eval ( "(..10.0)" ) . count . should == inf
18
+ end
19
+ end
20
+ end
Original file line number Diff line number Diff line change 54
54
end
55
55
end
56
56
57
+ ruby_version_is "2.7" do
58
+ it "raises a TypeError beginless ranges" do
59
+ -> { eval ( "(..2)" ) . each { |x | x } } . should raise_error ( TypeError )
60
+ end
61
+ end
62
+
57
63
it "raises a TypeError if the first element does not respond to #succ" do
58
64
-> { ( 0.5 ..2.4 ) . each { |i | i } } . should raise_error ( TypeError )
59
65
Original file line number Diff line number Diff line change 13
13
eval ( "(1.0..)" ) . should == eval ( "(1.0..)" )
14
14
end
15
15
end
16
+
17
+ ruby_version_is "2.7" do
18
+ it "returns true if the endpoints are == for beginless ranges" do
19
+ eval ( "(...10)" ) . should == eval ( "(...10)" )
20
+ end
21
+ end
16
22
end
Original file line number Diff line number Diff line change 46
46
it "raises a TypeError when passed a String" do
47
47
-> { ( 2 ..3 ) . first ( "1" ) } . should raise_error ( TypeError )
48
48
end
49
+
50
+ ruby_version_is "2.7" do
51
+ it "raises a RangeError when called on an beginless range" do
52
+ -> { eval ( "(..1)" ) . first } . should raise_error ( RangeError )
53
+ end
54
+ end
49
55
end
Original file line number Diff line number Diff line change 19
19
end
20
20
end
21
21
22
+ ruby_version_is '2.7' do
23
+ it "works for beginless ranges" do
24
+ eval ( "(..1)" ) . inspect . should == "..1"
25
+ eval ( "(...0.1)" ) . inspect . should == "...0.1"
26
+ end
27
+
28
+ it "works for nil ... nil ranges" do
29
+ eval ( "(..nil)" ) . inspect . should == "nil..nil"
30
+ eval ( "(nil...)" ) . inspect . should == "nil...nil"
31
+ end
32
+ end
33
+
22
34
ruby_version_is '' ...'2.7' do
23
35
it "returns a tainted string if either end is tainted" do
24
36
( ( "a" . taint ) ..."c" ) . inspect . tainted? . should be_true
Original file line number Diff line number Diff line change 51
51
-> { eval ( "(1..)" ) . max } . should raise_error ( RangeError )
52
52
end
53
53
end
54
+
55
+ ruby_version_is "2.7.2" do
56
+ it "returns the end point (or one less) for beginless ranges" do
57
+ eval ( "(...1)" ) . max . should == 0
58
+ eval ( "(..1)" ) . max . should == 1
59
+ eval ( "(..1.0)" ) . max . should == 1.0
60
+ end
61
+ end
54
62
end
55
63
56
64
describe "Range#max given a block" do
85
93
( 'z' ..'l' ) . max { |x , y | x <=> y } . should be_nil
86
94
( 5 ...5 ) . max { |x , y | x <=> y } . should be_nil
87
95
end
96
+
97
+ ruby_version_is "2.7" do
98
+ it "raises RangeError when called with custom comparison method on an beginless range" do
99
+ -> { eval ( "(..1)" ) . max { |a , b | a } } . should raise_error ( RangeError )
100
+ end
101
+ end
88
102
end
Original file line number Diff line number Diff line change 38
38
time_end = Time . now + 1.0
39
39
( time_start ...time_end ) . min . should equal ( time_start )
40
40
end
41
+
42
+ ruby_version_is "2.6" do
43
+ it "returns the start point for endless ranges" do
44
+ eval ( "(1..)" ) . min . should == 1
45
+ eval ( "(1.0...)" ) . min . should == 1.0
46
+ end
47
+ end
48
+
49
+ ruby_version_is "2.7" do
50
+ it "raises RangeError when called on an beginless range" do
51
+ -> { eval ( "(..1)" ) . min } . should raise_error ( RangeError )
52
+ end
53
+ end
41
54
end
42
55
43
56
describe "Range#min given a block" do
74
87
end
75
88
76
89
ruby_version_is "2.6" do
77
- it "returns the start point for endless ranges" do
78
- eval ( "(1..)" ) . min . should == 1
79
- eval ( "(1.0...)" ) . min . should == 1.0
90
+ it "raises RangeError when called with custom comparison method on an endless range" do
91
+ -> { eval ( "(1..)" ) . min { |a , b | a } } . should raise_error ( RangeError )
80
92
end
81
93
end
82
94
end
Original file line number Diff line number Diff line change 25
25
end
26
26
27
27
ruby_version_is "2.6" do
28
- it 'returns Float::INFINITY for endless ranges' do
28
+ it 'returns Float::INFINITY for endless ranges if the start is numeric ' do
29
29
eval ( "(1..)" ) . size . should == Float ::INFINITY
30
30
eval ( "(0.5...)" ) . size . should == Float ::INFINITY
31
31
end
32
+
33
+ it 'returns nil for endless ranges if the start is not numeric' do
34
+ eval ( "('z'..)" ) . size . should == nil
35
+ eval ( "([]...)" ) . size . should == nil
36
+ end
37
+ end
38
+
39
+ ruby_version_is "2.7" do
40
+ it 'returns Float::INFINITY for all beginless ranges' do
41
+ eval ( "(..1)" ) . size . should == Float ::INFINITY
42
+ eval ( "(...0.5)" ) . size . should == Float ::INFINITY
43
+ eval ( "(..nil)" ) . size . should == Float ::INFINITY
44
+ eval ( "(...'o')" ) . size . should == Float ::INFINITY
45
+ end
32
46
end
33
47
34
48
it "returns nil if first and last are not Numeric" do
You can’t perform that action at this time.
0 commit comments