Sha256: 58842296a95f9366049f8c353c7c6ca1fd5f9cc6254e28ac6487ff85dcec14c8

Contents?: true

Size: 1.79 KB

Versions: 21

Compression:

Stored size: 1.79 KB

Contents

require 'test_helper'
require 'review/extentions/hash'

class TestExtentionsHash < Test::Unit::TestCase
  def test_deep_merge_simple
    assert_equal({ a: 1, b: 3, c: 4 },
                 { a: 1, b: 2 }.deep_merge(b: 3, c: 4))
  end

  def test_deep_empty_r
    assert_equal({ b: 3, c: 4 },
                 {}.deep_merge(b: 3, c: 4))
  end

  def test_deep_empty_l
    assert_equal({ a: 1, b: 2 },
                 { a: 1, b: 2 }.deep_merge({}))
  end

  def test_deep_merge_nested
    assert_equal({ a: { aa: 1, ab: 2 },
                   b: { ba: 5, bb: 4, bc: 6 },
                   c: { ca: 1 } },
                 { a: { aa: 1, ab: 2 },
                   b: { ba: 3, bb: 4 } }.deep_merge(b: { ba: 5, bc: 6 },
                                                    c: { ca: 1 }))
  end

  def test_deep_merge_with_array
    assert_equal({ a: 'string', b: ['BA'],
                   c: { ca: [cab: 'CAB'], cb: 3 } },
                 { a: 1, b: ['shouldoverriden'],
                   c: { ca: [caa: 'shouldoverriden'], cb: 3 } }.
                   deep_merge(a: 'string', b: ['BA'],
                              c: { ca: [cab: 'CAB'] }))
  end

  def test_deep_merge_b_simple
    a = { a: 1, b: 2 }
    a.deep_merge!(b: 3, c: 4)
    assert_equal({ a: 1, b: 3, c: 4 }, a)
  end

  def test_deep_b_empty_r
    a = {}
    a.deep_merge!(b: 3, c: 4)
    assert_equal({ b: 3, c: 4 }, a)
  end

  def test_deep_b_empty_l
    a = { a: 1, b: 2 }
    a.deep_merge!({})
    assert_equal({ a: 1, b: 2 }, a)
  end

  def test_deep_merge_b_nested
    a = { a: { aa: 1, ab: 2 },
          b: { ba: 3, bb: 4 } }
    a.deep_merge!(b: { ba: 5, bc: 6 },
                  c: { ca: 1 })
    assert_equal({ a: { aa: 1, ab:  2 },
                   b: { ba: 5, bb: 4, bc: 6 },
                   c: { ca: 1 } },
                 a)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
review-5.6.0 test/test_extentions_hash.rb
review-5.5.0 test/test_extentions_hash.rb
review-5.4.0 test/test_extentions_hash.rb
review-5.3.0 test/test_extentions_hash.rb
review-5.2.0 test/test_extentions_hash.rb
review-5.1.1 test/test_extentions_hash.rb
review-5.1.0 test/test_extentions_hash.rb
review-5.0.0 test/test_extentions_hash.rb
review-4.2.0 test/test_extentions_hash.rb
review-4.1.0 test/test_extentions_hash.rb
review-4.0.0 test/test_extentions_hash.rb
review-3.2.0 test/test_extentions_hash.rb
review-3.1.0 test/test_extentions_hash.rb
review-3.0.0 test/test_extentions_hash.rb
review-3.0.0.rc1 test/test_extentions_hash.rb
review-3.0.0.preview4 test/test_extentions_hash.rb
review-3.0.0.preview3 test/test_extentions_hash.rb
review-3.0.0.preview2 test/test_extentions_hash.rb
review-3.0.0.preview1 test/test_extentions_hash.rb
review-2.5.0 test/test_extentions_hash.rb