-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |