Sha256: fa34d8af3815460b1ac5a77a19fa471f21c349dbb6abfabaed2ebd0a0cc7d266

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 Bytes

Contents

require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  describe "#compact" do
    it "returns a new Vector with all nils removed" do
      V[1, nil, 2, nil].compact.should eql(V[1, 2])
      V[1, 2, 3].compact.should eql(V[1, 2, 3])
      V[nil].compact.should eql(V.empty)
    end

    context "on an empty vector" do
      it "returns self" do
        V.empty.compact.should be(V.empty)
      end
    end

    it "doesn't remove false" do
      V[false].compact.should eql(V[false])
    end

    context "from a subclass" do
      it "returns an instance of the subclass" do
        subclass = Class.new(V)
        instance = subclass[1, nil, 2]
        instance.compact.class.should be(subclass)
      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/vector/compact_spec.rb
hamster-3.0.0 spec/lib/hamster/vector/compact_spec.rb
hamster-2.0.0 spec/lib/hamster/vector/compact_spec.rb