File: uniq_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 (35 lines) | stat: -rw-r--r-- 810 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
require 'spec_helper'

describe Immutable::List do
  describe '#uniq' do
    it 'is lazy' do
      -> { Immutable.stream { fail }.uniq }.should_not raise_error
    end

    context 'when passed a block' do
      it 'uses the block to identify duplicates' do
        L['a', 'A', 'b'].uniq(&:upcase).should eql(Immutable::List['a', 'b'])
      end
    end

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

        it 'preserves the original' do
          list.uniq
          list.should eql(L[*values])
        end

        it "returns #{expected.inspect}" do
          list.uniq.should eql(L[*expected])
        end
      end
    end
  end
end