1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/test/test-l10n-plural-rules.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const { getRulesForLocale } = require("sdk/l10n/plural-rules"); 1.9 + 1.10 +// For more information, please visit unicode website: 1.11 +// http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 1.12 + 1.13 +function map(assert, f, n, form) { 1.14 + assert.equal(f(n), form, n + " maps to '" + form + "'"); 1.15 +} 1.16 + 1.17 +exports.testFrench = function(assert) { 1.18 + let f = getRulesForLocale("fr"); 1.19 + map(assert, f, -1, "other"); 1.20 + map(assert, f, 0, "one"); 1.21 + map(assert, f, 1, "one"); 1.22 + map(assert, f, 1.5, "one"); 1.23 + map(assert, f, 2, "other"); 1.24 + map(assert, f, 100, "other"); 1.25 +} 1.26 + 1.27 +exports.testEnglish = function(assert) { 1.28 + let f = getRulesForLocale("en"); 1.29 + map(assert, f, -1, "other"); 1.30 + map(assert, f, 0, "other"); 1.31 + map(assert, f, 1, "one"); 1.32 + map(assert, f, 1.5, "other"); 1.33 + map(assert, f, 2, "other"); 1.34 + map(assert, f, 100, "other"); 1.35 +} 1.36 + 1.37 +exports.testArabic = function(assert) { 1.38 + let f = getRulesForLocale("ar"); 1.39 + map(assert, f, -1, "other"); 1.40 + map(assert, f, 0, "zero"); 1.41 + map(assert, f, 0.5, "other"); 1.42 + 1.43 + map(assert, f, 1, "one"); 1.44 + map(assert, f, 1.5, "other"); 1.45 + 1.46 + map(assert, f, 2, "two"); 1.47 + map(assert, f, 2.5, "other"); 1.48 + 1.49 + map(assert, f, 3, "few"); 1.50 + map(assert, f, 3.5, "few"); // I'd expect it to be 'other', but the unicode.org 1.51 + // algorithm computes 'few'. 1.52 + map(assert, f, 5, "few"); 1.53 + map(assert, f, 10, "few"); 1.54 + map(assert, f, 103, "few"); 1.55 + map(assert, f, 105, "few"); 1.56 + map(assert, f, 110, "few"); 1.57 + map(assert, f, 203, "few"); 1.58 + map(assert, f, 205, "few"); 1.59 + map(assert, f, 210, "few"); 1.60 + 1.61 + map(assert, f, 11, "many"); 1.62 + map(assert, f, 50, "many"); 1.63 + map(assert, f, 99, "many"); 1.64 + map(assert, f, 111, "many"); 1.65 + map(assert, f, 150, "many"); 1.66 + map(assert, f, 199, "many"); 1.67 + 1.68 + map(assert, f, 100, "other"); 1.69 + map(assert, f, 101, "other"); 1.70 + map(assert, f, 102, "other"); 1.71 + map(assert, f, 200, "other"); 1.72 + map(assert, f, 201, "other"); 1.73 + map(assert, f, 202, "other"); 1.74 +} 1.75 + 1.76 +exports.testJapanese = function(assert) { 1.77 + // Japanese doesn't have plural forms. 1.78 + let f = getRulesForLocale("ja"); 1.79 + map(assert, f, -1, "other"); 1.80 + map(assert, f, 0, "other"); 1.81 + map(assert, f, 1, "other"); 1.82 + map(assert, f, 1.5, "other"); 1.83 + map(assert, f, 2, "other"); 1.84 + map(assert, f, 100, "other"); 1.85 +} 1.86 + 1.87 +require('sdk/test').run(exports);