/vendor/gems/facets-2.4.5/test/more/test_to_hash.rb
Ruby | 58 lines | 29 code | 21 blank | 8 comment | 0 complexity | 8fdc31043b048318d43665670ed55df9 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
- require 'facets/to_hash.rb'
- require 'test/unit'
- class TestArrayConversion < Test::Unit::TestCase
- def test_to_h
- a = [[1,2],[3,4],[5,6]]
- assert_equal( { 1=>2, 3=>4, 5=>6 }, a.to_h )
- end
- def test_to_h_arrayed
- a = [[:a,1,2],[:b,3,4],[:c,5,6]]
- assert_equal( { :a=>[1,2], :b=>[3,4], :c=>[5,6] }, a.to_h(true) )
- end
- #def test_to_hash
- # a = [:a,:b,:c]
- # assert_equal( { 0=>:a, 1=>:b, 2=>:c }, a.to_hash )
- #end
- end
- class TestEnumerableConversion < Test::Unit::TestCase
- def test_to_h
- a = [[1,:a],[2,:b],[3,:c]]
- assert_equal( { 1=>:a, 2=>:b, 3=>:c }, a.to_h )
- end
- #def test_to_hash
- # a = [:a,:b,:c]
- # assert_equal( { 0=>:a, 1=>:b, 2=>:c }, a.to_hash )
- #end
- end
- class TestHashConversion < Test::Unit::TestCase
- def test_to_h
- a = { :a => 1, :b => 2, :c => 3 }
- assert_equal( a, a.to_h )
- end
- end
- class TestNilClassConversion < Test::Unit::TestCase
- def test_to_h
- assert_equal( {}, nil.to_h )
- end
- end