Skip to content

Commit caa743e

Browse files
herwinwandrykonchin
authored andcommitted
Add specs for Range#reverse_each
1 parent 3f505ce commit caa743e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

core/range/reverse_each_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require_relative '../../spec_helper'
2+
3+
ruby_version_is "3.3" do
4+
describe "Range#reverse_each" do
5+
it "works efficiently for very long Ranges of Integers" do
6+
(1..2**100).reverse_each.take(3).size.should == 3
7+
end
8+
9+
it "works for beginless Ranges of Integers" do
10+
(..5).reverse_each.take(3).should == [5, 4, 3]
11+
end
12+
13+
it "works for Ranges of Strings by converting the Range to an Array first" do
14+
("a".."z").reverse_each.take(3).should == ["z", "y", "x"]
15+
end
16+
17+
it "raises a TypeError for endless Ranges of Integers" do
18+
-> {
19+
(1..).reverse_each.take(3)
20+
}.should raise_error(TypeError, "can't iterate from NilClass")
21+
end
22+
23+
it "raises a TypeError for endless Ranges of other objects" do
24+
-> {
25+
("a"..).reverse_each.take(3)
26+
}.should raise_error(TypeError, "can't iterate from NilClass")
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)