Sha256: 0e0f70e9a8029b13cbb516e870f88395780ef3efbf6a143c529c815110985960

Contents?: true

Size: 945 Bytes

Versions: 3

Compression:

Stored size: 945 Bytes

Contents

require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  describe ".hash" do
    context "with nothing" do
      it "returns the canonical empty hash" do
        H.empty.should be_empty
        H.empty.should equal(Hamster::EmptyHash)
      end
    end

    context "with an implicit hash" do
      let(:hash) { H["A" => "aye", "B" => "bee", "C" => "see"] }

      it "is equivalent to repeatedly using #put" do
        hash.should eql(H.empty.put("A", "aye").put("B", "bee").put("C", "see"))
        hash.size.should == 3
      end
    end

    context "with an array of pairs" do
      let(:hash) { H[[[:a, 1], [:b, 2]]] }

      it "initializes a new Hash" do
        hash.should eql(H[a: 1, b: 2])
      end
    end

    context "with a Hamster::Hash" do
      let(:hash) { H[a: 1, b: 2] }
      let(:other) { H[hash] }

      it "initializes an equivalent Hash" do
        hash.should eql(other)
      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/hash/construction_spec.rb
hamster-3.0.0 spec/lib/hamster/hash/construction_spec.rb
hamster-2.0.0 spec/lib/hamster/hash/construction_spec.rb