From e27c9f690cfc6aaedf039d319313c13cca14100e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 23 Aug 2023 15:16:08 +0200 Subject: [PATCH] Add DurationFormat test for negative durations --- .../negative-duration-style-default-en.js | 33 +++++++++++++ .../negative-duration-style-short-en.js | 35 +++++++++++++ .../negative-durationstyle-digital-en.js | 35 +++++++++++++ .../format/negative-durationstyle-long-en.js | 35 +++++++++++++ .../negative-durationstyle-narrow-en.js | 35 +++++++++++++ ...duration-formatToParts-style-default-en.js | 47 ++++++++++++++++++ ...duration-formatToParts-style-digital-en.js | 49 +++++++++++++++++++ ...ve-duration-formatToParts-style-long-en.js | 49 +++++++++++++++++++ ...-duration-formatToParts-style-narrow-en.js | 49 +++++++++++++++++++ ...e-duration-formatToParts-style-short-en.js | 49 +++++++++++++++++++ 10 files changed, 416 insertions(+) create mode 100644 test/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js create mode 100644 test/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js create mode 100644 test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js diff --git a/test/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js b/test/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js new file mode 100644 index 0000000000..955d9f08ee --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js @@ -0,0 +1,33 @@ +// Copyright (C) 2023 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 default style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration); + +const df = new Intl.DurationFormat("en"); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using default style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js b/test/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js new file mode 100644 index 0000000000..f92540e6a5 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js @@ -0,0 +1,35 @@ +// Copyright (C) 2023 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 "short" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "short"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js b/test/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js new file mode 100644 index 0000000000..8c90ea4942 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js @@ -0,0 +1,35 @@ +// Copyright (C) 2023 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 "digital" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "digital"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js b/test/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js new file mode 100644 index 0000000000..97f577caf6 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js @@ -0,0 +1,35 @@ +// Copyright (C) 2023 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 "long" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "long"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js b/test/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js new file mode 100644 index 0000000000..49dd23792d --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js @@ -0,0 +1,35 @@ +// Copyright (C) 2023 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 "narrow" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "narrow"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js new file mode 100644 index 0000000000..5c4a230c91 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js @@ -0,0 +1,47 @@ +// Copyright (C) 2023 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 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 = { + years: -1, + months: -2, + weeks: -3, + days: -4, + hours: -5, + minutes: -6, + seconds: -7, + milliseconds: -123, + microseconds: -456, + nanoseconds: -789, +}; + +const expected = partitionDurationFormatPattern(duration); + +const df = new Intl.DurationFormat("en"); +compare(df.formatToParts(duration), expected, `Using style : default`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js new file mode 100644 index 0000000000..dc42b6591b --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js @@ -0,0 +1,49 @@ +// Copyright (C) 2023 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 "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 = { + years: -1, + months: -2, + weeks: -3, + days: -4, + hours: -5, + minutes: -6, + seconds: -7, + milliseconds: -123, + microseconds: -456, + nanoseconds: -789, +}; + +const expected = partitionDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", { style }); +compare(df.formatToParts(duration), expected, `Using style : ${style}`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js new file mode 100644 index 0000000000..58f16514e7 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js @@ -0,0 +1,49 @@ +// Copyright (C) 2023 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 "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 = { + years: -1, + months: -2, + weeks: -3, + days: -4, + hours: -5, + minutes: -6, + seconds: -7, + milliseconds: -123, + microseconds: -456, + nanoseconds: -789, +}; + +const expected = partitionDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", { style }); +compare(df.formatToParts(duration), expected, `Using style : ${style}`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js new file mode 100644 index 0000000000..8aca8b8568 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js @@ -0,0 +1,49 @@ +// Copyright (C) 2023 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 "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 = { + years: -1, + months: -2, + weeks: -3, + days: -4, + hours: -5, + minutes: -6, + seconds: -7, + milliseconds: -123, + microseconds: -456, + nanoseconds: -789, +}; + +const expected = partitionDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", { style }); +compare(df.formatToParts(duration), expected, `Using style : ${style}`); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js new file mode 100644 index 0000000000..44d1b75e3c --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js @@ -0,0 +1,49 @@ +// Copyright (C) 2023 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 "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 = { + years: -1, + months: -2, + weeks: -3, + days: -4, + hours: -5, + minutes: -6, + seconds: -7, + milliseconds: -123, + microseconds: -456, + nanoseconds: -789, +}; + +const expected = partitionDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", { style }); +compare(df.formatToParts(duration), expected, `Using style : ${style}`);