Sha256: 248b3d63264ae8734b8a5e13f29f536d2aba27976aa506be0003ff956387c743

Contents?: true

Size: 1018 Bytes

Versions: 3

Compression:

Stored size: 1018 Bytes

Contents

require "spec_helper"
require "hamster/list"

describe Hamster::List do
  describe "#drop_while" do
    it "is lazy" do
      -> { Hamster.stream { fail }.drop_while { false } }.should_not raise_error
    end

    [
      [[], []],
      [["A"], []],
      [%w[A B C], ["C"]],
    ].each do |values, expected|
      context "on #{values.inspect}" do
        let(:list) { L[*values] }

        context "with a block" do
          it "preserves the original" do
            list.drop_while { |item| item < "C" }
            list.should eql(L[*values])
          end

          it "returns #{expected.inspect}" do
            list.drop_while { |item| item < "C" }.should eql(L[*expected])
          end
        end

        context "without a block" do
          it "returns an Enumerator" do
            list.drop_while.class.should be(Enumerator)
            list.drop_while.each { false }.should eql(list)
            list.drop_while.each { true  }.should be_empty
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/list/drop_while_spec.rb
hamster-3.0.0 spec/lib/hamster/list/drop_while_spec.rb
hamster-2.0.0 spec/lib/hamster/list/drop_while_spec.rb