Sha256: 3daa336bf57bb21b46e68c2e28567866585186e43d25272b23347f1c37f2e37d

Contents?: true

Size: 989 Bytes

Versions: 169

Compression:

Stored size: 989 Bytes

Contents

require 'test_helper'
require 'tins/xt'

module Tins
  class HashUnionTest < Test::Unit::TestCase

    class HashLike1
      def to_hash
        { 'foo' => true }
      end
    end

    class HashLike2
      def to_h
        { 'foo' => true }
      end
    end

    def test_union
      defaults = { 'foo' => true, 'bar' => false, 'quux' => nil }
      hash = { 'foo' => false }
      assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ],
        (hash | defaults).sort
      hash |= defaults
      assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ],
        hash.sort
      hash = { 'foo' => false }
      hash |= {
        'quux' => true,
        'baz' => 23,
      } | defaults
      assert_equal [ ['bar', false], [ 'baz', 23 ], ['foo', false],
        ['quux', true] ],
        hash.sort
    end

    def test_hash_conversion
      assert_equal({ 'foo' => true }, { } | HashLike1.new)
      assert_equal({ 'foo' => true }, { } | HashLike2.new)
    end
  end
end

Version data entries

169 entries across 151 versions & 9 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/tins-1.13.2/tests/hash_union_test.rb
tins-1.14.0 tests/hash_union_test.rb
tins-1.13.3 tests/hash_union_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/tins-1.13.2/tests/hash_union_test.rb
tdiary-5.0.4 vendor/bundle/gems/tins-1.13.2/tests/hash_union_test.rb
tins-1.13.2 tests/hash_union_test.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/tins-1.13.0/tests/hash_union_test.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/tins-1.13.0/tests/hash_union_test.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/tins-1.13.0/tests/hash_union_test.rb
tins-1.13.0 tests/hash_union_test.rb
tdiary-5.0.2 vendor/bundle/gems/tins-1.12.0/tests/hash_union_test.rb
tins-1.12.0 tests/hash_union_test.rb
tins-1.11.0 tests/hash_union_test.rb
tdiary-5.0.1 vendor/bundle/gems/tins-1.10.2/tests/hash_union_test.rb
tins-1.10.2 tests/hash_union_test.rb
tins-1.10.1 tests/hash_union_test.rb
tins-1.10.0 tests/hash_union_test.rb
tins-1.9.0 tests/hash_union_test.rb
tins-1.8.2 tests/hash_union_test.rb
tins-1.8.1 tests/hash_union_test.rb