test-l10n-plural-rules.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. const { getRulesForLocale } = require("sdk/l10n/plural-rules");
  5. // For more information, please visit unicode website:
  6. // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
  7. function map(assert, f, n, form) {
  8. assert.equal(f(n), form, n + " maps to '" + form + "'");
  9. }
  10. exports.testFrench = function(assert) {
  11. let f = getRulesForLocale("fr");
  12. map(assert, f, -1, "other");
  13. map(assert, f, 0, "one");
  14. map(assert, f, 1, "one");
  15. map(assert, f, 1.5, "one");
  16. map(assert, f, 2, "other");
  17. map(assert, f, 100, "other");
  18. }
  19. exports.testEnglish = function(assert) {
  20. let f = getRulesForLocale("en");
  21. map(assert, f, -1, "other");
  22. map(assert, f, 0, "other");
  23. map(assert, f, 1, "one");
  24. map(assert, f, 1.5, "other");
  25. map(assert, f, 2, "other");
  26. map(assert, f, 100, "other");
  27. }
  28. exports.testArabic = function(assert) {
  29. let f = getRulesForLocale("ar");
  30. map(assert, f, -1, "other");
  31. map(assert, f, 0, "zero");
  32. map(assert, f, 0.5, "other");
  33. map(assert, f, 1, "one");
  34. map(assert, f, 1.5, "other");
  35. map(assert, f, 2, "two");
  36. map(assert, f, 2.5, "other");
  37. map(assert, f, 3, "few");
  38. map(assert, f, 3.5, "few"); // I'd expect it to be 'other', but the unicode.org
  39. // algorithm computes 'few'.
  40. map(assert, f, 5, "few");
  41. map(assert, f, 10, "few");
  42. map(assert, f, 103, "few");
  43. map(assert, f, 105, "few");
  44. map(assert, f, 110, "few");
  45. map(assert, f, 203, "few");
  46. map(assert, f, 205, "few");
  47. map(assert, f, 210, "few");
  48. map(assert, f, 11, "many");
  49. map(assert, f, 50, "many");
  50. map(assert, f, 99, "many");
  51. map(assert, f, 111, "many");
  52. map(assert, f, 150, "many");
  53. map(assert, f, 199, "many");
  54. map(assert, f, 100, "other");
  55. map(assert, f, 101, "other");
  56. map(assert, f, 102, "other");
  57. map(assert, f, 200, "other");
  58. map(assert, f, 201, "other");
  59. map(assert, f, 202, "other");
  60. }
  61. exports.testJapanese = function(assert) {
  62. // Japanese doesn't have plural forms.
  63. let f = getRulesForLocale("ja");
  64. map(assert, f, -1, "other");
  65. map(assert, f, 0, "other");
  66. map(assert, f, 1, "other");
  67. map(assert, f, 1.5, "other");
  68. map(assert, f, 2, "other");
  69. map(assert, f, 100, "other");
  70. }
  71. require('sdk/test').run(exports);