dbce325fa056be326a235e78107cebd4d26b4a0d.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. if (!dojo._hasResource["tests.currency"]) { // _hasResource checks added by
  2. // build. Do not use _hasResource
  3. // directly in your code.
  4. dojo._hasResource["tests.currency"] = true;
  5. dojo.provide("tests.currency");
  6. dojo.require("dojo.currency");
  7. tests.register("tests.currency", [{
  8. // Test formatting and parsing of currencies in various locales
  9. // pre-built in dojo.cldr
  10. // NOTE: we can't set djConfig.extraLocale before bootstrapping unit
  11. // tests, so directly
  12. // load resources here for specific locales:
  13. name : "currency",
  14. setUp : function() {
  15. var partLocaleList = ["en-us", "en-ca", "de-de"];
  16. for (var i = 0; i < partLocaleList.length; i++) {
  17. dojo.requireLocalization("dojo.cldr", "currency",
  18. partLocaleList[i],
  19. "ko,zh,ja,en,en-ca,en-au,ROOT,en-us,it,fr,pt,es,de");
  20. dojo
  21. .requireLocalization("dojo.cldr", "number",
  22. partLocaleList[i],
  23. "zh-cn,en,en-ca,zh-tw,en-us,it,ja-jp,ROOT,de-de,es-es,fr,pt,ko-kr,es,de");
  24. }
  25. },
  26. runTest : function(t) {
  27. t.is("\u20ac123.45", dojo.currency.format(123.45, {
  28. currency : "EUR",
  29. locale : "en-us"
  30. }));
  31. t.is("$123.45", dojo.currency.format(123.45, {
  32. currency : "USD",
  33. locale : "en-us"
  34. }));
  35. t.is("$1,234.56", dojo.currency.format(1234.56, {
  36. currency : "USD",
  37. locale : "en-us"
  38. }));
  39. t.is("US$123.45", dojo.currency.format(123.45, {
  40. currency : "USD",
  41. locale : "en-ca"
  42. }));
  43. t.is("$123.45", dojo.currency.format(123.45, {
  44. currency : "CAD",
  45. locale : "en-ca"
  46. }));
  47. t.is("Can$123.45", dojo.currency.format(123.45, {
  48. currency : "CAD",
  49. locale : "en-us"
  50. }));
  51. t.is("123,45 \u20ac", dojo.currency.format(123.45, {
  52. currency : "EUR",
  53. locale : "de-de"
  54. }));
  55. t.is("1.234,56 \u20ac", dojo.currency.format(1234.56, {
  56. currency : "EUR",
  57. locale : "de-de"
  58. }));
  59. // There is no special currency symbol for ADP, so expect the ISO
  60. // code instead
  61. t.is("ADP123", dojo.currency.format(123, {
  62. currency : "ADP",
  63. locale : "en-us"
  64. }));
  65. t.is(123.45, dojo.currency.parse("$123.45", {
  66. currency : "USD",
  67. locale : "en-us"
  68. }));
  69. t.is(1234.56, dojo.currency.parse("$1,234.56", {
  70. currency : "USD",
  71. locale : "en-us"
  72. }));
  73. t.is(123.45, dojo.currency.parse("123,45 \u20ac", {
  74. currency : "EUR",
  75. locale : "de-de"
  76. }));
  77. t.is(1234.56, dojo.currency.parse("1.234,56 \u20ac", {
  78. currency : "EUR",
  79. locale : "de-de"
  80. }));
  81. t.is(1234.56, dojo.currency.parse("1.234,56\u20ac", {
  82. currency : "EUR",
  83. locale : "de-de"
  84. }));
  85. t.is(1234, dojo.currency.parse("$1,234", {
  86. currency : "USD",
  87. locale : "en-us"
  88. }));
  89. t.is(1234, dojo.currency.parse("$1,234", {
  90. currency : "USD",
  91. fractional : false,
  92. locale : "en-us"
  93. }));
  94. t.t(isNaN(dojo.currency.parse("$1,234", {
  95. currency : "USD",
  96. fractional : true,
  97. locale : "en-us"
  98. })));
  99. }
  100. }]);
  101. }