Sha256: ad01abd69a9f61d01921a6518342f38784fadb0cc1880a5e525520a5c8d4ab77

Contents?: true

Size: 1002 Bytes

Versions: 3

Compression:

Stored size: 1002 Bytes

Contents

require_relative 'test_helper'

class CanalTest < Minitest::Test
  def test_identity
    f = canal
    value = Object.new

    assert_equal(value.object_id, f.(value).object_id)
  end

  def test_hash
    f = canal[:foo]
    value = { foo: :bar }

    assert_equal(:bar, f.(value))
  end

  def test_operators
    operators = %w(+ - * / % ** == === != < > <= >=)

    operators.each do |operator|
      a = 123
      b = 65

      assert_equal(a.send(operator, b), canal.send(operator, b).(a))
    end
  end

  def test_immutability
    f = canal[:foo]
    g = f[:bar]

    assert_equal(123, f.({ foo: 123 }))
    assert_equal(456, g.({ foo: { bar: 456 } }))
    refute_equal(f.object_id, g.object_id)
  end

  def test_kwargs
    f = canal.foo(bar: 123)
    cls = Class.new do
      def foo(bar:)
        bar
      end
    end

    assert_equal(123, f.(cls.new))
  end

  def test_block
    f = canal.map(&canal + 1) + [:foo]
    value = [0, 1, 2]

    assert_equal([1,2,3,:foo], f.(value))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
canal-0.0.6 test/canal_test.rb
canal-0.0.5 test/canal_test.rb
canal-0.0.4 test/canal_test.rb