summaryrefslogtreecommitdiff
path: root/spec/ruby/core/range
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/range')
-rw-r--r--spec/ruby/core/range/bsearch_spec.rb178
-rw-r--r--spec/ruby/core/range/case_compare_spec.rb24
-rw-r--r--spec/ruby/core/range/each_spec.rb34
-rw-r--r--spec/ruby/core/range/equal_value_spec.rb6
-rw-r--r--spec/ruby/core/range/inspect_spec.rb8
-rw-r--r--spec/ruby/core/range/last_spec.rb6
-rw-r--r--spec/ruby/core/range/max_spec.rb6
-rw-r--r--spec/ruby/core/range/min_spec.rb14
-rw-r--r--spec/ruby/core/range/minmax_spec.rb14
-rw-r--r--spec/ruby/core/range/new_spec.rb22
-rw-r--r--spec/ruby/core/range/percent_spec.rb24
-rw-r--r--spec/ruby/core/range/shared/cover.rb96
-rw-r--r--spec/ruby/core/range/shared/cover_and_include.rb8
-rw-r--r--spec/ruby/core/range/shared/equal_value.rb10
-rw-r--r--spec/ruby/core/range/size_spec.rb16
-rw-r--r--spec/ruby/core/range/step_spec.rb191
-rw-r--r--spec/ruby/core/range/to_a_spec.rb6
-rw-r--r--spec/ruby/core/range/to_s_spec.rb8
18 files changed, 293 insertions, 378 deletions
diff --git a/spec/ruby/core/range/bsearch_spec.rb b/spec/ruby/core/range/bsearch_spec.rb
index d31c5d5d51..438c7ce314 100644
--- a/spec/ruby/core/range/bsearch_spec.rb
+++ b/spec/ruby/core/range/bsearch_spec.rb
@@ -215,118 +215,116 @@ describe "Range#bsearch" do
end
end
- ruby_version_is "2.6" do
- context "with endless ranges and Integer values" do
- context "with a block returning true or false" do
- it "returns minimum element if the block returns true for every element" do
- eval("(-2..)").bsearch { |x| true }.should == -2
- end
+ context "with endless ranges and Integer values" do
+ context "with a block returning true or false" do
+ it "returns minimum element if the block returns true for every element" do
+ eval("(-2..)").bsearch { |x| true }.should == -2
+ end
- it "returns the smallest element for which block returns true" do
- eval("(0..)").bsearch { |x| x >= 2 }.should == 2
- eval("(-1..)").bsearch { |x| x >= 1 }.should == 1
- end
+ it "returns the smallest element for which block returns true" do
+ eval("(0..)").bsearch { |x| x >= 2 }.should == 2
+ eval("(-1..)").bsearch { |x| x >= 1 }.should == 1
end
+ end
- context "with a block returning negative, zero, positive numbers" do
- it "returns nil if the block returns less than zero for every element" do
- eval("(0..)").bsearch { |x| -1 }.should be_nil
- end
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns less than zero for every element" do
+ eval("(0..)").bsearch { |x| -1 }.should be_nil
+ end
- it "returns nil if the block never returns zero" do
- eval("(0..)").bsearch { |x| x > 5 ? -1 : 1 }.should be_nil
- end
+ it "returns nil if the block never returns zero" do
+ eval("(0..)").bsearch { |x| x > 5 ? -1 : 1 }.should be_nil
+ end
- it "accepts -Float::INFINITY from the block" do
- eval("(0..)").bsearch { |x| -Float::INFINITY }.should be_nil
- end
+ it "accepts -Float::INFINITY from the block" do
+ eval("(0..)").bsearch { |x| -Float::INFINITY }.should be_nil
+ end
- it "returns an element at an index for which block returns 0.0" do
- result = eval("(0..)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
- result.should == 2
- end
+ it "returns an element at an index for which block returns 0.0" do
+ result = eval("(0..)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
- it "returns an element at an index for which block returns 0" do
- result = eval("(0..)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
- [1, 2, 3].should include(result)
- end
+ it "returns an element at an index for which block returns 0" do
+ result = eval("(0..)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ [1, 2, 3].should include(result)
end
end
+ end
- context "with endless ranges and Float values" do
- context "with a block returning true or false" do
- it "returns nil if the block returns false for every element" do
- eval("(0.1..)").bsearch { |x| x < 0.0 }.should be_nil
- eval("(0.1...)").bsearch { |x| x < 0.0 }.should be_nil
- end
+ context "with endless ranges and Float values" do
+ context "with a block returning true or false" do
+ it "returns nil if the block returns false for every element" do
+ eval("(0.1..)").bsearch { |x| x < 0.0 }.should be_nil
+ eval("(0.1...)").bsearch { |x| x < 0.0 }.should be_nil
+ end
- it "returns nil if the block returns nil for every element" do
- eval("(-0.0..)").bsearch { |x| nil }.should be_nil
- eval("(-0.0...)").bsearch { |x| nil }.should be_nil
- end
+ it "returns nil if the block returns nil for every element" do
+ eval("(-0.0..)").bsearch { |x| nil }.should be_nil
+ eval("(-0.0...)").bsearch { |x| nil }.should be_nil
+ end
- it "returns minimum element if the block returns true for every element" do
- eval("(-0.2..)").bsearch { |x| true }.should == -0.2
- eval("(-0.2...)").bsearch { |x| true }.should == -0.2
- end
+ it "returns minimum element if the block returns true for every element" do
+ eval("(-0.2..)").bsearch { |x| true }.should == -0.2
+ eval("(-0.2...)").bsearch { |x| true }.should == -0.2
+ end
- it "returns the smallest element for which block returns true" do
- eval("(0..)").bsearch { |x| x >= 2 }.should == 2
- eval("(-1.2..)").bsearch { |x| x >= 1 }.should == 1
- end
+ it "returns the smallest element for which block returns true" do
+ eval("(0..)").bsearch { |x| x >= 2 }.should == 2
+ eval("(-1.2..)").bsearch { |x| x >= 1 }.should == 1
+ end
- it "works with infinity bounds" do
- inf = Float::INFINITY
- eval("(inf..)").bsearch { |x| true }.should == inf
- eval("(inf...)").bsearch { |x| true }.should == nil
- eval("(-inf..)").bsearch { |x| true }.should == -inf
- eval("(-inf...)").bsearch { |x| true }.should == -inf
- end
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ eval("(inf..)").bsearch { |x| true }.should == inf
+ eval("(inf...)").bsearch { |x| true }.should == nil
+ eval("(-inf..)").bsearch { |x| true }.should == -inf
+ eval("(-inf...)").bsearch { |x| true }.should == -inf
end
+ end
- context "with a block returning negative, zero, positive numbers" do
- it "returns nil if the block returns less than zero for every element" do
- eval("(-2.0..)").bsearch { |x| -1 }.should be_nil
- eval("(-2.0...)").bsearch { |x| -1 }.should be_nil
- end
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns less than zero for every element" do
+ eval("(-2.0..)").bsearch { |x| -1 }.should be_nil
+ eval("(-2.0...)").bsearch { |x| -1 }.should be_nil
+ end
- it "returns nil if the block returns greater than zero for every element" do
- eval("(0.3..)").bsearch { |x| 1 }.should be_nil
- eval("(0.3...)").bsearch { |x| 1 }.should be_nil
- end
+ it "returns nil if the block returns greater than zero for every element" do
+ eval("(0.3..)").bsearch { |x| 1 }.should be_nil
+ eval("(0.3...)").bsearch { |x| 1 }.should be_nil
+ end
- it "returns nil if the block never returns zero" do
- eval("(0.2..)").bsearch { |x| x < 2 ? 1 : -1 }.should be_nil
- end
+ it "returns nil if the block never returns zero" do
+ eval("(0.2..)").bsearch { |x| x < 2 ? 1 : -1 }.should be_nil
+ end
- it "accepts (+/-)Float::INFINITY from the block" do
- eval("(0.1..)").bsearch { |x| Float::INFINITY }.should be_nil
- eval("(-5.0..)").bsearch { |x| -Float::INFINITY }.should be_nil
- end
+ it "accepts (+/-)Float::INFINITY from the block" do
+ eval("(0.1..)").bsearch { |x| Float::INFINITY }.should be_nil
+ eval("(-5.0..)").bsearch { |x| -Float::INFINITY }.should be_nil
+ end
- it "returns an element at an index for which block returns 0.0" do
- result = eval("(0.0..)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
- result.should == 2
- end
+ it "returns an element at an index for which block returns 0.0" do
+ result = eval("(0.0..)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
- it "returns an element at an index for which block returns 0" do
- result = eval("(0.1..)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
- result.should >= 1
- result.should <= 3
- end
+ it "returns an element at an index for which block returns 0" do
+ result = eval("(0.1..)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ result.should >= 1
+ result.should <= 3
+ end
- it "works with infinity bounds" do
- inf = Float::INFINITY
- eval("(inf..)").bsearch { |x| 1 }.should == nil
- eval("(inf...)").bsearch { |x| 1 }.should == nil
- eval("(inf..)").bsearch { |x| x == inf ? 0 : 1 }.should == inf
- eval("(inf...)").bsearch { |x| x == inf ? 0 : 1 }.should == nil
- eval("(-inf..)").bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
- eval("(-inf...)").bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
- eval("(-inf..)").bsearch { |x| 3 - x }.should == 3
- eval("(-inf...)").bsearch { |x| 3 - x }.should == 3
- eval("(0.0...)").bsearch { 0 }.should != inf
- end
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ eval("(inf..)").bsearch { |x| 1 }.should == nil
+ eval("(inf...)").bsearch { |x| 1 }.should == nil
+ eval("(inf..)").bsearch { |x| x == inf ? 0 : 1 }.should == inf
+ eval("(inf...)").bsearch { |x| x == inf ? 0 : 1 }.should == nil
+ eval("(-inf..)").bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ eval("(-inf...)").bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ eval("(-inf..)").bsearch { |x| 3 - x }.should == 3
+ eval("(-inf...)").bsearch { |x| 3 - x }.should == 3
+ eval("(0.0...)").bsearch { 0 }.should != inf
end
end
end
diff --git a/spec/ruby/core/range/case_compare_spec.rb b/spec/ruby/core/range/case_compare_spec.rb
index b1afa90a41..e795026230 100644
--- a/spec/ruby/core/range/case_compare_spec.rb
+++ b/spec/ruby/core/range/case_compare_spec.rb
@@ -3,27 +3,9 @@ require_relative 'shared/cover_and_include'
require_relative 'shared/cover'
describe "Range#===" do
- ruby_version_is ""..."2.6" do
- it "returns the result of calling #include? on self" do
- range = 0...10
- range.should_receive(:include?).with(2).and_return(:true)
- (range === 2).should == :true
- end
-
- it "requires #succ method to be implemented" do
- range = RangeSpecs::WithoutSucc.new(0)..RangeSpecs::WithoutSucc.new(10)
-
- -> do
- range === RangeSpecs::WithoutSucc.new(2)
- end.should raise_error(TypeError, /can't iterate from/)
- end
- end
-
- ruby_version_is "2.6" do
- it "returns the result of calling #cover? on self" do
- range = RangeSpecs::WithoutSucc.new(0)..RangeSpecs::WithoutSucc.new(10)
- (range === RangeSpecs::WithoutSucc.new(2)).should == true
- end
+ it "returns the result of calling #cover? on self" do
+ range = RangeSpecs::WithoutSucc.new(0)..RangeSpecs::WithoutSucc.new(10)
+ (range === RangeSpecs::WithoutSucc.new(2)).should == true
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/range/each_spec.rb b/spec/ruby/core/range/each_spec.rb
index 1dce9c1f1e..bd4bbb82e5 100644
--- a/spec/ruby/core/range/each_spec.rb
+++ b/spec/ruby/core/range/each_spec.rb
@@ -38,26 +38,24 @@ describe "Range#each" do
a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
end
- ruby_version_is "2.6" do
- it "works with endless ranges" do
- a = []
- eval("(-2..)").each { |x| break if x > 2; a << x }
- a.should == [-2, -1, 0, 1, 2]
-
- a = []
- eval("(-2...)").each { |x| break if x > 2; a << x }
- a.should == [-2, -1, 0, 1, 2]
- end
+ it "works with endless ranges" do
+ a = []
+ eval("(-2..)").each { |x| break if x > 2; a << x }
+ a.should == [-2, -1, 0, 1, 2]
+
+ a = []
+ eval("(-2...)").each { |x| break if x > 2; a << x }
+ a.should == [-2, -1, 0, 1, 2]
+ end
- it "works with String endless ranges" do
- a = []
- eval("('A'..)").each { |x| break if x > "D"; a << x }
- a.should == ["A", "B", "C", "D"]
+ it "works with String endless ranges" do
+ a = []
+ eval("('A'..)").each { |x| break if x > "D"; a << x }
+ a.should == ["A", "B", "C", "D"]
- a = []
- eval("('A'...)").each { |x| break if x > "D"; a << x }
- a.should == ["A", "B", "C", "D"]
- end
+ a = []
+ eval("('A'...)").each { |x| break if x > "D"; a << x }
+ a.should == ["A", "B", "C", "D"]
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/range/equal_value_spec.rb b/spec/ruby/core/range/equal_value_spec.rb
index f88d3029bb..0aaebfb59a 100644
--- a/spec/ruby/core/range/equal_value_spec.rb
+++ b/spec/ruby/core/range/equal_value_spec.rb
@@ -8,10 +8,8 @@ describe "Range#==" do
(0..1).should == (0..1.0)
end
- ruby_version_is "2.6" do
- it "returns true if the endpoints are == for endless ranges" do
- eval("(1.0..)").should == eval("(1.0..)")
- end
+ it "returns true if the endpoints are == for endless ranges" do
+ eval("(1.0..)").should == eval("(1.0..)")
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/range/inspect_spec.rb b/spec/ruby/core/range/inspect_spec.rb
index 6a206a0355..f49882e6ce 100644
--- a/spec/ruby/core/range/inspect_spec.rb
+++ b/spec/ruby/core/range/inspect_spec.rb
@@ -12,11 +12,9 @@ describe "Range#inspect" do
(0.5..2.4).inspect.should == "0.5..2.4"
end
- ruby_version_is "2.6" do
- it "works for endless ranges" do
- eval("(1..)").inspect.should == "1.."
- eval("(0.1...)").inspect.should == "0.1..."
- end
+ it "works for endless ranges" do
+ eval("(1..)").inspect.should == "1.."
+ eval("(0.1...)").inspect.should == "0.1..."
end
ruby_version_is '2.7' do
diff --git a/spec/ruby/core/range/last_spec.rb b/spec/ruby/core/range/last_spec.rb
index 54884ba4d6..d7ef776b42 100644
--- a/spec/ruby/core/range/last_spec.rb
+++ b/spec/ruby/core/range/last_spec.rb
@@ -47,9 +47,7 @@ describe "Range#last" do
-> { (2..3).last("1") }.should raise_error(TypeError)
end
- ruby_version_is "2.6" do
- it "raises a RangeError when called on an endless range" do
- -> { eval("(1..)").last }.should raise_error(RangeError)
- end
+ it "raises a RangeError when called on an endless range" do
+ -> { eval("(1..)").last }.should raise_error(RangeError)
end
end
diff --git a/spec/ruby/core/range/max_spec.rb b/spec/ruby/core/range/max_spec.rb
index f2672170d9..a970144d66 100644
--- a/spec/ruby/core/range/max_spec.rb
+++ b/spec/ruby/core/range/max_spec.rb
@@ -46,10 +46,8 @@ describe "Range#max" do
-> { (time_start...time_end).max }.should raise_error(TypeError)
end
- ruby_version_is "2.6" do
- it "raises RangeError when called on an endless range" do
- -> { eval("(1..)").max }.should raise_error(RangeError)
- end
+ it "raises RangeError when called on an endless range" do
+ -> { eval("(1..)").max }.should raise_error(RangeError)
end
ruby_version_is "3.0" do
diff --git a/spec/ruby/core/range/min_spec.rb b/spec/ruby/core/range/min_spec.rb
index ffd40f3a07..6e56cc733b 100644
--- a/spec/ruby/core/range/min_spec.rb
+++ b/spec/ruby/core/range/min_spec.rb
@@ -39,11 +39,9 @@ describe "Range#min" do
(time_start...time_end).min.should equal(time_start)
end
- ruby_version_is "2.6" do
- it "returns the start point for endless ranges" do
- eval("(1..)").min.should == 1
- eval("(1.0...)").min.should == 1.0
- end
+ it "returns the start point for endless ranges" do
+ eval("(1..)").min.should == 1
+ eval("(1.0...)").min.should == 1.0
end
ruby_version_is "2.7" do
@@ -86,9 +84,7 @@ describe "Range#min given a block" do
(7...7).min {|x,y| x <=> y}.should be_nil
end
- ruby_version_is "2.6" do
- it "raises RangeError when called with custom comparison method on an endless range" do
- -> { eval("(1..)").min {|a, b| a} }.should raise_error(RangeError)
- end
+ it "raises RangeError when called with custom comparison method on an endless range" do
+ -> { eval("(1..)").min {|a, b| a} }.should raise_error(RangeError)
end
end
diff --git a/spec/ruby/core/range/minmax_spec.rb b/spec/ruby/core/range/minmax_spec.rb
index fa0637ac56..1db9bfce38 100644
--- a/spec/ruby/core/range/minmax_spec.rb
+++ b/spec/ruby/core/range/minmax_spec.rb
@@ -1,6 +1,6 @@
require_relative '../../spec_helper'
-# These specs use Range.new instead of the literal notation so they parse fine on Ruby < 2.6
+# These specs use Range.new instead of the literal notation for beginless Ranges so they parse fine on Ruby < 2.7
describe 'Range#minmax' do
before(:each) do
@x = mock('x')
@@ -13,10 +13,10 @@ describe 'Range#minmax' do
end
describe 'on an inclusive range' do
- ruby_version_is '2.6'...'2.7' do
+ ruby_version_is ''...'2.7' do
it 'should try to iterate endlessly on an endless range' do
@x.should_receive(:succ).once.and_return(@y)
- range = Range.new(@x, nil)
+ range = (@x..)
-> { range.minmax }.should raise_error(NoMethodError, /^undefined method `succ' for/)
end
@@ -26,7 +26,7 @@ describe 'Range#minmax' do
it 'should raise RangeError on an endless range without iterating the range' do
@x.should_not_receive(:succ)
- range = Range.new(@x, nil)
+ range = (@x..)
-> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
end
@@ -96,11 +96,11 @@ describe 'Range#minmax' do
end
describe 'on an exclusive range' do
- ruby_version_is '2.6'...'2.7' do
+ ruby_version_is ''...'2.7' do
# Endless ranges introduced in 2.6
it 'should try to iterate endlessly on an endless range' do
@x.should_receive(:succ).once.and_return(@y)
- range = Range.new(@x, nil, true)
+ range = (@x...)
-> { range.minmax }.should raise_error(NoMethodError, /^undefined method `succ' for/)
end
@@ -109,7 +109,7 @@ describe 'Range#minmax' do
ruby_version_is '2.7' do
it 'should raise RangeError on an endless range' do
@x.should_not_receive(:succ)
- range = Range.new(@x, nil, true)
+ range = (@x...)
-> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
end
diff --git a/spec/ruby/core/range/new_spec.rb b/spec/ruby/core/range/new_spec.rb
index be10ff244e..a4de4963e7 100644
--- a/spec/ruby/core/range/new_spec.rb
+++ b/spec/ruby/core/range/new_spec.rb
@@ -62,24 +62,16 @@ describe "Range.new" do
end
end
- ruby_version_is ""..."2.6" do
- it "does not allow range without right boundary" do
- -> { Range.new(1, nil) }.should raise_error(ArgumentError, /bad value for range/)
- end
+ it "allows endless right boundary" do
+ range = Range.new(1, nil)
+ range.end.should == nil
end
- ruby_version_is "2.6" do
- it "allows endless right boundary" do
- range = Range.new(1, nil)
- range.end.should == nil
- end
-
- it "distinguishes ranges with included and excluded right boundary" do
- range_exclude = Range.new(1, nil, true)
- range_include = Range.new(1, nil, false)
+ it "distinguishes ranges with included and excluded right boundary" do
+ range_exclude = Range.new(1, nil, true)
+ range_include = Range.new(1, nil, false)
- range_exclude.should_not == range_include
- end
+ range_exclude.should_not == range_include
end
end
end
diff --git a/spec/ruby/core/range/percent_spec.rb b/spec/ruby/core/range/percent_spec.rb
index 41badd4f72..5ec6770ddb 100644
--- a/spec/ruby/core/range/percent_spec.rb
+++ b/spec/ruby/core/range/percent_spec.rb
@@ -1,18 +1,16 @@
require_relative '../../spec_helper'
-ruby_version_is "2.6" do
- describe "Range#%" do
- it "works as a Range#step" do
- aseq = (1..10) % 2
- aseq.class.should == Enumerator::ArithmeticSequence
- aseq.begin.should == 1
- aseq.end.should == 10
- aseq.step.should == 2
- aseq.to_a.should == [1, 3, 5, 7, 9]
- end
+describe "Range#%" do
+ it "works as a Range#step" do
+ aseq = (1..10) % 2
+ aseq.class.should == Enumerator::ArithmeticSequence
+ aseq.begin.should == 1
+ aseq.end.should == 10
+ aseq.step.should == 2
+ aseq.to_a.should == [1, 3, 5, 7, 9]
+ end
- it "produces an arithmetic sequence with a percent sign in #inspect" do
- ((1..10) % 2).inspect.should == "((1..10).%(2))"
- end
+ it "produces an arithmetic sequence with a percent sign in #inspect" do
+ ((1..10) % 2).inspect.should == "((1..10).%(2))"
end
end
diff --git a/spec/ruby/core/range/shared/cover.rb b/spec/ruby/core/range/shared/cover.rb
index e04682ba71..f3c7d22668 100644
--- a/spec/ruby/core/range/shared/cover.rb
+++ b/spec/ruby/core/range/shared/cover.rb
@@ -93,63 +93,61 @@ describe :range_cover, shared: true do
end
describe :range_cover_subrange, shared: true do
- ruby_version_is "2.6" do
- context "range argument" do
- it "accepts range argument" do
- (0..10).send(@method, (3..7)).should be_true
- (0..10).send(@method, (3..15)).should be_false
- (0..10).send(@method, (-2..7)).should be_false
-
- (1.1..7.9).send(@method, (2.5..6.5)).should be_true
- (1.1..7.9).send(@method, (2.5..8.5)).should be_false
- (1.1..7.9).send(@method, (0.5..6.5)).should be_false
-
- ('c'..'i').send(@method, ('d'..'f')).should be_true
- ('c'..'i').send(@method, ('d'..'z')).should be_false
- ('c'..'i').send(@method, ('a'..'f')).should be_false
-
- range_10_100 = RangeSpecs::TenfoldSucc.new(10)..RangeSpecs::TenfoldSucc.new(100)
- range_20_90 = RangeSpecs::TenfoldSucc.new(20)..RangeSpecs::TenfoldSucc.new(90)
- range_20_110 = RangeSpecs::TenfoldSucc.new(20)..RangeSpecs::TenfoldSucc.new(110)
- range_0_90 = RangeSpecs::TenfoldSucc.new(0)..RangeSpecs::TenfoldSucc.new(90)
-
- range_10_100.send(@method, range_20_90).should be_true
- range_10_100.send(@method, range_20_110).should be_false
- range_10_100.send(@method, range_0_90).should be_false
- end
+ context "range argument" do
+ it "accepts range argument" do
+ (0..10).send(@method, (3..7)).should be_true
+ (0..10).send(@method, (3..15)).should be_false
+ (0..10).send(@method, (-2..7)).should be_false
+
+ (1.1..7.9).send(@method, (2.5..6.5)).should be_true
+ (1.1..7.9).send(@method, (2.5..8.5)).should be_false
+ (1.1..7.9).send(@method, (0.5..6.5)).should be_false
+
+ ('c'..'i').send(@method, ('d'..'f')).should be_true
+ ('c'..'i').send(@method, ('d'..'z')).should be_false
+ ('c'..'i').send(@method, ('a'..'f')).should be_false
+
+ range_10_100 = RangeSpecs::TenfoldSucc.new(10)..RangeSpecs::TenfoldSucc.new(100)
+ range_20_90 = RangeSpecs::TenfoldSucc.new(20)..RangeSpecs::TenfoldSucc.new(90)
+ range_20_110 = RangeSpecs::TenfoldSucc.new(20)..RangeSpecs::TenfoldSucc.new(110)
+ range_0_90 = RangeSpecs::TenfoldSucc.new(0)..RangeSpecs::TenfoldSucc.new(90)
+
+ range_10_100.send(@method, range_20_90).should be_true
+ range_10_100.send(@method, range_20_110).should be_false
+ range_10_100.send(@method, range_0_90).should be_false
+ end
- it "supports boundaries of different comparable types" do
- (0..10).send(@method, (3.1..7.9)).should be_true
- (0..10).send(@method, (3.1..15.9)).should be_false
- (0..10).send(@method, (-2.1..7.9)).should be_false
- end
+ it "supports boundaries of different comparable types" do
+ (0..10).send(@method, (3.1..7.9)).should be_true
+ (0..10).send(@method, (3.1..15.9)).should be_false
+ (0..10).send(@method, (-2.1..7.9)).should be_false
+ end
- it "returns false if types are not comparable" do
- (0..10).send(@method, ('a'..'z')).should be_false
- (0..10).send(@method, (RangeSpecs::TenfoldSucc.new(0)..RangeSpecs::TenfoldSucc.new(100))).should be_false
- end
+ it "returns false if types are not comparable" do
+ (0..10).send(@method, ('a'..'z')).should be_false
+ (0..10).send(@method, (RangeSpecs::TenfoldSucc.new(0)..RangeSpecs::TenfoldSucc.new(100))).should be_false
+ end
- it "honors exclusion of right boundary (:exclude_end option)" do
- # Integer
- (0..10).send(@method, (0..10)).should be_true
- (0...10).send(@method, (0...10)).should be_true
+ it "honors exclusion of right boundary (:exclude_end option)" do
+ # Integer
+ (0..10).send(@method, (0..10)).should be_true
+ (0...10).send(@method, (0...10)).should be_true
- (0..10).send(@method, (0...10)).should be_true
- (0...10).send(@method, (0..10)).should be_false
+ (0..10).send(@method, (0...10)).should be_true
+ (0...10).send(@method, (0..10)).should be_false
- (0...11).send(@method, (0..10)).should be_true
- (0..10).send(@method, (0...11)).should be_true
+ (0...11).send(@method, (0..10)).should be_true
+ (0..10).send(@method, (0...11)).should be_true
- # Float
- (0..10.1).send(@method, (0..10.1)).should be_true
- (0...10.1).send(@method, (0...10.1)).should be_true
+ # Float
+ (0..10.1).send(@method, (0..10.1)).should be_true
+ (0...10.1).send(@method, (0...10.1)).should be_true
- (0..10.1).send(@method, (0...10.1)).should be_true
- (0...10.1).send(@method, (0..10.1)).should be_false
+ (0..10.1).send(@method, (0...10.1)).should be_true
+ (0...10.1).send(@method, (0..10.1)).should be_false
- (0...11.1).send(@method, (0..10.1)).should be_true
- (0..10.1).send(@method, (0...11.1)).should be_false
- end
+ (0...11.1).send(@method, (0..10.1)).should be_true
+ (0..10.1).send(@method, (0...11.1)).should be_false
end
end
diff --git a/spec/ruby/core/range/shared/cover_and_include.rb b/spec/ruby/core/range/shared/cover_and_include.rb
index 0267e3ccb0..e978e39af5 100644
--- a/spec/ruby/core/range/shared/cover_and_include.rb
+++ b/spec/ruby/core/range/shared/cover_and_include.rb
@@ -19,11 +19,9 @@ describe :range_cover_and_include, shared: true do
(0.5...2.4).send(@method, 2.4).should == false
end
- ruby_version_is "2.6" do
- it "returns true if other is an element of self for endless ranges" do
- eval("(1..)").send(@method, 2.4).should == true
- eval("(0.5...)").send(@method, 2.4).should == true
- end
+ it "returns true if other is an element of self for endless ranges" do
+ eval("(1..)").send(@method, 2.4).should == true
+ eval("(0.5...)").send(@method, 2.4).should == true
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/range/shared/equal_value.rb b/spec/ruby/core/range/shared/equal_value.rb
index 8872b4efc0..363c6be558 100644
--- a/spec/ruby/core/range/shared/equal_value.rb
+++ b/spec/ruby/core/range/shared/equal_value.rb
@@ -43,11 +43,9 @@ describe :range_eql, shared: true do
a.send(@method, b).should == true
end
- ruby_version_is "2.6" do
- it "works for endless Ranges" do
- eval("(1..)").send(@method, eval("(1..)")).should == true
- eval("(0.5...)").send(@method, eval("(0.5...)")).should == true
- eval("(1..)").send(@method, eval("(1...)")).should == false
- end
+ it "works for endless Ranges" do
+ eval("(1..)").send(@method, eval("(1..)")).should == true
+ eval("(0.5...)").send(@method, eval("(0.5...)")).should == true
+ eval("(1..)").send(@method, eval("(1...)")).should == false
end
end
diff --git a/spec/ruby/core/range/size_spec.rb b/spec/ruby/core/range/size_spec.rb
index 4bf525e541..0019c5ff00 100644
--- a/spec/ruby/core/range/size_spec.rb
+++ b/spec/ruby/core/range/size_spec.rb
@@ -24,16 +24,14 @@ describe "Range#size" do
(-Float::INFINITY..Float::INFINITY).size.should == Float::INFINITY
end
- ruby_version_is "2.6" do
- it 'returns Float::INFINITY for endless ranges if the start is numeric' do
- eval("(1..)").size.should == Float::INFINITY
- eval("(0.5...)").size.should == Float::INFINITY
- end
+ it 'returns Float::INFINITY for endless ranges if the start is numeric' do
+ eval("(1..)").size.should == Float::INFINITY
+ eval("(0.5...)").size.should == Float::INFINITY
+ end
- it 'returns nil for endless ranges if the start is not numeric' do
- eval("('z'..)").size.should == nil
- eval("([]...)").size.should == nil
- end
+ it 'returns nil for endless ranges if the start is not numeric' do
+ eval("('z'..)").size.should == nil
+ eval("([]...)").size.should == nil
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/range/step_spec.rb b/spec/ruby/core/range/step_spec.rb
index be4b482654..624fa71f5f 100644
--- a/spec/ruby/core/range/step_spec.rb
+++ b/spec/ruby/core/range/step_spec.rb
@@ -282,98 +282,96 @@ describe "Range#step" do
end
end
- ruby_version_is "2.6" do
- describe "with an endless range" do
- describe "and Integer values" do
- it "yield Integer values incremented by 1 when not passed a step" do
- eval("(-2..)").step { |x| break if x > 2; ScratchPad << x }
- ScratchPad.recorded.should eql([-2, -1, 0, 1, 2])
-
- ScratchPad.record []
- eval("(-2...)").step { |x| break if x > 2; ScratchPad << x }
- ScratchPad.recorded.should eql([-2, -1, 0, 1, 2])
- end
+ describe "with an endless range" do
+ describe "and Integer values" do
+ it "yield Integer values incremented by 1 when not passed a step" do
+ eval("(-2..)").step { |x| break if x > 2; ScratchPad << x }
+ ScratchPad.recorded.should eql([-2, -1, 0, 1, 2])
- it "yields Integer values incremented by an Integer step" do
- eval("(-5..)").step(2) { |x| break if x > 3; ScratchPad << x }
- ScratchPad.recorded.should eql([-5, -3, -1, 1, 3])
+ ScratchPad.record []
+ eval("(-2...)").step { |x| break if x > 2; ScratchPad << x }
+ ScratchPad.recorded.should eql([-2, -1, 0, 1, 2])
+ end
- ScratchPad.record []
- eval("(-5...)").step(2) { |x| break if x > 3; ScratchPad << x }
- ScratchPad.recorded.should eql([-5, -3, -1, 1, 3])
- end
+ it "yields Integer values incremented by an Integer step" do
+ eval("(-5..)").step(2) { |x| break if x > 3; ScratchPad << x }
+ ScratchPad.recorded.should eql([-5, -3, -1, 1, 3])
- it "yields Float values incremented by a Float step" do
- eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -0.5, 1.0])
+ ScratchPad.record []
+ eval("(-5...)").step(2) { |x| break if x > 3; ScratchPad << x }
+ ScratchPad.recorded.should eql([-5, -3, -1, 1, 3])
+ end
- ScratchPad.record []
- eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -0.5, 1.0])
- end
+ it "yields Float values incremented by a Float step" do
+ eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x }
+ ScratchPad.recorded.should eql([-2.0, -0.5, 1.0])
+
+ ScratchPad.record []
+ eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x }
+ ScratchPad.recorded.should eql([-2.0, -0.5, 1.0])
end
+ end
- describe "and Float values" do
- it "yields Float values incremented by 1 and less than end when not passed a step" do
- eval("(-2.0..)").step { |x| break if x > 1.5; ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0])
+ describe "and Float values" do
+ it "yields Float values incremented by 1 and less than end when not passed a step" do
+ eval("(-2.0..)").step { |x| break if x > 1.5; ScratchPad << x }
+ ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0])
- ScratchPad.record []
- eval("(-2.0...)").step { |x| break if x > 1.5; ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0])
- end
+ ScratchPad.record []
+ eval("(-2.0...)").step { |x| break if x > 1.5; ScratchPad << x }
+ ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0])
+ end
- it "yields Float values incremented by an Integer step" do
- eval("(-5.0..)").step(2) { |x| break if x > 3.5; ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0])
+ it "yields Float values incremented by an Integer step" do
+ eval("(-5.0..)").step(2) { |x| break if x > 3.5; ScratchPad << x }
+ ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0])
- ScratchPad.record []
- eval("(-5.0...)").step(2) { |x| break if x > 3.5; ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0])
- end
+ ScratchPad.record []
+ eval("(-5.0...)").step(2) { |x| break if x > 3.5; ScratchPad << x }
+ ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0])
+ end
- it "yields Float values incremented by a Float step" do
- eval("(-1.0..)").step(0.5) { |x| break if x > 0.6; ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5])
+ it "yields Float values incremented by a Float step" do
+ eval("(-1.0..)").step(0.5) { |x| break if x > 0.6; ScratchPad << x }
+ ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5])
- ScratchPad.record []
- eval("(-1.0...)").step(0.5) { |x| break if x > 0.6; ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5])
- end
+ ScratchPad.record []
+ eval("(-1.0...)").step(0.5) { |x| break if x > 0.6; ScratchPad << x }
+ ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5])
+ end
- it "handles infinite values at the start" do
- eval("(-Float::INFINITY..)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
- ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
+ it "handles infinite values at the start" do
+ eval("(-Float::INFINITY..)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
- ScratchPad.record []
- eval("(-Float::INFINITY...)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
- ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
- end
+ ScratchPad.record []
+ eval("(-Float::INFINITY...)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
end
+ end
- describe "and String values" do
- it "yields String values incremented by #succ and less than or equal to end when not passed a step" do
- eval("('A'..)").step { |x| break if x > "D"; ScratchPad << x }
- ScratchPad.recorded.should == ["A", "B", "C", "D"]
+ describe "and String values" do
+ it "yields String values incremented by #succ and less than or equal to end when not passed a step" do
+ eval("('A'..)").step { |x| break if x > "D"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "B", "C", "D"]
- ScratchPad.record []
- eval("('A'...)").step { |x| break if x > "D"; ScratchPad << x }
- ScratchPad.recorded.should == ["A", "B", "C", "D"]
- end
+ ScratchPad.record []
+ eval("('A'...)").step { |x| break if x > "D"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "B", "C", "D"]
+ end
- it "yields String values incremented by #succ called Integer step times" do
- eval("('A'..)").step(2) { |x| break if x > "F"; ScratchPad << x }
- ScratchPad.recorded.should == ["A", "C", "E"]
+ it "yields String values incremented by #succ called Integer step times" do
+ eval("('A'..)").step(2) { |x| break if x > "F"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "C", "E"]
- ScratchPad.record []
- eval("('A'...)").step(2) { |x| break if x > "F"; ScratchPad << x }
- ScratchPad.recorded.should == ["A", "C", "E"]
- end
+ ScratchPad.record []
+ eval("('A'...)").step(2) { |x| break if x > "F"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "C", "E"]
+ end
- it "raises a TypeError when passed a Float step" do
- -> { eval("('A'..)").step(2.0) { } }.should raise_error(TypeError)
- -> { eval("('A'...)").step(2.0) { } }.should raise_error(TypeError)
- end
+ it "raises a TypeError when passed a Float step" do
+ -> { eval("('A'..)").step(2.0) { } }.should raise_error(TypeError)
+ -> { eval("('A'...)").step(2.0) { } }.should raise_error(TypeError)
end
end
end
@@ -416,24 +414,7 @@ describe "Range#step" do
end
end
- ruby_version_is ""..."2.6" do
- it "raises an ArgumentError if step is 0" do
- enum = (-1..1).step(0)
- -> { enum.size }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError if step is 0.0" do
- enum = (-1..1).step(0.0)
- -> { enum.size }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError if step is negative" do
- enum = (-1..1).step(-2)
- -> { enum.size }.should raise_error(ArgumentError)
- end
- end
-
- ruby_version_is "2.6"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "returns Float::INFINITY for zero step" do
(-1..1).step(0).size.should == Float::INFINITY
(-1..1).step(0.0).size.should == Float::INFINITY
@@ -453,11 +434,9 @@ describe "Range#step" do
(-5...5).step(2).size.should == 5
end
- ruby_version_is "2.6" do
- it "returns the ceil of range size divided by the number of steps even if step is negative" do
- (-1..1).step(-1).size.should == 0
- (1..-1).step(-1).size.should == 3
- end
+ it "returns the ceil of range size divided by the number of steps even if step is negative" do
+ (-1..1).step(-1).size.should == 0
+ (1..-1).step(-1).size.should == 3
end
it "returns the correct number of steps when one of the arguments is a float" do
@@ -496,23 +475,15 @@ describe "Range#step" do
end
describe "type" do
- ruby_version_is ""..."2.6" do
- it "returns an instance of Enumerator" do
- (1..10).step.class.should == Enumerator
+ context "when both begin and end are numerics" do
+ it "returns an instance of Enumerator::ArithmeticSequence" do
+ (1..10).step.class.should == Enumerator::ArithmeticSequence
end
end
- ruby_version_is "2.6" do
- context "when both begin and end are numerics" do
- it "returns an instance of Enumerator::ArithmeticSequence" do
- (1..10).step.class.should == Enumerator::ArithmeticSequence
- end
- end
-
- context "when begin and end are not numerics" do
- it "returns an instance of Enumerator" do
- ("a".."z").step.class.should == Enumerator
- end
+ context "when begin and end are not numerics" do
+ it "returns an instance of Enumerator" do
+ ("a".."z").step.class.should == Enumerator
end
end
end
diff --git a/spec/ruby/core/range/to_a_spec.rb b/spec/ruby/core/range/to_a_spec.rb
index 9a1352b7b0..52ebc02941 100644
--- a/spec/ruby/core/range/to_a_spec.rb
+++ b/spec/ruby/core/range/to_a_spec.rb
@@ -29,10 +29,8 @@ describe "Range#to_a" do
('Σ'..'Ω').to_a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
end
- ruby_version_is "2.6" do
- it "throws an exception for endless ranges" do
- -> { eval("(1..)").to_a }.should raise_error(RangeError)
- end
+ it "throws an exception for endless ranges" do
+ -> { eval("(1..)").to_a }.should raise_error(RangeError)
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/range/to_s_spec.rb b/spec/ruby/core/range/to_s_spec.rb
index 59672da822..581c2e7d90 100644
--- a/spec/ruby/core/range/to_s_spec.rb
+++ b/spec/ruby/core/range/to_s_spec.rb
@@ -11,11 +11,9 @@ describe "Range#to_s" do
(0.5..2.4).to_s.should == "0.5..2.4"
end
- ruby_version_is "2.6" do
- it "can show endless ranges" do
- eval("(1..)").to_s.should == "1.."
- eval("(1.0...)").to_s.should == "1.0..."
- end
+ it "can show endless ranges" do
+ eval("(1..)").to_s.should == "1.."
+ eval("(1.0...)").to_s.should == "1.0..."
end
ruby_version_is "2.7" do