Sha256: 3739366d4a3c8f60d7935708ed8800ffda9465b3b84986e1df2a6b445306f5a4

Contents?: true

Size: 1.77 KB

Versions: 11

Compression:

Stored size: 1.77 KB

Contents

require 'test/unit'

require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/ext/hash_extensions')

# Tests for the Hash extension methods
class TestHashExtensions < Test::Unit::TestCase
  def test_deep_merge!
    h1 = { key: 'value', key2: %w(value1, value2) }
    h2 = { key: 'another_value' }
    exp_result = { key: 'another_value', key2: %w(value1, value2) }
    actual_result = h1.deep_merge!(h2)
    
    assert_equal(exp_result, actual_result)
  end
  
  def test_deep_stringify_keys
    h = { key: { subkey1: 'value1', subkey2: { subsubkey1: 'value' } } }
    exp_result = { 'key' => { 'subkey1' => 'value1', 'subkey2' => { 'subsubkey1' => 'value' } } }
    actual_result = h.deep_stringify_keys
    
    assert_not_equal(h, actual_result)
    assert_equal(exp_result, actual_result)
  end
  
  def test_deep_stringify_keys!
    h = {key: {subkey1: 'value1', subkey2: {subsubkey1: 'value'}}}
    exp_result = { 'key' => { 'subkey1' => 'value1', 'subkey2' => { 'subsubkey1' => 'value' } } }
    actual_result = h.deep_stringify_keys!
    
    assert_equal(h, actual_result)
    assert_equal(exp_result, actual_result)
  end
  
  def test_deep_symbolize_keys
    h = { 'key' => { 'subkey1' => 'value1', 'subkey2' => { 'subsubkey1' => 'value'} } }
    exp_result = { key: { subkey1: 'value1', subkey2: { subsubkey1: 'value'} } }
    actual_result = h.deep_symbolize_keys
    
    assert_not_equal(h, actual_result)
    assert_equal(exp_result, actual_result)
  end

  def test_deep_symbolize_keys!
    h = { 'key' => { 'subkey1' => 'value1', 'subkey2' => { 'subsubkey1' => 'value'} } }
    exp_result = { key: { subkey1: 'value1', subkey2: { subsubkey1: 'value'} } }
    actual_result = h.deep_symbolize_keys!
    
    assert_equal(h, actual_result)
    assert_equal(exp_result, actual_result)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cliutils-1.4.2 test/hash_extensions_test.rb
cliutils-1.4.1 test/hash_extensions_test.rb
cliutils-1.4.0 test/hash_extensions_test.rb
cliutils-1.3.1 test/hash_extensions_test.rb
cliutils-1.3.0 test/hash_extensions_test.rb
cliutils-1.2.9 test/hash_extensions_test.rb
cliutils-1.2.8 test/hash_extensions_test.rb
cliutils-1.2.7 test/hash_extensions_test.rb
cliutils-1.2.6 test/hash_extensions_test.rb
cliutils-1.2.5 test/hash_extensions_test.rb
cliutils-1.2.4 test/hash_extensions_test.rb