Skip to content

Commit

Permalink
Add specs for Range#reverse_each
Browse files Browse the repository at this point in the history
  • Loading branch information
herwinw committed Jun 27, 2024
1 parent a62556b commit 5dc543d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions core/range/reverse_each_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_relative '../../spec_helper'

ruby_version_is "3.3" do
describe "Range#reverse_each" do
it "works efficiently for very long Ranges of Integers" do
(1..2**100).reverse_each.take(3).size.should == 3
end

it "works for infinite Ranges of Integers" do
(..5).reverse_each.take(3).should == [5, 4, 3]
end

it "works for Ranges of Strings by converting the Range to an Array first" do
("a".."z").reverse_each.take(3).should == ["z", "y", "x"]
end

it "raises a TypeError for endless Ranges of Integers" do
-> {
(1..).reverse_each.take(3)
}.should raise_error(TypeError, "can't iterate from NilClass")
end

it "raises a TypeError for endless Ranges of other objects" do
-> {
("a"..).reverse_each.take(3)
}.should raise_error(TypeError, "can't iterate from NilClass")
end
end
end

0 comments on commit 5dc543d

Please sign in to comment.