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
tins-1.37.0 tests/hash_union_test.rb
tins-1.36.1 tests/hash_union_test.rb
tins-1.36.0 tests/hash_union_test.rb
tins-1.35.0 tests/hash_union_test.rb
tins-1.34.0 tests/hash_union_test.rb
tins-1.33.0 tests/hash_union_test.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/hash_union_test.rb
tins-1.32.1 tests/hash_union_test.rb
tins-1.32.0 tests/hash_union_test.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/hash_union_test.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/hash_union_test.rb
tins-1.31.1 tests/hash_union_test.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/tests/hash_union_test.rb
tins-1.31.0 tests/hash_union_test.rb
tins-1.30.0 tests/hash_union_test.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/hash_union_test.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/hash_union_test.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/hash_union_test.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/hash_union_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/tests/hash_union_test.rb