Class: TestSymbolize

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/core_ext/symbolize.rb

Instance Method Summary collapse

Instance Method Details

#test_array_symbolizeObject



36
37
38
39
40
41
# File 'lib/core_ext/symbolize.rb', line 36

def test_array_symbolize
  array = ('a'..'d').to_a
  expected = array.map { |e| e.to_sym }
  
  assert_equal(expected, array.symbolize)
end

#test_array_with_hash_insideObject



70
71
72
73
# File 'lib/core_ext/symbolize.rb', line 70

def test_array_with_hash_inside                             
  assert_equal( [:a , { :b => :c, :d => 'x x'}],
                ['a' , { 'b' => 'c', 'd' => 'x x'}].symbolize )
end

#test_array_with_non_word_elementObject



51
52
53
# File 'lib/core_ext/symbolize.rb', line 51

def test_array_with_non_word_element
  assert_equal([:a, :b, :c, 'x x'], ['a', 'b', 'c', 'x x'].symbolize)
end

#test_hash_symbolizeObject



43
44
45
46
47
48
49
# File 'lib/core_ext/symbolize.rb', line 43

def test_hash_symbolize
  hash = {'a' => 'x', 'b' => 'y', 'c' => 'z'}
  
  expected = hash.inject({}) { |h, (a, v)|  h[a.to_sym] = v.to_sym; h }
  
  assert_equal(expected, hash.symbolize)
end

#test_hash_with_array_insideObject



65
66
67
68
# File 'lib/core_ext/symbolize.rb', line 65

def test_hash_with_array_inside
  assert_equal( {:a => :x, :b => [ :c, :d, 'x x']},
                {'a' => 'x', 'b' => [ 'c', 'd', 'x x']}.symbolize )
end

#test_hash_with_non_word_stringsObject



55
56
57
58
59
60
61
62
63
# File 'lib/core_ext/symbolize.rb', line 55

def test_hash_with_non_word_strings
  assert_equal( {:a => :x, :b => :y, :c => 'a b', 'x x' => :c},
                { 'a' => 'x', 
                  'b' => 'y', 
                  'c' => 'a b', 
                  'x x' => 'c'
                }.symbolize 
              )
end

#test_integer_symbolizeObject



28
29
30
# File 'lib/core_ext/symbolize.rb', line 28

def test_integer_symbolize
  assert_equal(1, 1.symbolize)
end

#test_string_symbolizeObject



32
33
34
# File 'lib/core_ext/symbolize.rb', line 32

def test_string_symbolize
  assert_equal(:expected, "expected".symbolize)
end