Sha256: fff67caac35f182ff9a0e4261d48792ce52d81bea7e36d250fd07960e839fc8f

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require File.dirname(__FILE__) + '/helper'

class HashTest < Test::Unit::TestCase
  def setup
    @h = { :foo => 1, :bar => 2, :baz => 3 }
    @nh = { :foo => { :bar => 2 }, :baz => { :biz => 4 } }
  end

  def test_with_defaults
    assert_equal(@h.with_defaults(:biz => 4), { :foo => 1, :bar => 2, :baz => 3, :biz => 4 })
    assert_equal(@h.with_defaults(:foo => 5), { :foo => 1, :bar => 2, :baz => 3 })
    @h.with_defaults!(:biz => 4)
    assert_equal(@h, { :foo => 1, :bar => 2, :baz => 3, :biz => 4 })
  end

  def test_nested_find
    assert_equal(@nh.nested_find(:baz,:biz), 4)
    assert_equal(@nh.nested_find(:foo,:bar), 2)
    assert_nil(@nh.nested_find(:foo,:biz))
  end

  def test_deep_merge
    a = { :foo => 1, :bar => { :baz => 10, :biz => { :hello => :world }}}
    b = { :pickles => true, :sandwich => { :ham => 2, :bread => { :grains => :whole }}}
    result = { :foo => 1, :pickles => true, :sandwich => { :ham => 2, :bread => { :grains => :whole }}, :bar => { :baz => 10, :biz => { :hello => :world }}}
    a.deep_merge!(b)
    assert_equal(a,result)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
darkhelmet-darkext-0.11.1 test/hash_test.rb
darkhelmet-darkext-0.11.2 test/hash_test.rb