Skip to content

Commit

Permalink
Merge pull request #1168 from herwinw/enumerator_with_index
Browse files Browse the repository at this point in the history
Separate specs for Enumerator#each_with_index and Enumerator#with_index
  • Loading branch information
andrykonchin authored Jul 1, 2024
2 parents f8987ac + 123cfbd commit 0eb86e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/enumerator/each_with_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

it "passes on the given block's return value" do
arr = [1,2,3]
arr.delete_if.with_index { |a,b| false }
arr.delete_if.each_with_index { |a,b| false }
arr.should == [1,2,3]
end

it "returns the iterator's return value" do
[1,2,3].select.with_index { |a,b| false }.should == []
[1,2,3].select.each_with_index { |a,b| false }.should == []
[1,2,3].select.each_with_index { |a,b| true }.should == [1,2,3]
end

it "returns the correct value if chained with itself" do
[:a].each_with_index.each_with_index.to_a.should == [[[:a,0],0]]
[:a].each.with_index.with_index.to_a.should == [[[:a,0],0]]
end
end
17 changes: 17 additions & 0 deletions core/enumerator/with_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,21 @@
@enum.with_index(-1) { |*x| res << x}
res.should == [[1,-1], [2,0], [3,1], [4,2]]
end

it "passes on the given block's return value" do
arr = [1,2,3]
arr.delete_if.with_index { |a,b| false }
arr.should == [1,2,3]

arr.delete_if.with_index { |a,b| true }
arr.should == []
end

it "returns the iterator's return value" do
@enum.select.with_index { |a,b| false }.should == []
end

it "returns the correct value if chained with itself" do
[:a].each.with_index.with_index.to_a.should == [[[:a,0],0]]
end
end

0 comments on commit 0eb86e1

Please sign in to comment.