From 19d2a385588c9d834aaa8ffaaf98560ec2d868fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Tue, 9 Jan 2024 11:42:55 +0100 Subject: [PATCH] Add tests for negative durations with leading zero unit --- ...tion-with-leading-zero-style-default-en.js | 26 ++++++++++++ ...tion-with-leading-zero-style-digital-en.js | 28 +++++++++++++ ...uration-with-leading-zero-style-long-en.js | 28 +++++++++++++ ...ation-with-leading-zero-style-narrow-en.js | 28 +++++++++++++ ...ration-with-leading-zero-style-short-en.js | 28 +++++++++++++ ...tion-with-leading-zero-style-default-en.js | 40 ++++++++++++++++++ ...tion-with-leading-zero-style-digital-en.js | 42 +++++++++++++++++++ ...uration-with-leading-zero-style-long-en.js | 42 +++++++++++++++++++ ...ation-with-leading-zero-style-narrow-en.js | 42 +++++++++++++++++++ ...ration-with-leading-zero-style-short-en.js | 42 +++++++++++++++++++ 10 files changed, 346 insertions(+) create mode 100644 test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-default-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-digital-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-long-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-narrow-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-short-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-default-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-digital-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-long-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-narrow-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-short-en.js diff --git a/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-default-en.js b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-default-en.js new file mode 100644 index 0000000000..531bda46a4 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-default-en.js @@ -0,0 +1,26 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Test format method with negative duration and leading zero using the default style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {hoursDisplay: "always"}); + +const expected = formatDurationFormatPattern(df, duration); + +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using default style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-digital-en.js b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-digital-en.js new file mode 100644 index 0000000000..caaf42179d --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-digital-en.js @@ -0,0 +1,28 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Test format method with negative duration and leading zero using the "digital" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "digital"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = formatDurationFormatPattern(df, duration); + +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-long-en.js b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-long-en.js new file mode 100644 index 0000000000..35a80e9486 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-long-en.js @@ -0,0 +1,28 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Test format method with negative duration and leading zero using the "long" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "long"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = formatDurationFormatPattern(df, duration); + +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-narrow-en.js b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-narrow-en.js new file mode 100644 index 0000000000..c5e7924ef9 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-narrow-en.js @@ -0,0 +1,28 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Test format method with negative duration and leading zero using the "narrow" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "narrow"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = formatDurationFormatPattern(df, duration); + +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-short-en.js b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-short-en.js new file mode 100644 index 0000000000..898063ac7c --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-duration-with-leading-zero-style-short-en.js @@ -0,0 +1,28 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Test format method with negative duration and leading zero using the "short" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "short"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = formatDurationFormatPattern(df, duration); + +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-default-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-default-en.js new file mode 100644 index 0000000000..629b478df7 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-default-en.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Test formatToParts method with negative duration and leading zero using the default style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +function compare(actual, expected, message) { + assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`); + assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`); + assert.sameValue(actual.length, expected.length, `${message}: length`); + + for (let i = 0; i < expected.length; ++i) { + let actualEntry = actual[i]; + let expectedEntry = expected[i]; + + assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`); + assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`); + assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`); + if ("unit" in expectedEntry) { + assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`); + } + } +} + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {hoursDisplay: "always"}); + +const expected = partitionDurationFormatPattern(df, duration); + +compare(df.formatToParts(duration), expected, `Using style : default`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-digital-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-digital-en.js new file mode 100644 index 0000000000..f97268ec72 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-digital-en.js @@ -0,0 +1,42 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Test formatToParts method with negative duration and leading zero using the "digital" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +function compare(actual, expected, message) { + assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`); + assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`); + assert.sameValue(actual.length, expected.length, `${message}: length`); + + for (let i = 0; i < expected.length; ++i) { + let actualEntry = actual[i]; + let expectedEntry = expected[i]; + + assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`); + assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`); + assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`); + if ("unit" in expectedEntry) { + assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`); + } + } +} + +const style = "digital"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = partitionDurationFormatPattern(df, duration); + +compare(df.formatToParts(duration), expected, `Using style : ${style}`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-long-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-long-en.js new file mode 100644 index 0000000000..cca1f06794 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-long-en.js @@ -0,0 +1,42 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Test formatToParts method with negative duration and leading zero using the "long" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +function compare(actual, expected, message) { + assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`); + assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`); + assert.sameValue(actual.length, expected.length, `${message}: length`); + + for (let i = 0; i < expected.length; ++i) { + let actualEntry = actual[i]; + let expectedEntry = expected[i]; + + assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`); + assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`); + assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`); + if ("unit" in expectedEntry) { + assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`); + } + } +} + +const style = "long"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = partitionDurationFormatPattern(df, duration); + +compare(df.formatToParts(duration), expected, `Using style : ${style}`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-narrow-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-narrow-en.js new file mode 100644 index 0000000000..a654bf17d1 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-narrow-en.js @@ -0,0 +1,42 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Test formatToParts method with negative duration and leading zero using the "narrow" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +function compare(actual, expected, message) { + assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`); + assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`); + assert.sameValue(actual.length, expected.length, `${message}: length`); + + for (let i = 0; i < expected.length; ++i) { + let actualEntry = actual[i]; + let expectedEntry = expected[i]; + + assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`); + assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`); + assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`); + if ("unit" in expectedEntry) { + assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`); + } + } +} + +const style = "narrow"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = partitionDurationFormatPattern(df, duration); + +compare(df.formatToParts(duration), expected, `Using style : ${style}`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-short-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-short-en.js new file mode 100644 index 0000000000..a59eced308 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-with-leading-zero-style-short-en.js @@ -0,0 +1,42 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Test formatToParts method with negative duration and leading zero using the "short" style. +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +function compare(actual, expected, message) { + assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`); + assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`); + assert.sameValue(actual.length, expected.length, `${message}: length`); + + for (let i = 0; i < expected.length; ++i) { + let actualEntry = actual[i]; + let expectedEntry = expected[i]; + + assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`); + assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`); + assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`); + if ("unit" in expectedEntry) { + assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`); + } + } +} + +const style = "short"; + +const duration = { + hours: 0, + seconds: -1, +}; + +const df = new Intl.DurationFormat("en", {style, hoursDisplay: "always"}); + +const expected = partitionDurationFormatPattern(df, duration); + +compare(df.formatToParts(duration), expected, `Using style : ${style}`);