diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/Intl/RelativeTimeFormat | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Intl/RelativeTimeFormat')
10 files changed, 673 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/browser.js b/js/src/tests/non262/Intl/RelativeTimeFormat/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/browser.js diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/construct-newtarget.js b/js/src/tests/non262/Intl/RelativeTimeFormat/construct-newtarget.js new file mode 100644 index 0000000000..c20c07434e --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/construct-newtarget.js @@ -0,0 +1,21 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var obj = new Intl.RelativeTimeFormat(); + +// Test that new RTF produces an object with the right prototype. +assertEq(Object.getPrototypeOf(obj), Intl.RelativeTimeFormat.prototype); + +// Test subclassing %Intl.RelativeTimeFormat% works correctly. +class MyRelativeTimeFormat extends Intl.RelativeTimeFormat {} + +var obj = new MyRelativeTimeFormat(); +assertEq(obj instanceof MyRelativeTimeFormat, true); +assertEq(obj instanceof Intl.RelativeTimeFormat, true); +assertEq(Object.getPrototypeOf(obj), MyRelativeTimeFormat.prototype); + +if (typeof reportCompare === "function") + reportCompare(0, 0); diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/cross-compartment.js b/js/src/tests/non262/Intl/RelativeTimeFormat/cross-compartment.js new file mode 100644 index 0000000000..c826538f39 --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/cross-compartment.js @@ -0,0 +1,22 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +var otherGlobal = newGlobal(); + +var relativeTimeFormat = new Intl.RelativeTimeFormat(); +var ccwRelativeTimeFormat = new otherGlobal.Intl.RelativeTimeFormat(); + +// Test Intl.RelativeTimeFormat.prototype.format with a CCW object. +var Intl_RelativeTimeFormat_format = Intl.RelativeTimeFormat.prototype.format; + +assertEq(Intl_RelativeTimeFormat_format.call(ccwRelativeTimeFormat, 0, "hour"), + Intl_RelativeTimeFormat_format.call(relativeTimeFormat, 0, "hour")); + +// Test Intl.RelativeTimeFormat.prototype.resolvedOptions with a CCW object. +var Intl_RelativeTimeFormat_resolvedOptions = Intl.RelativeTimeFormat.prototype.resolvedOptions; + +assertEq(deepEqual(Intl_RelativeTimeFormat_resolvedOptions.call(ccwRelativeTimeFormat), + Intl_RelativeTimeFormat_resolvedOptions.call(relativeTimeFormat)), + true); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/format.js b/js/src/tests/non262/Intl/RelativeTimeFormat/format.js new file mode 100644 index 0000000000..244dbb5c56 --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/format.js @@ -0,0 +1,145 @@ +// |reftest| skip-if(!this.hasOwnProperty('Intl')) +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Tests the format function with a diverse set of locales and options. + +var rtf; + +{ + // Numeric format + rtf = new Intl.RelativeTimeFormat("en-US"); + assertEq(rtf.format(0, "second"), "in 0 seconds"); + assertEq(rtf.format(-0, "second"), "0 seconds ago"); + assertEq(rtf.format(-1, "second"), "1 second ago"); + assertEq(rtf.format(1, "second"), "in 1 second"); + + assertEq(rtf.format(0, "minute"), "in 0 minutes"); + assertEq(rtf.format(-0, "minute"), "0 minutes ago"); + assertEq(rtf.format(-1, "minute"), "1 minute ago"); + assertEq(rtf.format(1, "minute"), "in 1 minute"); + + assertEq(rtf.format(0, "hour"), "in 0 hours"); + assertEq(rtf.format(-0, "hour"), "0 hours ago"); + assertEq(rtf.format(-1, "hour"), "1 hour ago"); + assertEq(rtf.format(1, "hour"), "in 1 hour"); + + assertEq(rtf.format(0, "day"), "in 0 days"); + assertEq(rtf.format(-0, "day"), "0 days ago"); + assertEq(rtf.format(-1, "day"), "1 day ago"); + assertEq(rtf.format(1, "day"), "in 1 day"); + + assertEq(rtf.format(0, "week"), "in 0 weeks"); + assertEq(rtf.format(-0, "week"), "0 weeks ago"); + assertEq(rtf.format(-1, "week"), "1 week ago"); + assertEq(rtf.format(1, "week"), "in 1 week"); + + assertEq(rtf.format(0, "month"), "in 0 months"); + assertEq(rtf.format(-0, "month"), "0 months ago"); + assertEq(rtf.format(-1, "month"), "1 month ago"); + assertEq(rtf.format(1, "month"), "in 1 month"); + + assertEq(rtf.format(0, "year"), "in 0 years"); + assertEq(rtf.format(-0, "year"), "0 years ago"); + assertEq(rtf.format(-1, "year"), "1 year ago"); + assertEq(rtf.format(1, "year"), "in 1 year"); +} + +{ + // Text format + rtf = new Intl.RelativeTimeFormat("en-US", { + numeric: "auto" + }); + assertEq(rtf.format(0, "second"), "now"); + assertEq(rtf.format(-0, "second"), "now"); + assertEq(rtf.format(-1, "second"), "1 second ago"); + assertEq(rtf.format(1, "second"), "in 1 second"); + + assertEq(rtf.format(0, "minute"), "this minute"); + assertEq(rtf.format(-0, "minute"), "this minute"); + assertEq(rtf.format(-1, "minute"), "1 minute ago"); + assertEq(rtf.format(1, "minute"), "in 1 minute"); + + assertEq(rtf.format(0, "hour"), "this hour"); + assertEq(rtf.format(-0, "hour"), "this hour"); + assertEq(rtf.format(-1, "hour"), "1 hour ago"); + assertEq(rtf.format(1, "hour"), "in 1 hour"); + + assertEq(rtf.format(0, "day"), "today"); + assertEq(rtf.format(-0, "day"), "today"); + assertEq(rtf.format(-1, "day"), "yesterday"); + assertEq(rtf.format(1, "day"), "tomorrow"); + + assertEq(rtf.format(0, "week"), "this week"); + assertEq(rtf.format(-0, "week"), "this week"); + assertEq(rtf.format(-1, "week"), "last week"); + assertEq(rtf.format(1, "week"), "next week"); + + assertEq(rtf.format(0, "month"), "this month"); + assertEq(rtf.format(-0, "month"), "this month"); + assertEq(rtf.format(-1, "month"), "last month"); + assertEq(rtf.format(1, "month"), "next month"); + + assertEq(rtf.format(0, "year"), "this year"); + assertEq(rtf.format(-0, "year"), "this year"); + assertEq(rtf.format(-1, "year"), "last year"); + assertEq(rtf.format(1, "year"), "next year"); +} + +{ + // Plural specifier + rtf = new Intl.RelativeTimeFormat("en-US"); + assertEq(rtf.format(1, "seconds"), "in 1 second"); + assertEq(rtf.format(1, "minutes"), "in 1 minute"); + assertEq(rtf.format(1, "hours"), "in 1 hour"); + assertEq(rtf.format(1, "days"), "in 1 day"); + assertEq(rtf.format(1, "weeks"), "in 1 week"); + assertEq(rtf.format(1, "months"), "in 1 month"); + assertEq(rtf.format(1, "years"), "in 1 year"); +} + +rtf = new Intl.RelativeTimeFormat("de", {numeric: "auto"}); +assertEq(rtf.format(-1, "day"), "gestern"); +assertEq(rtf.format(1, "day"), "morgen"); + +rtf = new Intl.RelativeTimeFormat("ar", {numeric: "auto"}); +assertEq(rtf.format(-1, "day"), "أمس"); +assertEq(rtf.format(1, "day"), "غدًا"); + + +rtf = new Intl.RelativeTimeFormat("en-US"); + +var weirdValueCases = [ + Infinity, + -Infinity, + NaN, + "word", + [0,2], + {}, +]; + +for (let c of weirdValueCases) { + assertThrowsInstanceOf(() => rtf.format(c, "year"), RangeError); +}; + +var weirdUnitCases = [ + "test", + "SECOND", + "sEcOnD", + 1, + NaN, + undefined, + null, + {}, +]; + +for (let u of weirdUnitCases) { + assertThrowsInstanceOf(function() { + var rtf = new Intl.RelativeTimeFormat("en-US"); + rtf.format(1, u); + }, RangeError); +}; + + +reportCompare(0, 0, 'ok'); diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/locale-fallback-handling.js b/js/src/tests/non262/Intl/RelativeTimeFormat/locale-fallback-handling.js new file mode 100644 index 0000000000..76917c6fa0 --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/locale-fallback-handling.js @@ -0,0 +1,15 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// In locales that don't have a relative-date/time formatter -- and presently +// "ak" is such a locale -- behavior is expected to fall back to the root-locale +// formatter. This test verifies such fallback works as long as "ak" satisfies +// these properties; "ak" may safely be changed to a different locale if that +// ever changes. See bug 1504656. +assertEq(new Intl.RelativeTimeFormat("ak").format(1, "second"), + "+1 s"); + +if (typeof reportCompare === "function") + reportCompare(0, 0, 'ok'); diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/numbering-system.js b/js/src/tests/non262/Intl/RelativeTimeFormat/numbering-system.js new file mode 100644 index 0000000000..d9a860bb01 --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/numbering-system.js @@ -0,0 +1,22 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +// Ensure passing the default numbering system leads to the same result as when +// no explicit numbering system is present. +// +// This is a regression test for the ICU issue reported at +// <https://unicode-org.atlassian.net/browse/ICU-20280>. + +for (var requestedLocale of [undefined, "en", "de", "fr"]) { + var rtf = new Intl.RelativeTimeFormat(requestedLocale); + var {locale, numberingSystem} = rtf.resolvedOptions(); + var rtfNu = new Intl.RelativeTimeFormat(`${locale}-u-nu-${numberingSystem}`); + + for (var unit of ["year", "quarter", "month", "week", "day", "hour", "minute", "second"]) { + for (var value of [-10, -3, -2, -1, 0, 1, 2, 3, 10]) { + assertEq(rtfNu.format(value, unit), rtf.format(value, unit)); + } + } +} + +if (typeof reportCompare === "function") + reportCompare(0, 0); diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/numberingSystem-option.js b/js/src/tests/non262/Intl/RelativeTimeFormat/numberingSystem-option.js new file mode 100644 index 0000000000..bbde290dfa --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/numberingSystem-option.js @@ -0,0 +1,60 @@ +const defaultLocale = "en"; +const defaultNumberingSystem = new Intl.RelativeTimeFormat(defaultLocale).resolvedOptions().numberingSystem; + +function createWithLocale(locale, numberingSystem) { + return new Intl.RelativeTimeFormat(locale, {numberingSystem}); +} + +function create(numberingSystem) { + return createWithLocale(defaultLocale, numberingSystem); +} + +// Empty string should throw. +assertThrowsInstanceOf(() => create(""), RangeError); + +// Trailing \0 should throw. +assertThrowsInstanceOf(() => create("latn\0"), RangeError); + +// Too short or too long strings should throw. +assertThrowsInstanceOf(() => create("a"), RangeError); +assertThrowsInstanceOf(() => create("toolongstring"), RangeError); + +// Throw even when prefix is valid. +assertThrowsInstanceOf(() => create("latn-toolongstring"), RangeError); + +// |numberingSystem| can be set to |undefined|. +let nf = create(undefined); +assertEq(nf.resolvedOptions().numberingSystem, defaultNumberingSystem); + +// Unsupported numbering systems are ignored. +nf = create("xxxxxxxx"); +assertEq(nf.resolvedOptions().numberingSystem, defaultNumberingSystem); + +// Numbering system in options overwrite Unicode extension keyword. +nf = createWithLocale(`${defaultLocale}-u-nu-thai`, "arab"); +assertEq(nf.resolvedOptions().locale, defaultLocale); +assertEq(nf.resolvedOptions().numberingSystem, "arab"); + +// |numberingSystem| option ignores case. +nf = create("ARAB"); +assertEq(nf.resolvedOptions().locale, defaultLocale); +assertEq(nf.resolvedOptions().numberingSystem, "arab"); + +for (let [numberingSystem, {algorithmic}] of Object.entries(numberingSystems)) { + let nf1 = new Intl.RelativeTimeFormat(`${defaultLocale}-u-nu-${numberingSystem}`); + let nf2 = new Intl.RelativeTimeFormat(defaultLocale, {numberingSystem}); + + if (!algorithmic) { + assertEq(nf1.resolvedOptions().numberingSystem, numberingSystem); + assertEq(nf2.resolvedOptions().numberingSystem, numberingSystem); + } else { + // We don't yet support algorithmic numbering systems. + assertEq(nf1.resolvedOptions().numberingSystem, defaultNumberingSystem); + assertEq(nf2.resolvedOptions().numberingSystem, defaultNumberingSystem); + } + + assertEq(nf2.format(0, "second"), nf1.format(0, "second")); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/relativetimeformat.js b/js/src/tests/non262/Intl/RelativeTimeFormat/relativetimeformat.js new file mode 100644 index 0000000000..fb30e5a9ce --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/relativetimeformat.js @@ -0,0 +1,15 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Tests the format function with a diverse set of locales and options. + +var rtf; + +rtf = new Intl.RelativeTimeFormat("en-us"); +assertEq(rtf.resolvedOptions().locale, "en-US"); +assertEq(rtf.resolvedOptions().style, "long"); +assertEq(rtf.resolvedOptions().numeric, "always"); + +reportCompare(0, 0, 'ok'); diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/shell.js b/js/src/tests/non262/Intl/RelativeTimeFormat/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/shell.js diff --git a/js/src/tests/non262/Intl/RelativeTimeFormat/supportedLocalesOf.js b/js/src/tests/non262/Intl/RelativeTimeFormat/supportedLocalesOf.js new file mode 100644 index 0000000000..214b12570e --- /dev/null +++ b/js/src/tests/non262/Intl/RelativeTimeFormat/supportedLocalesOf.js @@ -0,0 +1,373 @@ +// |reftest| skip-if(!this.hasOwnProperty('Intl')||xulRuntime.shell) +// -- test in browser only that ICU has locale data for all Mozilla languages + +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This array contains the locales that ICU supports in +// number formatting whose languages Mozilla localizes Firefox into. +// Current as of ICU 50.1.2 and Firefox March 2013. +var locales = [ + "af", + "af-NA", + "af-ZA", + "ar", + "ar-001", + "ar-AE", + "ar-BH", + "ar-DJ", + "ar-DZ", + "ar-EG", + "ar-EH", + "ar-ER", + "ar-IL", + "ar-IQ", + "ar-JO", + "ar-KM", + "ar-KW", + "ar-LB", + "ar-LY", + "ar-MA", + "ar-MR", + "ar-OM", + "ar-PS", + "ar-QA", + "ar-SA", + "ar-SD", + "ar-SO", + "ar-SY", + "ar-TD", + "ar-TN", + "ar-YE", + "as", + "as-IN", + "be", + "be-BY", + "bg", + "bg-BG", + "bn", + "bn-BD", + "bn-IN", + "br", + "br-FR", + "bs", + "bs-Cyrl", + "bs-Cyrl-BA", + "bs-Latn", + "bs-Latn-BA", + "ca", + "ca-AD", + "ca-ES", + "cs", + "cs-CZ", + "cy", + "cy-GB", + "da", + "da-DK", + "de", + "de-AT", + "de-BE", + "de-CH", + "de-DE", + "de-LI", + "de-LU", + "el", + "el-CY", + "el-GR", + "en", + "en-150", + "en-AG", + "en-AS", + "en-AU", + "en-BB", + "en-BE", + "en-BM", + "en-BS", + "en-BW", + "en-BZ", + "en-CA", + "en-CM", + "en-DM", + "en-FJ", + "en-FM", + "en-GB", + "en-GD", + "en-GG", + "en-GH", + "en-GI", + "en-GM", + "en-GU", + "en-GY", + "en-HK", + "en-IE", + "en-IM", + "en-IN", + "en-JE", + "en-JM", + "en-KE", + "en-KI", + "en-KN", + "en-KY", + "en-LC", + "en-LR", + "en-LS", + "en-MG", + "en-MH", + "en-MP", + "en-MT", + "en-MU", + "en-MW", + "en-NA", + "en-NG", + "en-NZ", + "en-PG", + "en-PH", + "en-PK", + "en-PR", + "en-PW", + "en-SB", + "en-SC", + "en-SG", + "en-SL", + "en-SS", + "en-SZ", + "en-TC", + "en-TO", + "en-TT", + "en-TZ", + "en-UG", + "en-UM", + "en-US", + "en-US-posix", + "en-VC", + "en-VG", + "en-VI", + "en-VU", + "en-WS", + "en-ZA", + "en-ZM", + "en-ZW", + "eo", + "es", + "es-419", + "es-AR", + "es-BO", + "es-CL", + "es-CO", + "es-CR", + "es-CU", + "es-DO", + "es-EA", + "es-EC", + "es-ES", + "es-GQ", + "es-GT", + "es-HN", + "es-IC", + "es-MX", + "es-NI", + "es-PA", + "es-PE", + "es-PH", + "es-PR", + "es-PY", + "es-SV", + "es-US", + "es-UY", + "es-VE", + "et", + "et-EE", + "eu", + "eu-ES", + "fa", + "fa-AF", + "fa-IR", + "ff", + "ff-SN", + "fi", + "fi-FI", + "fr", + "fr-BE", + "fr-BF", + "fr-BI", + "fr-BJ", + "fr-BL", + "fr-CA", + "fr-CD", + "fr-CF", + "fr-CG", + "fr-CH", + "fr-CI", + "fr-CM", + "fr-DJ", + "fr-DZ", + "fr-FR", + "fr-GA", + "fr-GF", + "fr-GN", + "fr-GP", + "fr-GQ", + "fr-HT", + "fr-KM", + "fr-LU", + "fr-MA", + "fr-MC", + "fr-MF", + "fr-MG", + "fr-ML", + "fr-MQ", + "fr-MR", + "fr-MU", + "fr-NC", + "fr-NE", + "fr-PF", + "fr-RE", + "fr-RW", + "fr-SC", + "fr-SN", + "fr-SY", + "fr-TD", + "fr-TG", + "fr-TN", + "fr-VU", + "fr-YT", + "ga", + "ga-IE", + "gl", + "gl-ES", + "gu", + "gu-IN", + "he", + "he-IL", + "hi", + "hi-IN", + "hr", + "hr-BA", + "hr-HR", + "hu", + "hu-HU", + "hy", + "hy-AM", + "id", + "id-ID", + "is", + "is-IS", + "it", + "it-CH", + "it-IT", + "it-SM", + "ja", + "ja-JP", + "kk", + "kk-Cyrl", + "kk-Cyrl-KZ", + "km", + "km-KH", + "kn", + "kn-IN", + "ko", + "ko-KP", + "ko-KR", + "lt", + "lt-LT", + "lv", + "lv-LV", + "mk", + "mk-MK", + "ml", + "ml-IN", + "mr", + "mr-IN", + "nb", + "nb-NO", + "nl", + "nl-AW", + "nl-BE", + "nl-CW", + "nl-NL", + "nl-SR", + "nl-SX", + "nn", + "nn-NO", + "or", + "or-IN", + "pa", + "pa-Arab", + "pa-Arab-PK", + "pa-Guru", + "pa-Guru-IN", + "pl", + "pl-PL", + "pt", + "pt-AO", + "pt-BR", + "pt-CV", + "pt-GW", + "pt-MO", + "pt-MZ", + "pt-PT", + "pt-ST", + "pt-TL", + "rm", + "rm-CH", + "ro", + "ro-MD", + "ro-RO", + "ru", + "ru-BY", + "ru-KG", + "ru-KZ", + "ru-MD", + "ru-RU", + "ru-UA", + "si", + "si-LK", + "sk", + "sk-SK", + "sl", + "sl-SI", + "sq", + "sq-AL", + "sq-MK", + "sr", + "sr-Cyrl", + "sr-Cyrl-BA", + "sr-Cyrl-ME", + "sr-Cyrl-RS", + "sr-Latn", + "sr-Latn-BA", + "sr-Latn-ME", + "sr-Latn-RS", + "sv", + "sv-AX", + "sv-FI", + "sv-SE", + "te", + "te-IN", + "th", + "th-TH", + "tr", + "tr-CY", + "tr-TR", + "uk", + "uk-UA", + "vi", + "vi-VN", + "zh", + "zh-Hans", + "zh-Hans-CN", + "zh-Hans-HK", + "zh-Hans-MO", + "zh-Hans-SG", + "zh-Hant", + "zh-Hant-HK", + "zh-Hant-MO", + "zh-Hant-TW", +]; + +const result = Intl.RelativeTimeFormat.supportedLocalesOf(locales); + +assertEqArray(locales, result); + +reportCompare(0, 0, 'ok'); |