addon-sdk/source/test/test-l10n-plural-rules.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 const { getRulesForLocale } = require("sdk/l10n/plural-rules");
     7 // For more information, please visit unicode website:
     8 // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
    10 function map(assert, f, n, form) {
    11   assert.equal(f(n), form, n + " maps to '" + form + "'");
    12 }
    14 exports.testFrench = function(assert) {
    15   let f = getRulesForLocale("fr");
    16   map(assert, f, -1, "other");
    17   map(assert, f, 0, "one");
    18   map(assert, f, 1, "one");
    19   map(assert, f, 1.5, "one");
    20   map(assert, f, 2, "other");
    21   map(assert, f, 100, "other");
    22 }
    24 exports.testEnglish = function(assert) {
    25   let f = getRulesForLocale("en");
    26   map(assert, f, -1, "other");
    27   map(assert, f, 0, "other");
    28   map(assert, f, 1, "one");
    29   map(assert, f, 1.5, "other");
    30   map(assert, f, 2, "other");
    31   map(assert, f, 100, "other");
    32 }
    34 exports.testArabic = function(assert) {
    35   let f = getRulesForLocale("ar");
    36   map(assert, f, -1, "other");
    37   map(assert, f, 0, "zero");
    38   map(assert, f, 0.5, "other");
    40   map(assert, f, 1, "one");
    41   map(assert, f, 1.5, "other");
    43   map(assert, f, 2, "two");
    44   map(assert, f, 2.5, "other");
    46   map(assert, f, 3, "few");
    47   map(assert, f, 3.5, "few"); // I'd expect it to be 'other', but the unicode.org
    48                             // algorithm computes 'few'.
    49   map(assert, f, 5, "few");
    50   map(assert, f, 10, "few");
    51   map(assert, f, 103, "few");
    52   map(assert, f, 105, "few");
    53   map(assert, f, 110, "few");
    54   map(assert, f, 203, "few");
    55   map(assert, f, 205, "few");
    56   map(assert, f, 210, "few");
    58   map(assert, f, 11, "many");
    59   map(assert, f, 50, "many");
    60   map(assert, f, 99, "many");
    61   map(assert, f, 111, "many");
    62   map(assert, f, 150, "many");
    63   map(assert, f, 199, "many");
    65   map(assert, f, 100, "other");
    66   map(assert, f, 101, "other");
    67   map(assert, f, 102, "other");
    68   map(assert, f, 200, "other");
    69   map(assert, f, 201, "other");
    70   map(assert, f, 202, "other");
    71 }
    73 exports.testJapanese = function(assert) {
    74   // Japanese doesn't have plural forms.
    75   let f = getRulesForLocale("ja");
    76   map(assert, f, -1, "other");
    77   map(assert, f, 0, "other");
    78   map(assert, f, 1, "other");
    79   map(assert, f, 1.5, "other");
    80   map(assert, f, 2, "other");
    81   map(assert, f, 100, "other");
    82 }
    84 require('sdk/test').run(exports);

mercurial