timezonelist_test.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.locale.TimeZoneListTest');
  15. goog.setTestOnly('goog.locale.TimeZoneListTest');
  16. goog.require('goog.locale');
  17. /** @suppress {extraRequire} */
  18. goog.require('goog.locale.TimeZoneList');
  19. goog.require('goog.testing.jsunit');
  20. function setUpPage() {
  21. // Test data files are in in http://go/js_locale_data
  22. // Test data from TimeZoneSelectedIds__FR.js
  23. var TimeZoneSelectedIds__FR =
  24. ['Etc/GMT+12', 'Pacific/Midway', 'America/Adak', 'Pacific/Honolulu'];
  25. goog.locale.registerTimeZoneSelectedIds(TimeZoneSelectedIds__FR, 'FR');
  26. // Test data from TimeZoneSelectedShortNames__de_DE.js
  27. var TimeZoneSelectedShortNames__de_DE = {
  28. 'Etc/GMT+12': 'GMT-12:00',
  29. 'Etc/GMT+11': 'GMT-11:00',
  30. 'Pacific/Pago_Pago': 'Amerikanisch-Samoa',
  31. 'Pacific/Midway': 'Midway (Amerikanisch-Ozeanien)',
  32. 'Pacific/Honolulu': 'Honolulu (Vereinigte Staaten)',
  33. 'Etc/GMT+10': 'GMT-10:00',
  34. 'America/Adak': 'Adak (Vereinigte Staaten)'
  35. };
  36. goog.locale.registerTimeZoneSelectedShortNames(
  37. TimeZoneSelectedShortNames__de_DE, 'de_DE');
  38. // Test data from TimeZoneSelectedLongNames__de_DE.js
  39. var TimeZoneSelectedLongNames__de_DE = {
  40. 'Etc/GMT+12': 'GMT-12:00',
  41. 'Etc/GMT+11': 'GMT-11:00',
  42. 'Pacific/Pago_Pago': 'GMT-11:00 Amerikanisch-Samoa',
  43. 'Pacific/Midway': 'GMT-11:00 Midway (Amerikanisch-Ozeanien)',
  44. 'Pacific/Honolulu': 'GMT-10:00 Honolulu (Vereinigte Staaten)',
  45. 'Etc/GMT+10': 'GMT-10:00',
  46. 'America/Adak': 'GMT-10:00 Adak (Vereinigte Staaten)'
  47. };
  48. goog.locale.registerTimeZoneSelectedLongNames(
  49. TimeZoneSelectedLongNames__de_DE, 'de_DE');
  50. // Test data from TimeZoneSelectedIds__en.js
  51. var TimeZoneSelectedIds__en =
  52. ['Etc/GMT+12', 'Pacific/Midway', 'America/Adak', 'Pacific/Honolulu'];
  53. goog.locale.registerTimeZoneSelectedIds(TimeZoneSelectedIds__en, 'en');
  54. // Test data from TimeZoneSelectedIds__DE.js
  55. var TimeZoneSelectedIds__DE =
  56. ['Etc/GMT+12', 'Pacific/Midway', 'America/Adak', 'Pacific/Honolulu'];
  57. goog.locale.registerTimeZoneSelectedIds(TimeZoneSelectedIds__DE, 'DE');
  58. // Test data from TimeZoneAllLongNames__de_DE.js
  59. var TimeZoneAllLongNames__de_DE = [
  60. {id: 'Etc/GMT+12', name: 'GMT-12:00'},
  61. {id: 'Pacific/Apia', name: 'GMT-11:00 Samoa'},
  62. {id: 'Pacific/Midway', name: 'GMT-11:00 Midway (Amerikanisch-Ozeanien)'},
  63. {id: 'Pacific/Niue', name: 'GMT-11:00 Niue'},
  64. {id: 'Pacific/Pago_Pago', name: 'GMT-11:00 Amerikanisch-Samoa'},
  65. {id: 'Etc/GMT+11', name: 'GMT-11:00'},
  66. {id: 'America/Adak', name: 'GMT-10:00 Adak (Vereinigte Staaten)'},
  67. {id: 'Pacific/Fakaofo', name: 'GMT-10:00 Tokelau'}
  68. ];
  69. goog.locale.registerTimeZoneAllLongNames(
  70. TimeZoneAllLongNames__de_DE, 'de_DE');
  71. goog.locale.setLocale('de_DE');
  72. }
  73. /* Uncomment to display complete listing in the unit tested invocations.
  74. document.write('Shortnames in German for France:<br>');
  75. var idlist = goog.locale.getTimeZoneSelectedShortNames('FR');
  76. for (var i = 0; i < idlist.length; i++) {
  77. document.write(i + ') ' + idlist[i].id + ' = ' + idlist[i].name + '<br>');
  78. }
  79. document.write('<hr>');
  80. document.write('long names in German for all en speakers:<br>');
  81. var idlist = goog.locale.getTimeZoneSelectedLongNames('en');
  82. for (var i = 0; i < idlist.length; i++) {
  83. document.write(i + ') ' + idlist[i].id + ' = ' + idlist[i].name + '<br>');
  84. }
  85. document.write('<hr>');
  86. document.write('Longnames in German for germans:<br>');
  87. var idlist = goog.locale.getTimeZoneSelectedLongNames();
  88. for (var i = 0; i < idlist.length; i++) {
  89. document.write(i + ') ' + idlist[i].id + ' = ' + idlist[i].name + '<br>');
  90. }
  91. document.write('<hr>');
  92. document.write('All longnames in German:<br>');
  93. var idlist = goog.locale.getTimeZoneAllLongNames();
  94. for (var i = 0; i < idlist.length; i++) {
  95. var pair = idlist[i];
  96. document.write(i + ') ' + pair.id + ' = ' + pair.name + '<br>');
  97. }
  98. document.write('<hr>');
  99. */
  100. // Test cases.
  101. function testTimeZoneSelectedShortNames() {
  102. // Shortnames in German for France.
  103. var result = goog.locale.getTimeZoneSelectedShortNames('FR');
  104. assertEquals('Honolulu (Vereinigte Staaten)', result[3].name);
  105. }
  106. function testTimeZoneSelectedLongNames() {
  107. // Long names in German for all English speaking regions.
  108. var result = goog.locale.getTimeZoneSelectedLongNames('en');
  109. assertEquals('GMT-11:00 Midway (Amerikanisch-Ozeanien)', result[1].name);
  110. // Long names in German for germans.
  111. var result = goog.locale.getTimeZoneSelectedLongNames();
  112. assertEquals('GMT-10:00 Adak (Vereinigte Staaten)', result[2].name);
  113. }
  114. function testTimeZoneAllLongNames() {
  115. // All longnames in German
  116. var result = goog.locale.getTimeZoneAllLongNames();
  117. assertEquals('GMT-10:00 Tokelau', result[7].name);
  118. }