Sha256: d8ec88fbd1bf8bd37e89b76d4f4d2c5f5452190791f44dc1f85f9c4e6ff78c9e

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  describe "#drop_while" do
    [
      [[], []],
      [["A"], []],
      [%w[A B C], ["C"]],
    ].each do |values, expected|
      describe "on #{values.inspect}" do
        let(:vector) { V[*values] }

        describe "with a block" do
          let(:result) { vector.drop_while { |item| item < "C" } }

          it "preserves the original" do
            result
            vector.should eql(V[*values])
          end

          it "returns #{expected.inspect}" do
            result.should eql(V[*expected])
          end
        end

        describe "without a block" do
          it "returns an Enumerator" do
            vector.drop_while.class.should be(Enumerator)
            vector.drop_while.each { |item| item < "C" }.should eql(V[*expected])
          end
        end
      end
    end

    context "on an empty vector" do
      it "returns an empty vector" do
        V.empty.drop_while { false }.should eql(V.empty)
      end
    end

    it "returns an empty vector if block is always true" do
      V.new(1..32).drop_while { true }.should eql(V.empty)
      V.new(1..100).drop_while { true }.should eql(V.empty)
    end

    it "stops dropping items if block returns nil" do
      V[1, 2, 3, nil, 4, 5].drop_while { |x| x }.should eql(V[nil, 4, 5])
    end

    it "stops dropping items if block returns false" do
      V[1, 2, 3, false, 4, 5].drop_while { |x| x }.should eql(V[false, 4, 5])
    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/vector/drop_while_spec.rb
hamster-3.0.0 spec/lib/hamster/vector/drop_while_spec.rb
hamster-2.0.0 spec/lib/hamster/vector/drop_while_spec.rb