PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/more/test_to_hash.rb

https://bitbucket.org/mediashelf/fedora-migrator
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
  1. require 'facets/to_hash.rb'
  2. require 'test/unit'
  3. class TestArrayConversion < Test::Unit::TestCase
  4. def test_to_h
  5. a = [[1,2],[3,4],[5,6]]
  6. assert_equal( { 1=>2, 3=>4, 5=>6 }, a.to_h )
  7. end
  8. def test_to_h_arrayed
  9. a = [[:a,1,2],[:b,3,4],[:c,5,6]]
  10. assert_equal( { :a=>[1,2], :b=>[3,4], :c=>[5,6] }, a.to_h(true) )
  11. end
  12. #def test_to_hash
  13. # a = [:a,:b,:c]
  14. # assert_equal( { 0=>:a, 1=>:b, 2=>:c }, a.to_hash )
  15. #end
  16. end
  17. class TestEnumerableConversion < Test::Unit::TestCase
  18. def test_to_h
  19. a = [[1,:a],[2,:b],[3,:c]]
  20. assert_equal( { 1=>:a, 2=>:b, 3=>:c }, a.to_h )
  21. end
  22. #def test_to_hash
  23. # a = [:a,:b,:c]
  24. # assert_equal( { 0=>:a, 1=>:b, 2=>:c }, a.to_hash )
  25. #end
  26. end
  27. class TestHashConversion < Test::Unit::TestCase
  28. def test_to_h
  29. a = { :a => 1, :b => 2, :c => 3 }
  30. assert_equal( a, a.to_h )
  31. end
  32. end
  33. class TestNilClassConversion < Test::Unit::TestCase
  34. def test_to_h
  35. assert_equal( {}, nil.to_h )
  36. end
  37. end