File: union_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 (31 lines) | stat: -rw-r--r-- 823 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
require 'spec_helper'

describe Immutable::List do
  [:union, :|].each do |method|
    describe "##{method}" do
      it 'is lazy' do
        -> { Immutable.stream { fail }.union(Immutable.stream { fail }) }.should_not raise_error
      end

      [
        [[], [], []],
        [['A'], [], ['A']],
        [%w[A B C], [], %w[A B C]],
        [%w[A A], ['A'], ['A']],
      ].each do |a, b, expected|
        context "returns #{expected.inspect}" do
          let(:list_a) { L[*a] }
          let(:list_b) { L[*b] }

          it "for #{a.inspect} and #{b.inspect}"  do
            list_a.send(method, list_b).should eql(L[*expected])
          end

          it "for #{b.inspect} and #{a.inspect}"  do
            list_b.send(method, list_a).should eql(L[*expected])
          end
        end
      end
    end
  end
end