Sha256: db63c18fb83bd8b5c66527f052f15ecc43644ff48aa59c5bd4e4660fabb801ba

Contents?: true

Size: 937 Bytes

Versions: 2

Compression:

Stored size: 937 Bytes

Contents

require 'test_helper'

class CoreExtTest < Test::Unit::TestCase
  test 'Hash#deep_symbolize_keys walks arrays, too' do
    hash     = { 'foo' => [{ 'bar' => 'bar', 'baz' => { 'buz' => 'buz' } }] }
    expected = { :foo  => [{ :bar  => 'bar', :baz  => { :buz  => 'buz' } }] }
    assert_equal expected, hash.deep_symbolize_keys
  end

  test 'Hash#deep_symbolize_keys! replaces with deep_symbolize' do
    hash     = { 'foo' => { 'bar' => 'baz' } }
    expected = { :foo => { :bar => 'baz' } }
    hash.deep_symbolize_keys!
    assert_equal expected, hash
  end

  test 'Hash#slice returns a new hash containing the given keys' do
    hash = { :foo => 'foo', :bar => 'bar', :baz => 'baz' }
    expected = { :foo => 'foo', :bar => 'bar' }
    assert_equal expected, hash.slice(:foo, :bar)
  end

  test 'Hash#slice does not explode on a missing key' do
    hash = {}
    expected = {}
    assert_equal expected, hash.slice(:foo)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hashr-0.0.22 test/core_ext_test.rb
hashr-0.0.21 test/core_ext_test.rb