File: construction_spec.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 930 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'spec_helper'

describe Immutable::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(Immutable::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 an Immutable::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