diff options
Diffstat (limited to 'js/src/tests/test262/intl402/DurationFormat/prototype/format')
17 files changed, 225 insertions, 37 deletions
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/fractions-of-subsecond-units-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/fractions-of-subsecond-units-en.js new file mode 100644 index 0000000000..342fa613cf --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/fractions-of-subsecond-units-en.js @@ -0,0 +1,65 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: Checks that fractional milliseconds and microseconds are formatted correctly when microseconds or nanoseconds are the first units with "numeric" style. +info: | + PartitionDurationFormatPattern ( durationFormat, duration ) + (...) + 9. + (...) + g. If unit is "seconds", "milliseconds", or "microseconds", then + i. If unit is "seconds", then + 1. Let nextStyle be durationFormat.[[MillisecondsStyle]]. + ii. Else if unit is "milliseconds", then + 1. Let nextStyle be durationFormat.[[MicrosecondsStyle]]. + iii. Else, + 1. Let nextStyle be durationFormat.[[NanosecondsStyle]]. + iv. If nextStyle is "fractional", then + 1. Set value to value + AddFractionalDigits(durationFormat, duration). + 2. If durationFormat.[[FractionalDigits]] is undefined, then + a. Let maximumFractionDigits be 9𝔽. + b. Let minimumFractionDigits be +0𝔽. + 3. Else, + a. Let maximumFractionDigits be 𝔽(durationFormat.[[FractionalDigits]]). + b. Let minimumFractionDigits be 𝔽(durationFormat.[[FractionalDigits]]). + 4. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", maximumFractionDigits ). + 5. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", minimumFractionDigits ). + 6. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc"). + 7. Set done to true. + +locale: [en] +features: [Intl.DurationFormat] +---*/ + + +const locale = "en"; +const decimalSeparator = "."; + +let d = {seconds: 3, milliseconds: 444, microseconds: 55, nanoseconds: 6}; +let dfOpts = {microseconds: "numeric"}; + +let expectedList = []; +expectedList.push(new Intl.NumberFormat(locale, {style: "unit", unit: "second", unitDisplay: "short"}).format(d.seconds)); +expectedList.push(new Intl.NumberFormat(locale, {style: "unit", unit: "millisecond", unitDisplay: "short", minimumFractionDigits:0, maximumFractionDigits: 9}).format(d.milliseconds.toString() + decimalSeparator + d.microseconds.toString().padStart(3, '0') + d.nanoseconds.toString().padStart(3, '0'))); + +let expected = new Intl.ListFormat(locale, {style: "short"}).format(expectedList); +let actual = new Intl.DurationFormat(locale, dfOpts).format(d); + +// assert.sameValue(actual, expected, `DurationFormat output when microseconds first "numeric" unit`); + +dfOpts = {nanoseconds: "numeric"}; +expectedList = []; + +expectedList.push(new Intl.NumberFormat(locale, {style: "unit", unit: "second", unitDisplay: "short"}).format(d.seconds)); +expectedList.push(new Intl.NumberFormat(locale, {style: "unit", unit: "millisecond", unitDisplay: "short"}).format(d.milliseconds)); +expectedList.push(new Intl.NumberFormat(locale, {style: "unit", unit: "microsecond", unitDisplay: "short", minimumFractionDigits:0, maximumFractionDigits: 9}).format(d.microseconds.toString() + decimalSeparator + d.nanoseconds.toString().padStart(3, '0'))); + +expected = new Intl.ListFormat(locale, {style: "short"}).format(expectedList); +actual = new Intl.DurationFormat(locale, dfOpts).format(d); + +assert.sameValue(actual, expected, `DurationFormat output when nanoseconds first "numeric" unit`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/mixed-non-numeric-styles-es.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/mixed-non-numeric-styles-es.js new file mode 100644 index 0000000000..33ec1a2776 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/mixed-non-numeric-styles-es.js @@ -0,0 +1,88 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// Copyright 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: Test if format method formats duration correctly with mixed non-numeric settings for unit styles. Compares output from format method to output produced through using NumberFormat and ListFormat as used by DurationFormat. +info: | + PartitionDurationFormatPattern ( durationFormat, duration ) + ... + 9. While done is false, repeat for each row in Table 2 in table order, except the header row: + ... + k. If value is not 0 or display is not "auto" or displayRequired is "true", then + ... + v. If style is not "fractional", "numeric", or "2-digit", then + 1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit"). + 2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit). + 3. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style). + ... + ix. Let parts be ! PartitionNumberPattern(nf, value). + ... + 14. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle). + 15. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »). + ... + 18. Let formatted be CreatePartsFromList(lf, strings). + +locale: [es] +features: [Intl.DurationFormat] +---*/ + +function formatDuration(locale, duration, dfOpts){ + let result = []; + for (const unit in duration){ + let nfUnit = unit.substring(0, unit.length - 1); + let nf = new Intl.NumberFormat(locale, {style: "unit", unit: nfUnit, unitDisplay: dfOpts[unit]}); + result.push(nf.format(duration[unit])); + } + + for (const baseStyle of ["long", "short", "narrow"]){ + let lf = new Intl.ListFormat(locale, {type: "unit", style: baseStyle}); + let expected = lf.format(result); + dfOpts.style = baseStyle; + let df = new Intl.DurationFormat(locale, dfOpts); + let actual = df.format(duration); + assert.sameValue(actual, expected); + } +} + +const duration = { + years: 1, + months: 2, + weeks: 3, + days: 0, + hours: 4, + minutes: 5, + seconds: 6, + milliseconds: 7, + microseconds: 8, + nanoseconds: 9, +}; + +const locale = "es"; + +formatDuration(locale, duration, { + years: "narrow", + months: "narrow", + weeks: "narrow", + days: "short", + hours: "short", + minutes: "short", + seconds: "long", + milliseconds: "long", + microseconds: "long", + nanoseconds: "narrow", }); + +formatDuration(locale, duration, { + years: "long", + months: "short", + weeks: "narrow", + days: "long", + hours: "short", + minutes: "narrow", + seconds: "long", + milliseconds: "short", + microseconds: "narrow", + nanoseconds: "long", }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/mixed-short-and-numeric.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/mixed-short-and-numeric.js new file mode 100644 index 0000000000..19adbfbd47 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/mixed-short-and-numeric.js @@ -0,0 +1,37 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: Checks that durations containing a mixture of numericlike and non-numericlike styles are formatted using the "short" style when DurationFormat base style is *undefined*. +info: | + PartitionDurationFormatPattern ( durationFormat, duration ) + + 12. Let listStyle be durationFormat.[[Style]]. + (...) + 14. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle). + +locale: [en] +features: [Intl.DurationFormat] +---*/ + +const locale = "en"; +const timeSeparator = ":"; + + +let d = {days: 5, hours: 1, minutes: 2, seconds: 3}; +let dfOpts = {minutes: "numeric", seconds: "numeric"}; + +let expectedList = []; +expectedList.push(new Intl.NumberFormat(locale, {style: "unit", unit: "day", unitDisplay: "short"}).format(d.days)); +expectedList.push(new Intl.NumberFormat(locale, {style: "unit", unit: "hour", unitDisplay: "short"}).format(d.hours)); +expectedList.push(new Intl.NumberFormat(locale).format(d.minutes) + timeSeparator + new Intl.NumberFormat(locale, {minimumIntegerDigits: 2}).format(d.seconds)); + +let expected = new Intl.ListFormat(locale, {style: "short"}).format(expectedList); +let actual = new Intl.DurationFormat(locale, dfOpts).format(d); + +assert.sameValue(actual, expected); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js index c6b58a5dfc..3c0f1d6dd5 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js @@ -6,7 +6,7 @@ esid: sec-Intl.DurationFormat.prototype.format description: > Test format method with negative duration and default style -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js index 83eb5b4639..9ebf996341 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js @@ -6,7 +6,7 @@ esid: sec-Intl.DurationFormat.prototype.format description: > Test format method with negative duration and "short" style -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js index c9f119c368..e26f198cd5 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js @@ -6,7 +6,7 @@ esid: sec-Intl.DurationFormat.prototype.format description: > Test format method with negative duration and "digital" style -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js index fe074d488e..d7654f5630 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js @@ -6,7 +6,7 @@ esid: sec-Intl.DurationFormat.prototype.format description: > Test format method with negative duration and "long" style -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js index 4d1db5dc67..1735112336 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js @@ -6,7 +6,7 @@ esid: sec-Intl.DurationFormat.prototype.format description: > Test format method with negative duration and "narrow" style -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js index dc5ad4ea84..3c37afa1b4 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js @@ -5,8 +5,8 @@ /*--- esid: sec-Intl.DurationFormat.prototype.format description: > - The correct separator is used for numeric hours with zero minutes and non-zero seconds. -locale: [en-US] + Minutes with numeric or 2-digit style are included in the output when between displayed hours and seconds, even when the minutes value is zero. +locale: [en] features: [Intl.DurationFormat] ---*/ @@ -15,30 +15,18 @@ const df = new Intl.DurationFormat("en", { hours: "numeric", }); -const lf = new Intl.ListFormat("en", { - type: "unit", - style: "short", -}); - const duration = { hours: 1, - - // Minutes is omitted from the output when its value is zero. minutes: 0, - - // Either seconds or sub-seconds must be non-zero. seconds: 3, }; -const expected = lf.format([ - new Intl.NumberFormat("en", {minimumIntegerDigits: 1}).format(duration.hours), - new Intl.NumberFormat("en", {minimumIntegerDigits: 2}).format(duration.seconds), -]); +const expected = "1:00:03" assert.sameValue( df.format(duration), expected, - `No time separator is used when minutes is zero` + `Minutes always displayed when between displayed hours and seconds, even if minutes is 0` ); reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js index 5518450d6a..dbb34d39f7 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js @@ -25,7 +25,7 @@ info: | 7. Let parts be ! PartitionNumberPattern(nf, value). ... -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-default-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-default-en.js index 6eb5c4999e..dae05ae5f1 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-default-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-default-en.js @@ -5,7 +5,7 @@ /*--- esid: sec-Intl.DurationFormat.prototype.format description: Test if format method formats duration correctly with different "style" arguments -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-en.js index 4f34d50aa9..cc2dd3342f 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-en.js @@ -6,7 +6,7 @@ /*--- esid: sec-Intl.DurationFormat.prototype.format description: Test if format method formats duration correctly with different "style" arguments -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-en.js index d75f51b14a..60c2232d6a 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-en.js @@ -14,6 +14,7 @@ info: | 5. Else, a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", durationFormat.[[FractionalDigits]]). b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", durationFormat.[[FractionalDigits]]). +locale: [en] features: [Intl.DurationFormat] ---*/ @@ -28,12 +29,12 @@ const duration = { const style = "digital"; -const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: 0}); -const dfMilli = new Intl.DurationFormat(undefined, {style, fractionalDigits: 3}); -const dfFourDigits = new Intl.DurationFormat(undefined, {style, fractionalDigits: 4}); -const dfMicro = new Intl.DurationFormat(undefined, {style, fractionalDigits: 6}); -const dfEightDigits = new Intl.DurationFormat(undefined, {style, fractionalDigits: 8}); -const dfNano = new Intl.DurationFormat(undefined, {style, fractionalDigits: 9}); +const df = new Intl.DurationFormat("en", {style, fractionalDigits: 0}); +const dfMilli = new Intl.DurationFormat("en", {style, fractionalDigits: 3}); +const dfFourDigits = new Intl.DurationFormat("en", {style, fractionalDigits: 4}); +const dfMicro = new Intl.DurationFormat("en", {style, fractionalDigits: 6}); +const dfEightDigits = new Intl.DurationFormat("en", {style, fractionalDigits: 8}); +const dfNano = new Intl.DurationFormat("en", {style, fractionalDigits: 9}); assert.sameValue(df.format(duration), "1:22:33", `format output without sub-second digits using ${style} style option`); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined-en.js index 631e6c36eb..b297c0c7ba 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined-en.js @@ -14,6 +14,7 @@ info: | 5. Else, a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", durationFormat.[[FractionalDigits]]). b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", durationFormat.[[FractionalDigits]]). +locale: [en] features: [Intl.DurationFormat] ---*/ @@ -35,7 +36,7 @@ const durationMicro = { microseconds: 222 }; -const durationMill = { +const durationMilli = { hours: 1, minutes: 22, seconds: 33, @@ -48,6 +49,14 @@ const durationNoSubsecond = { seconds: 33 }; +const durationFiveFractional = { + hours: 2, + minutes: 30, + seconds: 10, + milliseconds: 111, + microseconds: 220, +}; + const durationSevenFractional = { hours: 2, minutes: 30, @@ -58,14 +67,14 @@ const durationSevenFractional = { }; const style = "digital"; -const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: undefined}); +const df = new Intl.DurationFormat("en", {style, fractionalDigits: undefined}); assert.sameValue(df.format(durationNano), "1:22:33.111222333", `format output with nanosecond digits and fractionalDigits: undefined using ${style} style option`); assert.sameValue(df.format(durationMicro), "1:22:33.111222", `format output with microsecond digits and fractionalDigits: undefined using ${style} style option`); assert.sameValue(df.format(durationMilli), "1:22:33.111", `format output with millisecond digits and fractionalDigits: undefined using ${style} style option`); assert.sameValue(df.format(durationNoSubsecond), "1:22:33", `format output with no subsecond digits and fractionalDigits: undefined using ${style} style option`); -assert.sameValue(df.format(durationFiveFractional), "2:30:11122", `format output with five subsecond digits and fractionalDigits: undefined using ${style} style option`); -assert.sameValue(df.format(durationSevenFractional), "2:30:1112203", `format output with seven subsecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationFiveFractional), "2:30:10.11122", `format output with five subsecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationSevenFractional), "2:30:10.1112203", `format output with seven subsecond digits and fractionalDigits: undefined using ${style} style option`); reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-long-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-long-en.js index d9e6fc6cbb..74524da674 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-long-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-long-en.js @@ -5,7 +5,7 @@ /*--- esid: sec-Intl.DurationFormat.prototype.format description: Test if format method formats duration correctly with different "style" arguments -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-narrow-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-narrow-en.js index 66b2258761..e75dc17170 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-narrow-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-narrow-en.js @@ -5,7 +5,7 @@ /*--- esid: sec-Intl.DurationFormat.prototype.format description: Test if format method formats duration correctly with different "style" arguments -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-short-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-short-en.js index 2a66c01b06..049e034681 100644 --- a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-short-en.js +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-short-en.js @@ -5,7 +5,7 @@ /*--- esid: sec-Intl.DurationFormat.prototype.format description: Test if format method formats duration correctly with different "style" arguments -locale: [en-US] +locale: [en] includes: [testIntl.js] features: [Intl.DurationFormat] ---*/ |