+ * + * Any one or two of the language, script, or region parts may be left unspecified, + * and the other one or two parts will be filled in automatically. If this + * class has no information about the given locale, then the locale of this + * locale matcher instance is returned unchanged.
+ * + * This method returns the same information as getLikelyLocale but with the very common + * parts left out. + * + * @returns {Locale} the most likely "minimal" completion of the partial locale given + * to the constructor of this locale matcher instance where the commonly understood + * parts are left out. + */ + getLikelyLocaleMinimal: function() { + var fullLocale = this._getLikelyLocale(this.locale); + var langLocale = this._getLikelyLocale(new Locale(fullLocale.language)); + return fullLocale.script === langLocale.script && !multiScriptLanguages[fullLocale.language] ? + new Locale(fullLocale.language, undefined, fullLocale.region) : + fullLocale; + }, + /** * Return the degree that the given locale matches the current locale of this * matcher. This method returns an integer from 0 to 100. A value of 100 is diff --git a/js/lib/NormString.js b/js/lib/NormString.js index 4e144921e8..3051c6dc59 100644 --- a/js/lib/NormString.js +++ b/js/lib/NormString.js @@ -1,7 +1,7 @@ /* * NormString.js - ilib normalized string subclass definition * - * Copyright © 2013-2015, 2018, JEDLSoft + * Copyright © 2013-2015, 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -141,7 +141,7 @@ NormString.init = function(options) { if (files.length) { //console.log("loading files " + JSON.stringify(files)); - Utils._callLoadData(files, sync, loadParams, function(arr) { + Utils._callLoadData(files, sync, loadParams, undefined, function(arr) { for (var i = 0; i < arr.length; i++) { if (typeof(arr[i]) !== 'undefined') { ilib.extend(ilib.data.norm[toLoad[i]], arr[i]); diff --git a/js/lib/PhoneLocale.js b/js/lib/PhoneLocale.js index a8679afc02..d7d515abc7 100644 --- a/js/lib/PhoneLocale.js +++ b/js/lib/PhoneLocale.js @@ -180,54 +180,105 @@ PhoneLocale.prototype._mapAreatoRegion = function(cc, area) { PhoneLocale.prototype._normPhoneReg = function(region) { var norm; + /* + * Country list has been updated from metadata.json fro, libphonenumber-js library v1.7.20 + * and Modified some countries based on Wikipedia + */ + // Map all NANP regions to the right region, so that they get parsed using the // correct state table switch (region) { case "US": // usa - case "CA": // canada case "AG": // antigua and barbuda - case "BS": // bahamas + case "AI": // anguilla + case "AS": // American Samoa case "BB": // barbados + case "BM": // bermuda + case "BS": // bahamas + case "CA": // canada case "DM": // dominica case "DO": // dominican republic case "GD": // grenada + case "GU": // Guam case "JM": // jamaica case "KN": // st. kitts and nevis - case "LC": // st. lucia - case "VC": // st. vincent and the grenadines - case "TT": // trinidad and tobago - case "AI": // anguilla - case "BM": // bermuda - case "VG": // british virgin islands case "KY": // cayman islands + case "LC": // st. lucia + case "MP": // Northern Mariana Islands case "MS": // montserrat + case "PR": // Puerto Rico + case "SX": // Sint Maarten case "TC": // turks and caicos - case "AS": // American Samoa + case "TT": // trinidad and tobago + case "VC": // st. vincent and the grenadines + case "VG": // british virgin islands case "VI": // Virgin Islands, U.S. - case "PR": // Puerto Rico - case "MP": // Northern Mariana Islands - case "T:": // East Timor - case "GU": // Guam norm = "US"; break; - // these all use the Italian dialling plan - case "IT": // italy - case "SM": // san marino - case "VA": // vatican city - norm = "IT"; - break; - - // all the French dependencies are on the French dialling plan + /* all the French dependencies are on the French dialling plan + * Update manually following Wikipedia information + * https://en.wikipedia.org/wiki/Telephone_numbers_in_France#Others + */ case "FR": // france case "GF": // french guiana case "MQ": // martinique case "GP": // guadeloupe, case "BL": // saint barthélemy case "MF": // saint martin - case "RE": // réunion, mayotte + case "RE": // réunion + case "YT": // mayotte norm = "FR"; break; + + // these all use the Italian dialling plan + case "IT": // italy + case "SM": // san marino + case "VA": // vatican city // Update manually following Wikipedia information + norm = "IT"; + break; + + // all the UK dependencies are on the UK dialling plan + case "GB": // United Kingdom + case "GG": // Guernsey + case "IM": // Isle of Man + case "JE": // Jersey + norm = "GB"; + break; + case "RU": // Russia + case "KZ": // Kazakhstan + norm = "RU"; + break; + case "NO": // Norway + case "SJ": // Svalbard and Jan Mayen + norm = "NO"; + break; + case "AU": // Australia + case "CC": // Cocos (Keeling) Islands + case "CX": // Christmas Island + norm = "AU"; + break; + case "MA": // Morocco + case "EH": // Western Sahara + norm = "MA"; + break; + case "SH": // Saint Helena + case "TA": // ? + norm = "SH"; + break; + case "FI": // Finland + case "AX": // Aland Islands + norm = "FI"; + break; + case "GP": // Guadeloupe + case "BL": // Saint-Barthélemy + case "MF": // Saint Martin (French part) + norm = "GP"; + break; + case "CW": // Curaçao + case "BQ": // Caribbean Netherlands + norm = "CW"; + break; default: norm = region; break; diff --git a/js/lib/PhoneNumber.js b/js/lib/PhoneNumber.js index 3ff13eb91d..3a1ada67f6 100644 --- a/js/lib/PhoneNumber.js +++ b/js/lib/PhoneNumber.js @@ -1355,7 +1355,7 @@ PhoneNumber.prototype = { onLoad: ilib.bind(this, function (data) { tempRegion = (data.countryCode && data.locale._mapCCtoRegion(data.countryCode)); - if (tempRegion && tempRegion !== "unknown" && tempRegion !== "SG") { + if (tempRegion && tempRegion !== "XX" && tempRegion !== "SG") { // only use it if it is a recognized country code. Singapore (SG) is a special case. norm = data; destinationLocale = data.destinationLocale; diff --git a/js/lib/ResBundle.js b/js/lib/ResBundle.js index d542085088..be4e814f62 100644 --- a/js/lib/ResBundle.js +++ b/js/lib/ResBundle.js @@ -1,7 +1,7 @@ /* * ResBundle.js - Resource bundle definition * - * Copyright © 2012-2016, 2018, JEDLSoft + * Copyright © 2012-2016, 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,6 +71,11 @@ var IString = require("./IString.js"); * The default behaviour is the same as before, which is to return the source string * unchanged. * + *
* * Suggested implementations of this method might load files diff --git a/js/package.json.template b/js/package.json.template index 7b9656395f..d2e74646b1 100644 --- a/js/package.json.template +++ b/js/package.json.template @@ -20,12 +20,6 @@ "bugs": "https://github.com/iLib-js/iLib/issues", "email": "marketing@translationcircle.com", "license": "Apache-2.0", - "licenses": [ - { - "type": "apache2", - "url": "http://www.apache.org/licenses/LICENSE-2.0" - } - ], "author": { "name": "Edwin Hoogerbeets", "web": "http://www.translationcircle.com/", @@ -48,8 +42,9 @@ "files": [ "lib", "locale", + "index.js", "README.md", - "index.js" + "LICENSE" ], "repository": { "type": "git", diff --git a/js/test/phone/testnormalize.js b/js/test/phone/testnormalize.js index cee7ca854d..ac08941634 100644 --- a/js/test/phone/testnormalize.js +++ b/js/test/phone/testnormalize.js @@ -971,7 +971,7 @@ module.exports.normalize = { defaultAreaCode: "650", // phone is a US phone assistedDialing: true }; - var expectedString = "4259876543233"; // don't touch things with an invalid country code. ie. the reparse with a + didn't work. + var expectedString = "4259876543233"; test.equal(left.normalize(hints), expectedString); // 'en-US' test.done(); diff --git a/js/test/phone/testphonefmt_KR.js b/js/test/phone/testphonefmt_KR.js index 11ee5735a9..c6afc1a088 100644 --- a/js/test/phone/testphonefmt_KR.js +++ b/js/test/phone/testphonefmt_KR.js @@ -573,6 +573,22 @@ module.exports.phonefmt_KR = { test.equal(formatted, expected); test.done(); }, + testFormatKRStyle0Whole11: function(test) { + test.expect(1); + var formatted; + var parsed = new PhoneNumber({ + trunkAccess: "0", + areaCode: "33", + subscriberNumber: "123456789" + }); + var expected = "033-1234-56789"; + + var fmt = new PhoneFmt({locale: "ko-KR", style: "default"}); + formatted = fmt.format(parsed, {partial: false}); + + test.equal(formatted, expected); + test.done(); + }, testFormatKRStyle1Partial0: function(test) { test.expect(1); diff --git a/js/test/phone/testphonegeo.js b/js/test/phone/testphonegeo.js index 05af78d725..57f842e5be 100644 --- a/js/test/phone/testphonegeo.js +++ b/js/test/phone/testphonegeo.js @@ -561,7 +561,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "United Kingdom", - ln: "United Kingdom, Guernsey, Isle of Man, Jersey", + ln: "United Kingdom, Guernsey, Isle of Man, or Jersey", code: "GB" }, area: { @@ -588,7 +588,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "United Kingdom", - ln: "United Kingdom, Guernsey, Isle of Man, Jersey", + ln: "United Kingdom, Guernsey, Isle of Man, or Jersey", code: "GB" }, area: { @@ -615,7 +615,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "United Kingdom", - ln: "United Kingdom, Guernsey, Isle of Man, Jersey", + ln: "United Kingdom, Guernsey, Isle of Man, or Jersey", code: "GB" }, area: { @@ -642,7 +642,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "United Kingdom", - ln: "United Kingdom, Guernsey, Isle of Man, Jersey", + ln: "United Kingdom, Guernsey, Isle of Man, or Jersey", code: "GB" }, area: { @@ -669,7 +669,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "United Kingdom", - ln: "United Kingdom, Guernsey, Isle of Man, Jersey", + ln: "United Kingdom, Guernsey, Isle of Man, or Jersey", code: "GB" } }; @@ -880,7 +880,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "Italia", - ln: "Italia, Città del Vaticano", + ln: "Italy or Vatican City", code: "IT" }, area: { @@ -908,7 +908,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "Italia", - ln: "Italia, Città del Vaticano", + ln: "Italy or Vatican City", code: "IT" }, area: { @@ -935,7 +935,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "Italia", - ln: "Italia, Città del Vaticano", + ln: "Italy or Vatican City", code: "IT" }, area: { @@ -1037,7 +1037,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "Australia", - ln: "Australia, Isla Christmas, Islas Cocos", + ln: "Australia, Cocos (Keeling) Islands, or Christmas Island", code: "AU" }, area: { @@ -1064,7 +1064,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "Australia", - ln: "Australia, Isla Christmas, Islas Cocos", + ln: "Australia, Cocos (Keeling) Islands, or Christmas Island", code: "AU" }, area: { @@ -1091,7 +1091,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "Australia", - ln: "Australia, Isla Christmas, Islas Cocos", + ln: "Australia, Cocos (Keeling) Islands, or Christmas Island", code: "AU" }, area: { @@ -1118,7 +1118,7 @@ module.exports.phonegeo = { var expected = { country: { sn: "Australia", - ln: "Australia, Isla Christmas, Islas Cocos", + ln: "Australia, Cocos (Keeling) Islands, or Christmas Island", code: "AU" }, area: { @@ -2001,8 +2001,8 @@ module.exports.phonegeo = { var parsed = new PhoneNumber("+852 2543 2102"); var expected = { country: { - sn: "Hong Kong", - ln: "Hong Kong", + sn: "Hong Kong SAR China", + ln: "Hong Kong SAR China", code: "HK" } }; @@ -2022,8 +2022,8 @@ module.exports.phonegeo = { var parsed = new PhoneNumber("2543 2102", {locale: "en-HK"}); var expected = { country: { - sn: "Hong Kong", - ln: "Hong Kong", + sn: "Hong Kong SAR China", + ln: "Hong Kong SAR China", code: "HK" } }; @@ -2043,8 +2043,8 @@ module.exports.phonegeo = { var parsed = new PhoneNumber("6543 2102", {locale: "en-HK"}); var expected = { country: { - sn: "Hong Kong", - ln: "Hong Kong", + sn: "Hong Kong SAR China", + ln: "Hong Kong SAR China", code: "HK" } }; @@ -2099,4 +2099,4 @@ module.exports.phonegeo = { test.done(); } -}; \ No newline at end of file +}; diff --git a/js/test/phone/testphonegeo_RU.js b/js/test/phone/testphonegeo_RU.js index 150f6a5caf..e2bd06bc94 100644 --- a/js/test/phone/testphonegeo_RU.js +++ b/js/test/phone/testphonegeo_RU.js @@ -39,7 +39,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" } }; @@ -60,7 +60,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" } }; @@ -81,7 +81,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -107,7 +107,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -133,7 +133,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -159,7 +159,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -185,7 +185,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -211,7 +211,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -237,7 +237,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russie", - ln: "Russie, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -263,7 +263,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { @@ -289,7 +289,7 @@ module.exports.phonegeo_RU = { var expected = { country: { sn: "Russia", - ln: "Russia, Kazakhstan", + ln: "Russia or Kazakhstan", code: "RU" }, area: { diff --git a/js/test/root/resources/ja/basetest.json b/js/test/root/resources/ja/basetest.json new file mode 100644 index 0000000000..2049bb2aa7 --- /dev/null +++ b/js/test/root/resources/ja/basetest.json @@ -0,0 +1,6 @@ +{ + "hello" : "こんにちは", + "Hello from {country}": "{country}からこんにちは", + "Hello from {city}": "{city}からこんにちは", + "Greetings from {city} in {country}": "{city}と{country}からこんにちは" +} diff --git a/js/test/root/resources2/ja/basetest.json b/js/test/root/resources2/ja/basetest.json new file mode 100644 index 0000000000..72622f469c --- /dev/null +++ b/js/test/root/resources2/ja/basetest.json @@ -0,0 +1,6 @@ +{ + "hello" : "こんにちは2", + "Hello from {country}": "{country}からこんにちは2", + "Hello from {city}": "{city}からこんにちは2", + "Greetings from {city} in {country}": "{city}と{country}からこんにちは2" +} diff --git a/js/test/root/testglobal.js b/js/test/root/testglobal.js index 609887180a..3e528a8003 100644 --- a/js/test/root/testglobal.js +++ b/js/test/root/testglobal.js @@ -74,7 +74,7 @@ module.exports.testglobal = { return; } test.expect(1); - test.equal(ilib.getVersion().substring(0,4), "14.3"); + test.equal(ilib.getVersion().substring(0,4), "14.4"); test.done(); }, diff --git a/js/test/root/testlocalematch.js b/js/test/root/testlocalematch.js index bee14215bd..5389ef9b5a 100644 --- a/js/test/root/testlocalematch.js +++ b/js/test/root/testlocalematch.js @@ -1,785 +1,1713 @@ -/* - * testlocalematch.js - test the locale matcher object - * - * Copyright © 2012-2015,2017, JEDLSoft - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -if (typeof(LocaleMatcher) === "undefined") { - var LocaleMatcher = require("../../lib/LocaleMatcher.js"); -} - -if (typeof(ilib) === "undefined") { - var ilib = require("../../lib/ilib.js"); -} - -module.exports.testlocalematch = { - setUp: function(callback) { - ilib.clearCache(); - callback(); - }, - - testLocaleMatcherConstructor: function(test) { - test.expect(1); - var loc = new LocaleMatcher(); - - test.ok(loc !== null); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguage1: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "uz" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "uz-Latn-UZ"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguage2: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "alt" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "alt-Cyrl-RU"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguage3: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "gv" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "gv-Latn-IM"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguage4: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "ia" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "ia-Latn-FR"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguage5: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "sd" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "sd-Arab-PK"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByRegion: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "UZ" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "uz-Latn-UZ"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByScript: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "Arab" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "ar-Arab-EG"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageAndScript1: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "pa-Arab" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "pa-Arab-PK"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageAndScript2: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "Cyrl-BY" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "be-Cyrl-BY"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageAndScriptUnknownCombo: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "Cyrl-PL" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "pl-Latn-PL"); // default to country's locale - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageAndScriptOriya: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "or-Orya" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "or-Orya-IN"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByScriptOriya: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "or" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "or-Orya-IN"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageOriya: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "Orya" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "or-Orya-IN"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageAndRegion: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "uz-AF" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "uz-Arab-AF"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByRegionAndScript: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "MA-Latn" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "fr-Latn-MA"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleAlreadySpecified: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "en-CA-Latn" // non-standard order of components - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "en-Latn-CA"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageMissing: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "zxx" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "en-Latn-US"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLanguageAndRegionMissing: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "en-GB" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "en-Latn-GB"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeAF: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "af-ZA" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "af-Latn-ZA"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleCodeAF: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "af" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "af-Latn-ZA"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeAF: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "af-NA" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "af-Latn-NA"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeET: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "am-ET" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "am-Ethi-ET"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleCodeET: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "am" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "am-Ethi-ET"); - test.done(); - }, - /*Hausa */ - testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeHANG: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "ha" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "ha-Latn-NG"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleCodeHANG: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "ha-NG" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "ha-Latn-NG"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleCodeHANE: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "ha-NE" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "ha-Latn-NE"); - test.done(); - }, - - testLocaleMatcherGetLikelyLocaleByLocaleCodeGH: function(test) { - test.expect(3); - var lm = new LocaleMatcher({ - locale: "ha-GH" - }); - test.ok(typeof(lm) !== "undefined"); - var locale = lm.getLikelyLocale(); - test.ok(typeof(locale) !== "undefined"); - test.equal(locale.getSpec(), "ha-Latn-NG"); - test.done(); - }, - - testLocaleMatcherMatchExactFullLocale: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "zh-Hans-CN" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("zh-Hans-CN"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactLangRegion: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-US" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("en-US"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactLang: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("en"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactLangScript: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "zh-Hans" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("zh-Hans"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactRegion: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "US" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("US"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactDefaultScript: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "zh-Hans-CN" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("zh-CN"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactDefaultScript: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-Latn-US" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("en-US"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactDefaultRegion: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "ja-JP" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("ja"), 100); - - test.done(); - }, - - testLocaleMatcherMatchExactDefaultRegionReverse: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "ja" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("ja-JP"), 100); - - test.done(); - }, - - testLocaleMatcherMatchFullLocaleDifferentRegion: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "zh-Hans-CN" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("zh-Hans-SG"), 78); - - test.done(); - }, - - testLocaleMatcherMatchFullLocaleDifferentScript: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "zh-Hans-HK" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("zh-Hant-HK"), 80); - - test.done(); - }, - - testLocaleMatcherMatchFullLocaleDifferentLanguage: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-Latn-US" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("de-Latn-US"), 50); - - test.done(); - }, - - testLocaleMatcherMatchFullLocaleDifferentVariant: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-US-VARIANT" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("en-US"), 95); - - test.done(); - }, - - testLocaleMatcherMatchMutuallyIntelligibleLanguages: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "da-DK" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("no-NO"), 53); - - test.done(); - }, - - testLocaleMatcherMatchMutuallyIntelligibleLanguagesAsymetric: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "no-NO" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("da-DK"), 63); - - test.done(); - }, - - - testLocaleMatcherGetMacroLanguageZH: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "zh-Hans-CN" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.getMacroLanguage(), "zh"); - - test.done(); - }, - - testLocaleMatcherGetMacroLanguageCMN: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "cmn-Hans-CN" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.getMacroLanguage(), "zh"); - - test.done(); - }, - - testLocaleMatcherGetMacroLanguageNO: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "nn-NO" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.getMacroLanguage(), "no"); - - test.done(); - }, - - testLocaleMatcherGetMacroLanguageNoChange: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-US" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.getMacroLanguage(), "en"); - - test.done(); - }, - - testLocaleMatcherMatchMacroLanguagesNO: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "nn-NO" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("no-NO"), 95); - - test.done(); - }, - - testLocaleMatcherMatchMacroLanguagesZH: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "zh-Hans-CN" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("cmn-Hans-CN"), 95); - - test.done(); - }, - - testLocaleMatcherMatchMacroLanguagesZH2: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "yue-Hans-CN" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.match("cmn-Hans-CN"), 95); - - test.done(); - }, - - testLocaleMatcherGetMacroLanguageNO: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "nn-NO" - }); - test.ok(typeof(lm) !== "undefined"); - - test.equal(lm.getMacroLanguage(), "no"); - - test.done(); - }, - - testLocaleMatcherGetRegionContainmentNO: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "nn-NO" - }); - test.ok(typeof(lm) !== "undefined"); - - // northern europe, europe, world - test.equalIgnoringOrder(lm.getRegionContainment(), ["154", "150", "001"]); - - test.done(); - }, - - testLocaleMatcherGetRegionContainmentDA: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "da-DK" - }); - test.ok(typeof(lm) !== "undefined"); - - // northern europe, european union, europe, world - test.equalIgnoringOrder(lm.getRegionContainment(), ["154", "EU", "150", "001"]); - - test.done(); - }, - - testLocaleMatcherGetRegionContainmentUS: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-US" - }); - test.ok(typeof(lm) !== "undefined"); - - // northern north america, north america, world - test.equalIgnoringOrder(lm.getRegionContainment(), ["021", "019", "003", "001"]); - - test.done(); - }, - - testLocaleMatcherGetRegionContainmentUsingMostLikelyRegion: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "ja" // most likely region is "JP" for Japan - }); - test.ok(typeof(lm) !== "undefined"); - - // western asia, asia, world - test.equalIgnoringOrder(lm.getRegionContainment(), ["001","030","142"]); - - test.done(); - }, - - testLocaleMatcherSmallestCommonRegionUSCA: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-US" - }); - test.ok(typeof(lm) !== "undefined"); - - // northern north america - test.equal(lm.smallestCommonRegion("CA"), "021"); - - test.done(); - }, - - testLocaleMatcherSmallestCommonRegionUSJM: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-US" - }); - test.ok(typeof(lm) !== "undefined"); - - // north america - test.equal(lm.smallestCommonRegion("JM"), "003"); - - test.done(); - }, - - testLocaleMatcherSmallestCommonRegionUSGB: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "en-US" - }); - test.ok(typeof(lm) !== "undefined"); - - // world - test.equal(lm.smallestCommonRegion("GB"), "UN"); - - test.done(); - }, - - testLocaleMatcherSmallestCommonRegionNLDK: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "nl-NL" - }); - test.ok(typeof(lm) !== "undefined"); - - // world - test.equal(lm.smallestCommonRegion("DK"), "150"); - - test.done(); - }, - - testLocaleMatcherSmallestCommonRegionUndefined: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "nl-NL" - }); - test.ok(typeof(lm) !== "undefined"); - - // world - test.equal(lm.smallestCommonRegion(undefined), "001"); - - test.done(); - }, - - testLocaleMatcherSmallestCommonRegionWithMostLikelyRegions: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "ja" - }); - test.ok(typeof(lm) !== "undefined"); - - // eastern asia - test.equal(lm.smallestCommonRegion("zh"), "030"); - - test.done(); - }, - - testLocaleMatcherSmallestCommonRegionWithMostLikelyRegions2: function(test) { - test.expect(2); - var lm = new LocaleMatcher({ - locale: "hi" - }); - test.ok(typeof(lm) !== "undefined"); - - // asia - test.equal(lm.smallestCommonRegion("ja"), "142"); - - test.done(); - } -}; +/* + * testlocalematch.js - test the locale matcher object + * + * Copyright © 2012-2015,2017,2019 JEDLSoft + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +if (typeof(LocaleMatcher) === "undefined") { + var LocaleMatcher = require("../../lib/LocaleMatcher.js"); +} + +if (typeof(ilib) === "undefined") { + var ilib = require("../../lib/ilib.js"); +} + +module.exports.testlocalematch = { + setUp: function(callback) { + ilib.clearCache(); + callback(); + }, + + testLocaleMatcherConstructor: function(test) { + test.expect(1); + var loc = new LocaleMatcher(); + + test.ok(loc !== null); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguage1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "uz" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "uz-Latn-UZ"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguage2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "alt" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "alt-Cyrl-RU"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguage3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "gv" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "gv-Latn-IM"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguage4: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ia" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ia-Latn-001"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguage5: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "sd" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "sd-Arab-PK"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByRegion: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "UZ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "uz-Latn-UZ"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByScript1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Arab" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ar-Arab-EG"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByScript2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Aran" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fa-Aran-IR"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageAndScript1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "pa-Arab" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "pa-Arab-PK"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageAndScript2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Cyrl-BY" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "be-Cyrl-BY"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageAndScript3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ar-Hebr" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ar-Hebr-IL"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageAndScriptUnknownCombo: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Cyrl-PL" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "pl-Latn-PL"); // default to country's locale + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageAndScriptOriya: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "or-Orya" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "or-Orya-IN"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageOriya: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "or" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "or-Orya-IN"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByScriptOriya: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Orya" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "or-Orya-IN"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageAndRegion: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "uz-AF" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "uz-Arab-AF"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByRegionAndScript: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "MA-Latn" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-MA"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleAlreadySpecified: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-CA-Latn" // non-standard order of components + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-CA"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageMissing: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "zxx" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "zxx-Latn-XX"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLanguageAndRegionMissing: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-GB" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-GB"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeAF: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "af-ZA" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "af-Latn-ZA"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleCodeAF: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "af" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "af-Latn-ZA"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeAF: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "af-NA" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "af-Latn-NA"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeET: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "am-ET" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "am-Ethi-ET"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleCodeET: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "am" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "am-Ethi-ET"); + test.done(); + }, + /*Hausa */ + testLocaleMatcherGetLikelyLocaleByLocaleRegionCodeHANG: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ha" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ha-Latn-NG"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleCodeHANG: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ha-NG" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ha-Latn-NG"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleCodeHANE: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ha-NE" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ha-Latn-NE"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleCodeGH: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ha-GH" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ha-Latn-NG"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-CA" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-CA"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleCode2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ar-DJ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ar-Arab-DJ"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleByLocaleCode3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "bs-BA" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "bs-Latn-BA"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode4: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "de-AT" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "de-Latn-AT"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode5: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "de-LU" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "de-Latn-LU"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode6: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "el-GR" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "el-Grek-GR"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode7: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-AM" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-AM"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode8: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-AZ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-AZ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode9: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-CN" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-CN"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode10: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-ET" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-ET"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode11: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-GE" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-GE"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode12: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-IS" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-IS"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode13: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-JP" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-JP"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode14: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-LK" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-LK"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode15: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-MM" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-MM"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode16: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-MX" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-MX"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode17: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-MY" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-MY"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode18: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-PH" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-PH"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode19: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-PK" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-PK"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode20: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-PR" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-PR"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode21: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-RW" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-RW"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode22: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-SD" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-SD"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode23: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-TW" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-TW"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode24: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "uz-UZ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "uz-Latn-UZ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode25: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-TZ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Latn-TZ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode26: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "sv-SE" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "sv-Latn-SE"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode27: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "es-CA" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "es-Latn-CA"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode28: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "es-PH" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "es-Latn-PH"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode29: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "es-US" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "es-Latn-US"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode30: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "sv-FI" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "sv-Latn-FI"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode31: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "et-EE" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "et-Latn-EE"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode32: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-BE" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-BE"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode33: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-RW" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-RW"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode34: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-CH" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-CH"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode35: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-GQ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-GQ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode36: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-DZ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-DZ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode37: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-LB" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-LB"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode38: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr-DJ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-Latn-DJ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode39: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "kk-KZ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "kk-Cyrl-KZ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode40: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ha-NG" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ha-Latn-NG"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode41: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "it-CH" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "it-Latn-CH"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode42: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ms-MY" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ms-Latn-MY"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode43: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ms-SG" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ms-Latn-SG"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode44: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "nl-BE" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "nl-Latn-BE"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode45: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "pa-IN" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "pa-Guru-IN"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode46: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "pt-GQ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "pt-Latn-GQ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode47: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ru-BY" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ru-Cyrl-BY"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode48: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ru-GE" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ru-Cyrl-GE"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode49: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ru-KG" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ru-Cyrl-KG"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode50: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ru-UA" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ru-Cyrl-UA"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode51: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "sq-ME" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "sq-Latn-ME"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode52: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "tr-AM" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "tr-Latn-AM"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode53: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "tr-AZ" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "tr-Latn-AZ"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode54: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "tr-CY" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "tr-Latn-CY"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode55: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "uk-UA" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "uk-Cyrl-UA"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode56: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ur-IN" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ur-Arab-IN"); + test.done(); + }, + testLocaleMatcherGetLikelyLocaleByLocaleCode57: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ur-PK" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocale(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ur-Arab-PK"); + test.done(); + }, + testLocaleMatcherMatchExactFullLocale: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "zh-Hans-CN" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("zh-Hans-CN"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactLangRegion: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-US" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("en-US"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactLang: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("en"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactLangScript: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "zh-Hans" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("zh-Hans"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactRegion: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "US" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("US"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactDefaultScript: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "zh-Hans-CN" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("zh-CN"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactDefaultScript: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-Latn-US" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("en-US"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactDefaultRegion: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "ja-JP" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("ja"), 100); + + test.done(); + }, + + testLocaleMatcherMatchExactDefaultRegionReverse: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "ja" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("ja-JP"), 100); + + test.done(); + }, + + testLocaleMatcherMatchFullLocaleDifferentRegion: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "zh-Hans-CN" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("zh-Hans-SG"), 78); + + test.done(); + }, + + testLocaleMatcherMatchFullLocaleDifferentScript: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "zh-Hans-HK" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("zh-Hant-HK"), 80); + + test.done(); + }, + + testLocaleMatcherMatchFullLocaleDifferentLanguage: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-Latn-US" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("de-Latn-US"), 50); + + test.done(); + }, + + testLocaleMatcherMatchFullLocaleDifferentVariant: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-US-VARIANT" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("en-US"), 95); + + test.done(); + }, + + testLocaleMatcherMatchMutuallyIntelligibleLanguages: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "da-DK" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("no-NO"), 53); + + test.done(); + }, + + testLocaleMatcherMatchMutuallyIntelligibleLanguagesAsymetric: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "no-NO" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("da-DK"), 63); + + test.done(); + }, + + + testLocaleMatcherGetMacroLanguageZH: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "zh-Hans-CN" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.getMacroLanguage(), "zh"); + + test.done(); + }, + + testLocaleMatcherGetMacroLanguageCMN: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "cmn-Hans-CN" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.getMacroLanguage(), "zh"); + + test.done(); + }, + + testLocaleMatcherGetMacroLanguageNO: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "nn-NO" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.getMacroLanguage(), "no"); + + test.done(); + }, + + testLocaleMatcherGetMacroLanguageNoChange: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-US" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.getMacroLanguage(), "en"); + + test.done(); + }, + + testLocaleMatcherMatchMacroLanguagesNO: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "nn-NO" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("no-NO"), 95); + + test.done(); + }, + + testLocaleMatcherMatchMacroLanguagesZH: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "zh-Hans-CN" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("cmn-Hans-CN"), 95); + + test.done(); + }, + + testLocaleMatcherMatchMacroLanguagesZH2: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "yue-Hans-CN" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.match("cmn-Hans-CN"), 95); + + test.done(); + }, + + testLocaleMatcherGetMacroLanguageNO: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "nn-NO" + }); + test.ok(typeof(lm) !== "undefined"); + + test.equal(lm.getMacroLanguage(), "no"); + + test.done(); + }, + + testLocaleMatcherGetRegionContainmentNO: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "nn-NO" + }); + test.ok(typeof(lm) !== "undefined"); + + // northern europe, europe, world + test.equalIgnoringOrder(lm.getRegionContainment(), ["154", "150", "001"]); + + test.done(); + }, + + testLocaleMatcherGetRegionContainmentDA: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "da-DK" + }); + test.ok(typeof(lm) !== "undefined"); + + // northern europe, european union, europe, world + test.equalIgnoringOrder(lm.getRegionContainment(), ["154", "EU", "150", "001"]); + + test.done(); + }, + + testLocaleMatcherGetRegionContainmentUS: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-US" + }); + test.ok(typeof(lm) !== "undefined"); + + // northern north america, north america, world + test.equalIgnoringOrder(lm.getRegionContainment(), ["021", "019", "003", "001"]); + + test.done(); + }, + + testLocaleMatcherGetRegionContainmentUsingMostLikelyRegion: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "ja" // most likely region is "JP" for Japan + }); + test.ok(typeof(lm) !== "undefined"); + + // western asia, asia, world + test.equalIgnoringOrder(lm.getRegionContainment(), ["001","030","142"]); + + test.done(); + }, + + testLocaleMatcherSmallestCommonRegionUSCA: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-US" + }); + test.ok(typeof(lm) !== "undefined"); + + // northern north america + test.equal(lm.smallestCommonRegion("CA"), "021"); + + test.done(); + }, + + testLocaleMatcherSmallestCommonRegionUSJM: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-US" + }); + test.ok(typeof(lm) !== "undefined"); + + // north america + test.equal(lm.smallestCommonRegion("JM"), "003"); + + test.done(); + }, + + testLocaleMatcherSmallestCommonRegionUSGB: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "en-US" + }); + test.ok(typeof(lm) !== "undefined"); + + // world + test.equal(lm.smallestCommonRegion("GB"), "UN"); + + test.done(); + }, + + testLocaleMatcherSmallestCommonRegionNLDK: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "nl-NL" + }); + test.ok(typeof(lm) !== "undefined"); + + // world + test.equal(lm.smallestCommonRegion("DK"), "150"); + + test.done(); + }, + + testLocaleMatcherSmallestCommonRegionUndefined: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "nl-NL" + }); + test.ok(typeof(lm) !== "undefined"); + + // world + test.equal(lm.smallestCommonRegion(undefined), "001"); + + test.done(); + }, + + testLocaleMatcherSmallestCommonRegionWithMostLikelyRegions: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "ja" + }); + test.ok(typeof(lm) !== "undefined"); + + // eastern asia + test.equal(lm.smallestCommonRegion("zh"), "030"); + + test.done(); + }, + + testLocaleMatcherSmallestCommonRegionWithMostLikelyRegions2: function(test) { + test.expect(2); + var lm = new LocaleMatcher({ + locale: "hi" + }); + test.ok(typeof(lm) !== "undefined"); + + // asia + test.equal(lm.smallestCommonRegion("ja"), "142"); + + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalByLanguage1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-US"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalByLanguage2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "fr" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fr-FR"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalByLanguage3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ja" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ja-JP"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalUzbek: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "uz" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "uz-Latn-UZ"); // Uzbek always uses the script + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalChinese: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "zh" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "zh-Hans-CN"); // Chinese always uses the script + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalKazakh: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "kk" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "kk-Cyrl-KZ"); // Kazakh always uses the script + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultScriptForLanguage: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "sv" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "sv-SE"); // default is Latin + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultScriptForCountry: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "FI" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "fi-FI"); // default is Latin + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalNonDefaultScriptForLanguage1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "sr-ME" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "sr-Latn-ME"); // default is Cyrillic, so we have to put "Latn" explicitly + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalNonDefaultScriptForLanguage2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "sr-Latn-RS" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "sr-Latn-RS"); // default is Cyrillic, so we have to put "Latn" explicitly + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalNonDefaultScriptForLanguage3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "zh-TW" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "zh-Hant-TW"); // Chinese always uses the script + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultScriptForCountry1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "US" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-US"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultScriptForCountry2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "HK" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "zh-Hant-HK"); // Chinese always uses the script + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultScriptForCountry3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "RU" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ru-RU"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultLocaleForScript1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Latn" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-US"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultLocaleForScript2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Jpan" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ja-JP"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultLocaleForScript3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Hans" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "zh-Hans-CN"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalNonDefaultLocaleForScript1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "Hira" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ja-Hira-JP"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultLocaleForLangScript1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "uz-Latn" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "uz-Latn-UZ"); // Uzbek always uses the script + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultLocaleForLangScript2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ru-Cyrl" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ru-RU"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalDefaultLocaleForLangScript3: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "no-Latn" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "no-NO"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalNonDefaultLocaleForLangScript1: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "en-Dsrt" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "en-Dsrt-US"); + test.done(); + }, + + testLocaleMatcherGetLikelyLocaleMinimalNonDefaultLocaleForLangScript2: function(test) { + test.expect(3); + var lm = new LocaleMatcher({ + locale: "ar-Hebr" + }); + test.ok(typeof(lm) !== "undefined"); + var locale = lm.getLikelyLocaleMinimal(); + test.ok(typeof(locale) !== "undefined"); + test.equal(locale.getSpec(), "ar-Hebr-IL"); + test.done(); + } +}; diff --git a/js/test/root/testresources.js b/js/test/root/testresources.js index be245d6629..6d268097c6 100644 --- a/js/test/root/testresources.js +++ b/js/test/root/testresources.js @@ -1,7 +1,7 @@ /* * testresources.js - test the Resources object * - * Copyright © 2012-2015, 2017-2018, JEDLSoft + * Copyright © 2012-2015, 2017-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,9 @@ if (typeof(ResBundle) === "undefined") { if (typeof(Locale) === "undefined") { var Locale = require("../../lib/Locale.js"); } +if (ilib._getPlatform() === "nodejs" && ilib._dyndata && ilib._dyncode) { + var path = require("path"); +} ilib.data.strings = { "first string": "first", @@ -2072,6 +2075,58 @@ module.exports.testresources = { "dritte String 2" ]); + test.done(); + }, + + testResBundleGetStringWithBasePath: function(test) { + if (ilib._getPlatform() !== "nodejs" || !ilib._dyndata || !ilib._dyncode) { + test.done(); + return; + } + + test.expect(4); + + // clear this to be sure it is actually loading something + ilib.clearCache(); + + var base = path.relative(process.cwd(), path.resolve(__dirname, "./resources")); + + var rb = new ResBundle({ + locale: "ja-JP", + name: "basetest", + basePath: base + }); + + test.ok(rb !== null); + + test.equal(rb.getString("Hello from {country}").toString(), "{country}からこんにちは"); + test.equal(rb.getString("Hello from {city}").toString(), "{city}からこんにちは"); + test.equal(rb.getString("Greetings from {city} in {country}").toString(), "{city}と{country}からこんにちは"); + test.done(); + }, + + testResBundleGetStringWithDifferentBasePath: function(test) { + if (ilib._getPlatform() !== "nodejs" || !ilib._dyndata || !ilib._dyncode) { + test.done(); + return; + } + + test.expect(4); + + // don't clear the cache + var base = path.relative(process.cwd(), path.resolve(__dirname, "./resources2")); + + var rb = new ResBundle({ + locale: "ja-JP", + name: "basetest", + basePath: base + }); + + test.ok(rb !== null); + + test.equal(rb.getString("Hello from {country}").toString(), "{country}からこんにちは2"); + test.equal(rb.getString("Hello from {city}").toString(), "{city}からこんにちは2"); + test.equal(rb.getString("Greetings from {city} in {country}").toString(), "{city}と{country}からこんにちは2"); test.done(); } }; \ No newline at end of file diff --git a/js/test/root/testresourcesasync.js b/js/test/root/testresourcesasync.js index c370506a01..88026283a2 100644 --- a/js/test/root/testresourcesasync.js +++ b/js/test/root/testresourcesasync.js @@ -1,7 +1,7 @@ /* * testresourcesasync.js - test the Resources object * - * Copyright © 2018, JEDLSoft + * Copyright © 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,38 @@ module.exports.testresourcesasync = { test.done(); } }); + }, + + testResBundleAsyncGetStringWithPathesMX: function(test) { + if (ilib._getPlatform() !== "nodejs" || !ilib._dyndata || !ilib._dyncode) { + test.done(); + return; + } + + test.expect(4); + + // clear this to be sure it is actually loading something + ilib.data.strings = undefined; + ilib.data.strings_es = undefined; + ilib.data.strings_und_MX = undefined; + ilib.data.strings_es_MX = undefined; + ilib.clearCache(); + var base = path.relative(process.cwd(), path.resolve(__dirname, "./resources")); + + new ResBundle({ + locale: "es-MX", + sync: false, + basePath: base, + onLoad: function(rb) { + test.ok(rb !== null); + + test.equal(rb.getString("Hello from {country}").toString(), "Que tal de {country}"); + test.equal(rb.getString("Hello from {city}").toString(), "Que tal de {city}"); + test.equal(rb.getString("Greetings from {city} in {country}").toString(), "Hola de {city} en {country}"); + test.done(); + } + }); }, testResBundleAsyncGetStringOtherBundlePsuedoRaw: function(test) { diff --git a/js/test/root/testscriptinfo.js b/js/test/root/testscriptinfo.js index 87b249a9dd..cf53f1eabf 100644 --- a/js/test/root/testscriptinfo.js +++ b/js/test/root/testscriptinfo.js @@ -1,7 +1,7 @@ /* * testscriptinfo.js - test the script info object * - * Copyright © 2013-2017, JEDLSoft + * Copyright © 2013-2017, 2019 JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -180,7 +180,7 @@ module.exports.testscriptinfo = { var scripts = ScriptInfo.getAllScripts(); test.ok(scripts !== null); - test.equal(scripts.length, 189); + test.equal(scripts.length, 202); test.equal(scripts[0], "Adlm"); test.equal(scripts[1], "Afak"); @@ -198,7 +198,7 @@ module.exports.testscriptinfo = { test.equal(si.getCode(), "Kits"); test.equal(si.getCodeNumber(), 288); test.equal(si.getName(), "Khitan small script"); - test.equal(si.getLongCode(), "Khitan_small_script"); + test.equal(si.getLongCode(), "Khitan_Small_Script"); test.equal(si.getScriptDirection(), "ltr"); test.ok(!si.getNeedsIME()); test.ok(!si.getCasing()); diff --git a/js/test/root/testscriptinfoasync.js b/js/test/root/testscriptinfoasync.js index 2b64b6a0af..427f35f5f3 100644 --- a/js/test/root/testscriptinfoasync.js +++ b/js/test/root/testscriptinfoasync.js @@ -1,7 +1,7 @@ /* * testscriptinfoasync.js - test the script info object * - * Copyright © 2018, JEDLSoft + * Copyright © 2018-2019, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -114,7 +114,7 @@ module.exports.testscriptinfoasync = { ScriptInfo.getAllScripts(false, undefined, function(scripts) { test.ok(scripts !== null); - test.equal(scripts.length, 189); + test.equal(scripts.length, 202); test.equal(scripts[0], "Adlm"); test.equal(scripts[1], "Afak"); @@ -126,7 +126,7 @@ module.exports.testscriptinfoasync = { ScriptInfo.getAllScripts(false, undefined, function(scripts) { test.ok(scripts !== null); - test.equal(scripts.length, 189); + test.equal(scripts.length, 202); test.equal(scripts[0], "Adlm"); test.equal(scripts[scripts.length-1], "Zzzz"); diff --git a/js/test/strings-ext/testnorm.js b/js/test/strings-ext/testnorm.js index 8c5be805c0..55f89f7039 100644 --- a/js/test/strings-ext/testnorm.js +++ b/js/test/strings-ext/testnorm.js @@ -27,6 +27,10 @@ if (typeof(normtests) === "undefined") { var normtests = require("./normdata.js"); } +if (ilib._getPlatform() === "qt" && typeof normtests === "undefined" ) { + Qt.include("./normdata.js"); +} + if (ilib.isDynData()) { NormString.init(); } @@ -202,4 +206,4 @@ module.exports.testnorm = { test.done(); } -}; \ No newline at end of file +}; diff --git a/js/test/units/testarea.js b/js/test/units/testarea.js index 9b12152663..4f7c8736be 100644 --- a/js/test/units/testarea.js +++ b/js/test/units/testarea.js @@ -160,14 +160,14 @@ module.exports.testarea = { var m = AreaUnit.convert( "hectare", "square meter",2.0); test.equal(m, 0.0002); + + test.done(); }, - testAreaStaticConvert13: function(test) { test.expect(1); - var m = AreaUnit.convert( "square yard","square inch", 2.0); - - test.roughlyEqual(m, 0.00154321, 00000001); + var m = AreaUnit.convert("square yard","square inch", 2.0); + test.roughlyEqual(m, 0.00154321, 0.0000001); test.done(); }, testAreaStaticConvert14: function(test) { diff --git a/js/test/util/testutils.js b/js/test/util/testutils.js index 4c893eb056..7693eaf7b7 100644 --- a/js/test/util/testutils.js +++ b/js/test/util/testutils.js @@ -1,7 +1,7 @@ /* * testutils.js - test the utility routines * - * Copyright © 2012-2015, 2017-2018 JEDLSoft + * Copyright © 2012-2015, 2017-2019 JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1562,15 +1562,8 @@ module.exports.testutils = { testHashCodeNotEqualFunctionDifferentNames: function(test) { test.expect(1); - if (ilib._getPlatform() === "qt") { - // the qt javascript engine doesn't allow you to see the code of a function, so all - // functions should have the same hash - var expected = JSUtils.hashCode(function a() { return "a"; }); - test.equal(JSUtils.hashCode(function b() { return "a"; }), expected); - } else { - var expected = JSUtils.hashCode(function a() { return "a"; }); - test.notEqual(JSUtils.hashCode(function b() { return "a"; }), expected); - } + var expected = JSUtils.hashCode(function a() { return "a"; }); + test.notEqual(JSUtils.hashCode(function b() { return "a"; }), expected); test.done(); }, testHashCodeNotEqualFunctionDifferentContents: function(test) { @@ -2038,6 +2031,36 @@ module.exports.testutils = { } }, + testLoadDataDontMixDifferentBasePaths: function(test) { + ilib.data.foo = ilib.data.foo_de = ilib.data.foo_und_DE = ilib.data.foo_de_DE = undefined; + ilib.setLoaderCallback(mockLoaderNoMulti); + try { + Utils.loadData({ + name: "foo.json", + locale: "de-DE", + basePath: "asdf", + callback: function (results) { + test.ok(results); + Utils.loadData({ + name: "foo.json", + locale: "de-DE", + basePath: "foobar", + callback: function (results2) { + // if there is a cache miss when it attempts to load a file from disk twice + // then the mock loader will throw an exception, which is expected here + // because the base paths are different and Utils.loadData should try to + // load two files with the same name but different bases. + test.fail(); + test.done(); + } + }); + } + }); + } catch (e) { + test.done(); + } + }, + testLoadDataCacheResultAlreadyMerged: function(test) { ilib.data.foo = ilib.data.foo_de = ilib.data.foo_und_DE = ilib.data.foo_de_DE = undefined; ilib.setLoaderCallback(mockLoaderNoMulti); diff --git a/package.json b/package.json index d66a866b54..b367ae7412 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ilib", - "version": "14.3.0", + "version": "14.4.0", "main": "js/index.js", "description": "iLib is a cross-engine library of internationalization (i18n) classes written in pure JS", "keywords": [ @@ -42,7 +42,8 @@ "files": [ "js/lib", "js/locale", - "js/README.md" + "README.md", + "LICENSE" ], "repository": { "type": "git", diff --git a/qt/NodeunitTest/TestEnvironment.qml b/qt/NodeunitTest/TestEnvironment.qml index 83335c8689..1b84ae7c27 100644 --- a/qt/NodeunitTest/TestEnvironment.qml +++ b/qt/NodeunitTest/TestEnvironment.qml @@ -7,8 +7,8 @@ QtObject { id: thisObj property string path: "" property string moduleName: "" - property var ilib: {} - property var require: {} + property var ilib: ({}) + property var require: ({}) Component.onCompleted: { //console.log(">>>>>>>>>>>> [TestEnvironment.qml] new context. Loading in a fresh copy of ilib."); @@ -17,7 +17,7 @@ QtObject { ilib = QtIlib.ilib; var loader = new QtIlib.QmlLoader(FS.FileReader); ilib.setLoaderCallback(loader); - require = QtIlib.require; + require = QtIlib.require; var testSuites, runTest, i; testSuites = require("qmltest", path); diff --git a/qt/NodeunitTest/TestSuiteModule.js b/qt/NodeunitTest/TestSuiteModule.js index 2f4b4f9c12..6d17b3e4fc 100644 --- a/qt/NodeunitTest/TestSuiteModule.js +++ b/qt/NodeunitTest/TestSuiteModule.js @@ -42,8 +42,8 @@ TestSuite.prototype = { runTests: function() { //console.log("[TestSuiteModule.js] TestSuite.runTests: for suite (this.moduleName) " + this.moduleName); var suiteComponent = Qt.createComponent("./TestEnvironment.qml"); - if (suiteComponent.status != Component.Ready) { - if (suiteComponent.status == Component.Error) + if (suiteComponent.status !== Component.Ready) { + if (suiteComponent.status === Component.Error) console.debug("[TestSuiteModules.js] TestSuite.runTests: Error: "+ suiteComponent.errorString()); return; // or maybe throw } @@ -51,7 +51,7 @@ TestSuite.prototype = { path: this.path, moduleName: this.moduleName }); - if (suiteRunner == null) { + if (suiteRunner === null) { console.log("TestSuite.runTests: failed to run test suite " + this.path); } } diff --git a/qt/build.xml b/qt/build.xml index b01aa245f5..3dab623fc0 100644 --- a/qt/build.xml +++ b/qt/build.xml @@ -2,7 +2,7 @@ @@ -123,7 +134,7 @@ limitations under the License.