PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/External.LCA_RESTRICTED/Languages/Ruby/ruby19/lib/ruby/gems/1.9.1/gems/tzinfo-0.3.23/test/tc_country.rb

http://github.com/IronLanguages/main
Ruby | 156 lines | 120 code | 32 blank | 4 comment | 3 complexity | 0e08af239f7a2beeb56b48484d45299b MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  2. require 'test/unit'
  3. require File.join(File.dirname(__FILE__), 'test_utils')
  4. require 'tzinfo'
  5. include TZInfo
  6. class TCCountry < Test::Unit::TestCase
  7. def test_get_valid
  8. c = Country.get('GB')
  9. assert c
  10. assert_equal('GB', c.code)
  11. end
  12. def test_get_not_exist
  13. assert_raises(InvalidCountryCode) {
  14. Country.get('ZZ')
  15. }
  16. end
  17. def test_get_invalid
  18. assert_raises(InvalidCountryCode) {
  19. Country.get('../Countries/GB')
  20. }
  21. end
  22. def test_get_nil
  23. assert_raises(InvalidCountryCode) {
  24. Country.get(nil)
  25. }
  26. end
  27. def test_get_case
  28. assert_raises(InvalidCountryCode) {
  29. Country.get('gb')
  30. }
  31. end
  32. def test_new_nil
  33. assert_raises(InvalidCountryCode) {
  34. c = Country.new(nil)
  35. }
  36. end
  37. def test_new_arg
  38. c = Country.new('GB')
  39. assert_same(Country.get('GB'), c)
  40. end
  41. def test_new_arg_not_exist
  42. assert_raises(InvalidCountryCode) {
  43. Country.new('ZZ')
  44. }
  45. end
  46. def test_all_codes
  47. all_codes = Country.all_codes
  48. assert_kind_of(Array, all_codes)
  49. end
  50. def test_all
  51. all = Country.all
  52. assert_equal(Country.all_codes, all.collect {|c| c.code})
  53. end
  54. def test_code
  55. assert_equal('US', Country.get('US').code)
  56. end
  57. def test_name
  58. assert_kind_of(String, Country.get('US').name)
  59. end
  60. def test_to_s
  61. assert_equal(Country.get('US').name, Country.get('US').to_s)
  62. assert_equal(Country.get('GB').name, Country.get('GB').to_s)
  63. end
  64. def test_zone_identifiers
  65. zone_names = Country.get('US').zone_names
  66. assert_kind_of(Array, zone_names)
  67. assert_equal(true, zone_names.frozen?)
  68. end
  69. def test_zone_names
  70. assert_equal(Country.get('US').zone_identifiers, Country.get('US').zone_names)
  71. end
  72. def test_zones
  73. zones = Country.get('US').zones
  74. assert_kind_of(Array, zones)
  75. assert_equal(Country.get('US').zone_identifiers, zones.collect {|z| z.identifier})
  76. zones.each {|z| assert_kind_of(TimezoneProxy, z)}
  77. end
  78. def test_zone_info
  79. zones = Country.get('US').zone_info
  80. assert_kind_of(Array, zones)
  81. assert_equal(true, zones.frozen?)
  82. assert_equal(Country.get('US').zone_identifiers, zones.collect {|z| z.identifier})
  83. assert_equal(Country.get('US').zone_identifiers, zones.collect {|z| z.timezone.identifier})
  84. zones.each {|z| assert_kind_of(CountryTimezone, z)}
  85. end
  86. def test_compare
  87. assert_equal(0, Country.get('GB') <=> Country.get('GB'))
  88. assert_equal(-1, Country.get('GB') <=> Country.get('US'))
  89. assert_equal(1, Country.get('US') <=> Country.get('GB'))
  90. assert_equal(-1, Country.get('FR') <=> Country.get('US'))
  91. assert_equal(1, Country.get('US') <=> Country.get('FR'))
  92. end
  93. def test_equality
  94. assert_equal(true, Country.get('GB') == Country.get('GB'))
  95. assert_equal(false, Country.get('GB') == Country.get('US'))
  96. assert(!(Country.get('GB') == Object.new))
  97. end
  98. def test_eql
  99. assert_equal(true, Country.get('GB').eql?(Country.get('GB')))
  100. assert_equal(false, Country.get('GB').eql?(Country.get('US')))
  101. assert(!Country.get('GB').eql?(Object.new))
  102. end
  103. def test_hash
  104. assert_equal('GB'.hash, Country.get('GB').hash)
  105. assert_equal('US'.hash, Country.get('US').hash)
  106. end
  107. def test_marshal
  108. c = Country.get('US')
  109. # Should get back the same instance because load calls Country.get.
  110. assert_same(c, Marshal.load(Marshal.dump(c)))
  111. end
  112. def test_reload
  113. # If country gets reloaded for some reason, it needs to force a reload of
  114. # the country index.
  115. c = Country.get('US')
  116. assert_equal('US', Country.get('US').code)
  117. # Suppress redefined method warnings.
  118. without_warnings do
  119. load 'tzinfo/country.rb'
  120. end
  121. c = Country.get('US')
  122. assert_equal('US', Country.get('US').code)
  123. end
  124. end