diff options
Diffstat (limited to 'js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString')
6 files changed, 90 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/browser.js b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/browser.js diff --git a/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js new file mode 100644 index 0000000000..5cad007603 --- /dev/null +++ b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js @@ -0,0 +1,30 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tolocalestring +description: Calendar must match the locale calendar if not "iso8601" +features: [Temporal, Intl-enumeration] +---*/ + +const localeCalendar = new Intl.DateTimeFormat().resolvedOptions().calendar; +assert.notSameValue(localeCalendar, "iso8601", "no locale has the ISO calendar"); + +const sameCalendarInstance = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: localeCalendar }); +const result = sameCalendarInstance.toLocaleString(); +assert.sameValue(typeof result, "string", "toLocaleString() succeeds when instance has the same calendar as locale"); + +// Pick a different calendar that is not ISO and not the locale's calendar +const calendars = new Set(Intl.supportedValuesOf("calendar")); +calendars.delete("iso8601"); +calendars.delete(localeCalendar); +const differentCalendar = calendars.values().next().value; + +const differentCalendarInstance = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: differentCalendar }); +assert.throws(RangeError, () => differentCalendarInstance.toLocaleString(), "calendar mismatch"); + +const isoInstance = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: "iso8601" }); +assert.throws(RangeError, () => isoInstance.toLocaleString(), "calendar mismatch even when instance has the ISO calendar") + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/locales-undefined.js b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/locales-undefined.js new file mode 100644 index 0000000000..96f40e0394 --- /dev/null +++ b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/locales-undefined.js @@ -0,0 +1,22 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tolocalestring +description: Omitting the locales argument defaults to the DateTimeFormat default +features: [Temporal] +---*/ + +const defaultFormatter = new Intl.DateTimeFormat([], Object.create(null)); +const { calendar } = defaultFormatter.resolvedOptions(); +const monthday = new Temporal.PlainMonthDay(5, 2, calendar); +const expected = defaultFormatter.format(monthday); + +const actualExplicit = monthday.toLocaleString(undefined); +assert.sameValue(actualExplicit, expected, "default locale is determined by Intl.DateTimeFormat"); + +const actualImplicit = monthday.toLocaleString(); +assert.sameValue(actualImplicit, expected, "default locale is determined by Intl.DateTimeFormat"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/options-undefined.js b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/options-undefined.js new file mode 100644 index 0000000000..e59afa1d33 --- /dev/null +++ b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/options-undefined.js @@ -0,0 +1,22 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tolocalestring +description: Verify that undefined options are handled correctly. +features: [Temporal] +---*/ + +const defaultFormatter = new Intl.DateTimeFormat('en', Object.create(null)); +const { calendar } = defaultFormatter.resolvedOptions(); +const monthday = new Temporal.PlainMonthDay(5, 2, calendar); +const expected = defaultFormatter.format(monthday); + +const actualExplicit = monthday.toLocaleString('en', undefined); +assert.sameValue(actualExplicit, expected, "default locale is determined by Intl.DateTimeFormat"); + +const actualImplicit = monthday.toLocaleString('en'); +assert.sameValue(actualImplicit, expected, "default locale is determined by Intl.DateTimeFormat"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/resolved-time-zone.js b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/resolved-time-zone.js new file mode 100644 index 0000000000..bc66136c4f --- /dev/null +++ b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/resolved-time-zone.js @@ -0,0 +1,16 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tolocalestring +description: A time zone in resolvedOptions with a large offset still produces the correct string +locale: [en] +features: [Temporal] +---*/ + +const monthDay = new Temporal.PlainMonthDay(8, 4, "gregory"); +const result = monthDay.toLocaleString("en", { timeZone: "Pacific/Apia" }); +assert.sameValue(result, "8/4"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/shell.js b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/shell.js |