Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/enumerable/shared/value_packing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe :enumerable_value_packing, shared: true do
# @take must be set to a Proc that returns the take-result whose #each
# yields packed values (e.g. -> e { e.take(1) } or -> e { e.lazy.take(1) }).

it "yields a single nil for a zero-argument source yield" do
e = Enumerator.new { |y| y.yield }
args = nil
@take.call(e).each { |*a| args = a }
args.should == [nil]
end

it "yields the value for a single-argument source yield" do
e = Enumerator.new { |y| y.yield :v }
args = nil
@take.call(e).each { |*a| args = a }
args.should == [:v]
end

it "yields a packed Array for a multi-argument source yield" do
e = Enumerator.new { |y| y.yield 1, 2 }
args = nil
@take.call(e).each { |*a| args = a }
args.should == [[1, 2]]
end
end
8 changes: 8 additions & 0 deletions core/enumerable/take_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'shared/take'
require_relative 'shared/value_packing'

describe "Enumerable#take" do
it "requires an argument" do
Expand All @@ -10,4 +11,11 @@
describe "when passed an argument" do
it_behaves_like :enumerable_take, :take
end

describe "value packing of source yields" do
before :each do
@take = -> e { e.take(1) }
end
it_behaves_like :enumerable_value_packing, nil
end
end
8 changes: 8 additions & 0 deletions core/enumerator/lazy/take_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

require_relative '../../../spec_helper'
require_relative 'fixtures/classes'
require_relative '../../enumerable/shared/value_packing'

describe "Enumerator::Lazy#take" do
describe "value packing of source yields (matches Enumerable#take)" do
before :each do
@take = -> e { e.lazy.take(1) }
end
it_behaves_like :enumerable_value_packing, nil
end

before :each do
@yieldsmixed = EnumeratorLazySpecs::YieldsMixed.new.to_enum.lazy
@eventsmixed = EnumeratorLazySpecs::EventsMixed.new.to_enum.lazy
Expand Down
Loading