mirror of
https://github.com/tc39/test262.git
synced 2025-07-25 15:04:43 +02:00
Split DurationFormat style tests
For better parallization and reporting
This commit is contained in:
parent
92500bfffb
commit
4fda9c4c01
27
test/intl402/DurationFormat/prototype/format/style-default-en.js
vendored
Normal file
27
test/intl402/DurationFormat/prototype/format/style-default-en.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2022 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 different "style" arguments
|
||||||
|
locale: [en-US]
|
||||||
|
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 df = new Intl.DurationFormat("en");
|
||||||
|
const expected = "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns";
|
||||||
|
assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using default style option`);
|
28
test/intl402/DurationFormat/prototype/format/style-digital-en.js
vendored
Normal file
28
test/intl402/DurationFormat/prototype/format/style-digital-en.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2022 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 different "style" arguments
|
||||||
|
locale: [en-US]
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const style = "digital";
|
||||||
|
const expected = "1 yr 2 mths 3 wks 3 days 4:05:06";
|
||||||
|
|
||||||
|
const duration = {
|
||||||
|
years: 1,
|
||||||
|
months: 2,
|
||||||
|
weeks: 3,
|
||||||
|
days: 3,
|
||||||
|
hours: 4,
|
||||||
|
minutes: 5,
|
||||||
|
seconds: 6,
|
||||||
|
milliseconds: 7,
|
||||||
|
microseconds: 8,
|
||||||
|
nanoseconds: 9,
|
||||||
|
};
|
||||||
|
|
||||||
|
const df = new Intl.DurationFormat("en", {style});
|
||||||
|
assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`);
|
28
test/intl402/DurationFormat/prototype/format/style-long-en.js
vendored
Normal file
28
test/intl402/DurationFormat/prototype/format/style-long-en.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2022 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 different "style" arguments
|
||||||
|
locale: [en-US]
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const style = "long";
|
||||||
|
const expected = "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, 9 nanoseconds";
|
||||||
|
|
||||||
|
const duration = {
|
||||||
|
years: 1,
|
||||||
|
months: 2,
|
||||||
|
weeks: 3,
|
||||||
|
days: 3,
|
||||||
|
hours: 4,
|
||||||
|
minutes: 5,
|
||||||
|
seconds: 6,
|
||||||
|
milliseconds: 7,
|
||||||
|
microseconds: 8,
|
||||||
|
nanoseconds: 9,
|
||||||
|
};
|
||||||
|
|
||||||
|
const df = new Intl.DurationFormat("en", {style});
|
||||||
|
assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`);
|
28
test/intl402/DurationFormat/prototype/format/style-narrow-en.js
vendored
Normal file
28
test/intl402/DurationFormat/prototype/format/style-narrow-en.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2022 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 different "style" arguments
|
||||||
|
locale: [en-US]
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const style = "narrow";
|
||||||
|
const expected = "1y 2m 3w 3d 4h 5m 6s 7ms 8μs 9ns";
|
||||||
|
|
||||||
|
const duration = {
|
||||||
|
years: 1,
|
||||||
|
months: 2,
|
||||||
|
weeks: 3,
|
||||||
|
days: 3,
|
||||||
|
hours: 4,
|
||||||
|
minutes: 5,
|
||||||
|
seconds: 6,
|
||||||
|
milliseconds: 7,
|
||||||
|
microseconds: 8,
|
||||||
|
nanoseconds: 9,
|
||||||
|
};
|
||||||
|
|
||||||
|
const df = new Intl.DurationFormat("en", {style});
|
||||||
|
assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`);
|
@ -1,37 +0,0 @@
|
|||||||
// Copyright 2022 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 different "style" arguments
|
|
||||||
locale: [en-US]
|
|
||||||
features: [Intl.DurationFormat]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const testData = {
|
|
||||||
"long" : "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, 9 nanoseconds",
|
|
||||||
"short": "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns",
|
|
||||||
"narrow":"1y 2m 3w 3d 4h 5m 6s 7ms 8μs 9ns",
|
|
||||||
"digital":"1 yr 2 mths 3 wks 3 days 4:05:06",
|
|
||||||
}
|
|
||||||
|
|
||||||
const duration = {
|
|
||||||
years: 1,
|
|
||||||
months: 2,
|
|
||||||
weeks: 3,
|
|
||||||
days: 3,
|
|
||||||
hours: 4,
|
|
||||||
minutes: 5,
|
|
||||||
seconds: 6,
|
|
||||||
milliseconds: 7,
|
|
||||||
microseconds: 8,
|
|
||||||
nanoseconds: 9,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
for (const style in testData) {
|
|
||||||
const df = new Intl.DurationFormat("en", {style});
|
|
||||||
const expected = testData[style];
|
|
||||||
assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`);
|
|
||||||
}
|
|
||||||
|
|
28
test/intl402/DurationFormat/prototype/format/style-short-en.js
vendored
Normal file
28
test/intl402/DurationFormat/prototype/format/style-short-en.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2022 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 different "style" arguments
|
||||||
|
locale: [en-US]
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const style = "short";
|
||||||
|
const expected = "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns";
|
||||||
|
|
||||||
|
const duration = {
|
||||||
|
years: 1,
|
||||||
|
months: 2,
|
||||||
|
weeks: 3,
|
||||||
|
days: 3,
|
||||||
|
hours: 4,
|
||||||
|
minutes: 5,
|
||||||
|
seconds: 6,
|
||||||
|
milliseconds: 7,
|
||||||
|
microseconds: 8,
|
||||||
|
nanoseconds: 9,
|
||||||
|
};
|
||||||
|
|
||||||
|
const df = new Intl.DurationFormat("en", {style});
|
||||||
|
assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`);
|
67
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-default-en.js
vendored
Normal file
67
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-default-en.js
vendored
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright (C) 2023 Igalia S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.DurationFormat.prototype.formatToParts
|
||||||
|
description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Utils functions
|
||||||
|
function* zip(a, b) {
|
||||||
|
for (let i = 0; i < a.length; ++i) {
|
||||||
|
yield [i, a[i], b[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
||||||
|
// assertions
|
||||||
|
assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
|
||||||
|
assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
|
||||||
|
if (expectedEntry.unit) {
|
||||||
|
assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const duration = {
|
||||||
|
hours: 7,
|
||||||
|
minutes: 8,
|
||||||
|
seconds: 9,
|
||||||
|
milliseconds: 123,
|
||||||
|
microseconds: 456,
|
||||||
|
nanoseconds: 789,
|
||||||
|
};
|
||||||
|
|
||||||
|
const expected = [
|
||||||
|
{ type: "integer", value: "7", unit: "hour" },
|
||||||
|
{ type: "literal", value: " ", unit: "hour" },
|
||||||
|
{ type: "unit", value: "hr", unit: "hour" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "8", unit: "minute" },
|
||||||
|
{ type: "literal", value: " ", unit: "minute" },
|
||||||
|
{ type: "unit", value: "min", unit: "minute" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "9", unit: "second" },
|
||||||
|
{ type: "literal", value: " ", unit: "second" },
|
||||||
|
{ type: "unit", value: "sec", unit: "second" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "123", unit: "millisecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "millisecond" },
|
||||||
|
{ type: "unit", value: "msec", unit: "millisecond" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "456", unit: "microsecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "microsecond" },
|
||||||
|
{ type: "unit", value: "μsec", unit: "microsecond" },
|
||||||
|
{ type: "literal", value: " and " },
|
||||||
|
{ type: "integer", value: "789", unit: "nanosecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "nanosecond" },
|
||||||
|
{ type: "unit", value: "nsec", unit: "nanosecond" },
|
||||||
|
];
|
||||||
|
|
||||||
|
let df = new Intl.DurationFormat('en');
|
||||||
|
compare(df.formatToParts(duration), expected, `Using style : default`);
|
50
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-digital-en.js
vendored
Normal file
50
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-digital-en.js
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (C) 2023 Igalia S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.DurationFormat.prototype.formatToParts
|
||||||
|
description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Utils functions
|
||||||
|
function* zip(a, b) {
|
||||||
|
for (let i = 0; i < a.length; ++i) {
|
||||||
|
yield [i, a[i], b[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
||||||
|
// assertions
|
||||||
|
assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
|
||||||
|
assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
|
||||||
|
if (expectedEntry.unit) {
|
||||||
|
assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const duration = {
|
||||||
|
hours: 7,
|
||||||
|
minutes: 8,
|
||||||
|
seconds: 9,
|
||||||
|
milliseconds: 123,
|
||||||
|
microseconds: 456,
|
||||||
|
nanoseconds: 789,
|
||||||
|
};
|
||||||
|
|
||||||
|
const style = "digital";
|
||||||
|
const expected = [
|
||||||
|
{ type: "integer", value: "7", unit: "hour" },
|
||||||
|
{ type: "literal", value: ":", unit: "hour" },
|
||||||
|
{ type: "integer", value: "08", unit: "minute" },
|
||||||
|
{ type: "literal", value: ":", unit: "minute" },
|
||||||
|
{ type: "integer", value: "09", unit: "second" },
|
||||||
|
];
|
||||||
|
|
||||||
|
let df = new Intl.DurationFormat('en', { style });
|
||||||
|
compare(df.formatToParts(duration), expected, `Using style : ${style}`);
|
68
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-long-en.js
vendored
Normal file
68
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-long-en.js
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// Copyright (C) 2023 Igalia S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.DurationFormat.prototype.formatToParts
|
||||||
|
description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Utils functions
|
||||||
|
function* zip(a, b) {
|
||||||
|
for (let i = 0; i < a.length; ++i) {
|
||||||
|
yield [i, a[i], b[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
||||||
|
// assertions
|
||||||
|
assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
|
||||||
|
assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
|
||||||
|
if (expectedEntry.unit) {
|
||||||
|
assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const duration = {
|
||||||
|
hours: 7,
|
||||||
|
minutes: 8,
|
||||||
|
seconds: 9,
|
||||||
|
milliseconds: 123,
|
||||||
|
microseconds: 456,
|
||||||
|
nanoseconds: 789,
|
||||||
|
};
|
||||||
|
|
||||||
|
const style = "long";
|
||||||
|
const expected = [
|
||||||
|
{ type: "integer", value: "7", unit: "hour" },
|
||||||
|
{ type: "literal", value: " ", unit: "hour" },
|
||||||
|
{ type: "unit", value: "hours", unit: "hour" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "8", unit: "minute" },
|
||||||
|
{ type: "literal", value: " ", unit: "minute" },
|
||||||
|
{ type: "unit", value: "minutes", unit: "minute" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "9", unit: "second" },
|
||||||
|
{ type: "literal", value: " ", unit: "second" },
|
||||||
|
{ type: "unit", value: "seconds", unit: "second" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "123", unit: "millisecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "millisecond" },
|
||||||
|
{ type: "unit", value: "milliseconds", unit: "millisecond" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "456", unit: "microsecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "microsecond" },
|
||||||
|
{ type: "unit", value: "microseconds", unit: "microsecond" },
|
||||||
|
{ type: "literal", value: " and " },
|
||||||
|
{ type: "integer", value: "789", unit: "nanosecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "nanosecond" },
|
||||||
|
{ type: "unit", value: "nanoseconds", unit: "nanosecond" },
|
||||||
|
];
|
||||||
|
|
||||||
|
let df = new Intl.DurationFormat('en', { style });
|
||||||
|
compare(df.formatToParts(duration), expected, `Using style : ${style}`);
|
62
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-narrow-en.js
vendored
Normal file
62
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-narrow-en.js
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (C) 2023 Igalia S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.DurationFormat.prototype.formatToParts
|
||||||
|
description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Utils functions
|
||||||
|
function* zip(a, b) {
|
||||||
|
for (let i = 0; i < a.length; ++i) {
|
||||||
|
yield [i, a[i], b[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
||||||
|
// assertions
|
||||||
|
assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
|
||||||
|
assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
|
||||||
|
if (expectedEntry.unit) {
|
||||||
|
assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const duration = {
|
||||||
|
hours: 7,
|
||||||
|
minutes: 8,
|
||||||
|
seconds: 9,
|
||||||
|
milliseconds: 123,
|
||||||
|
microseconds: 456,
|
||||||
|
nanoseconds: 789,
|
||||||
|
};
|
||||||
|
|
||||||
|
const style = "narrow";
|
||||||
|
const expected = [
|
||||||
|
{ type: "integer", value: "7", unit: "hour" },
|
||||||
|
{ type: "unit", value: "h", unit: "hour" },
|
||||||
|
{ type: "literal", value: " " },
|
||||||
|
{ type: "integer", value: "8", unit: "minute" },
|
||||||
|
{ type: "unit", value: "m", unit: "minute" },
|
||||||
|
{ type: "literal", value: " " },
|
||||||
|
{ type: "integer", value: "9", unit: "second" },
|
||||||
|
{ type: "unit", value: "s", unit: "second" },
|
||||||
|
{ type: "literal", value: " " },
|
||||||
|
{ type: "integer", value: "123", unit: "millisecond" },
|
||||||
|
{ type: "unit", value: "ms", unit: "millisecond" },
|
||||||
|
{ type: "literal", value: " " },
|
||||||
|
{ type: "integer", value: "456", unit: "microsecond" },
|
||||||
|
{ type: "unit", value: "μs", unit: "microsecond" },
|
||||||
|
{ type: "literal", value: " " },
|
||||||
|
{ type: "integer", value: "789", unit: "nanosecond" },
|
||||||
|
{ type: "unit", value: "ns", unit: "nanosecond" },
|
||||||
|
];
|
||||||
|
|
||||||
|
let df = new Intl.DurationFormat('en', { style });
|
||||||
|
compare(df.formatToParts(duration), expected, `Using style : ${style}`);
|
68
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-short-en.js
vendored
Normal file
68
test/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-short-en.js
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// Copyright (C) 2023 Igalia S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.DurationFormat.prototype.formatToParts
|
||||||
|
description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
|
||||||
|
features: [Intl.DurationFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Utils functions
|
||||||
|
function* zip(a, b) {
|
||||||
|
for (let i = 0; i < a.length; ++i) {
|
||||||
|
yield [i, a[i], b[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
||||||
|
// assertions
|
||||||
|
assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
|
||||||
|
assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
|
||||||
|
if (expectedEntry.unit) {
|
||||||
|
assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const duration = {
|
||||||
|
hours: 7,
|
||||||
|
minutes: 8,
|
||||||
|
seconds: 9,
|
||||||
|
milliseconds: 123,
|
||||||
|
microseconds: 456,
|
||||||
|
nanoseconds: 789,
|
||||||
|
};
|
||||||
|
|
||||||
|
const style = "short";
|
||||||
|
const expected = [
|
||||||
|
{ type: "integer", value: "7", unit: "hour" },
|
||||||
|
{ type: "literal", value: " ", unit: "hour" },
|
||||||
|
{ type: "unit", value: "hr", unit: "hour" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "8", unit: "minute" },
|
||||||
|
{ type: "literal", value: " ", unit: "minute" },
|
||||||
|
{ type: "unit", value: "min", unit: "minute" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "9", unit: "second" },
|
||||||
|
{ type: "literal", value: " ", unit: "second" },
|
||||||
|
{ type: "unit", value: "sec", unit: "second" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "123", unit: "millisecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "millisecond" },
|
||||||
|
{ type: "unit", value: "msec", unit: "millisecond" },
|
||||||
|
{ type: "literal", value: ", " },
|
||||||
|
{ type: "integer", value: "456", unit: "microsecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "microsecond" },
|
||||||
|
{ type: "unit", value: "μsec", unit: "microsecond" },
|
||||||
|
{ type: "literal", value: " and " },
|
||||||
|
{ type: "integer", value: "789", unit: "nanosecond" },
|
||||||
|
{ type: "literal", value: " ", unit: "nanosecond" },
|
||||||
|
{ type: "unit", value: "nsec", unit: "nanosecond" },
|
||||||
|
];
|
||||||
|
|
||||||
|
let df = new Intl.DurationFormat('en', { style });
|
||||||
|
compare(df.formatToParts(duration), expected, `Using style : ${style}`);
|
@ -1,122 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-Intl.DurationFormat.prototype.formatToParts
|
|
||||||
description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
|
|
||||||
features: [Intl.DurationFormat]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
// Utils functions
|
|
||||||
function* zip(a, b) {
|
|
||||||
for (let i = 0; i < a.length; ++i) {
|
|
||||||
yield [i, a[i], b[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
|
||||||
// assertions
|
|
||||||
assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
|
|
||||||
assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
|
|
||||||
if (expectedEntry.unit) {
|
|
||||||
assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const duration = {
|
|
||||||
hours: 7,
|
|
||||||
minutes: 8,
|
|
||||||
seconds: 9,
|
|
||||||
milliseconds: 123,
|
|
||||||
microseconds: 456,
|
|
||||||
nanoseconds: 789,
|
|
||||||
};
|
|
||||||
|
|
||||||
const testsData = {
|
|
||||||
short: [
|
|
||||||
{ type: "integer", value: "7", unit: "hour" },
|
|
||||||
{ type: "literal", value: " ", unit: "hour" },
|
|
||||||
{ type: "unit", value: "hr", unit: "hour" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "8", unit: "minute" },
|
|
||||||
{ type: "literal", value: " ", unit: "minute" },
|
|
||||||
{ type: "unit", value: "min", unit: "minute" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "9", unit: "second" },
|
|
||||||
{ type: "literal", value: " ", unit: "second" },
|
|
||||||
{ type: "unit", value: "sec", unit: "second" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "123", unit: "millisecond" },
|
|
||||||
{ type: "literal", value: " ", unit: "millisecond" },
|
|
||||||
{ type: "unit", value: "msec", unit: "millisecond" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "456", unit: "microsecond" },
|
|
||||||
{ type: "literal", value: " ", unit: "microsecond" },
|
|
||||||
{ type: "unit", value: "μsec", unit: "microsecond" },
|
|
||||||
{ type: "literal", value: " and " },
|
|
||||||
{ type: "integer", value: "789", unit: "nanosecond" },
|
|
||||||
{ type: "literal", value: " ", unit: "nanosecond" },
|
|
||||||
{ type: "unit", value: "nsec", unit: "nanosecond" },
|
|
||||||
],
|
|
||||||
long: [
|
|
||||||
{ type: "integer", value: "7", unit: "hour" },
|
|
||||||
{ type: "literal", value: " ", unit: "hour" },
|
|
||||||
{ type: "unit", value: "hours", unit: "hour" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "8", unit: "minute" },
|
|
||||||
{ type: "literal", value: " ", unit: "minute" },
|
|
||||||
{ type: "unit", value: "minutes", unit: "minute" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "9", unit: "second" },
|
|
||||||
{ type: "literal", value: " ", unit: "second" },
|
|
||||||
{ type: "unit", value: "seconds", unit: "second" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "123", unit: "millisecond" },
|
|
||||||
{ type: "literal", value: " ", unit: "millisecond" },
|
|
||||||
{ type: "unit", value: "milliseconds", unit: "millisecond" },
|
|
||||||
{ type: "literal", value: ", " },
|
|
||||||
{ type: "integer", value: "456", unit: "microsecond" },
|
|
||||||
{ type: "literal", value: " ", unit: "microsecond" },
|
|
||||||
{ type: "unit", value: "microseconds", unit: "microsecond" },
|
|
||||||
{ type: "literal", value: " and " },
|
|
||||||
{ type: "integer", value: "789", unit: "nanosecond" },
|
|
||||||
{ type: "literal", value: " ", unit: "nanosecond" },
|
|
||||||
{ type: "unit", value: "nanoseconds", unit: "nanosecond" },
|
|
||||||
],
|
|
||||||
narrow: [
|
|
||||||
{ type: "integer", value: "7", unit: "hour" },
|
|
||||||
{ type: "unit", value: "h", unit: "hour" },
|
|
||||||
{ type: "literal", value: " " },
|
|
||||||
{ type: "integer", value: "8", unit: "minute" },
|
|
||||||
{ type: "unit", value: "m", unit: "minute" },
|
|
||||||
{ type: "literal", value: " " },
|
|
||||||
{ type: "integer", value: "9", unit: "second" },
|
|
||||||
{ type: "unit", value: "s", unit: "second" },
|
|
||||||
{ type: "literal", value: " " },
|
|
||||||
{ type: "integer", value: "123", unit: "millisecond" },
|
|
||||||
{ type: "unit", value: "ms", unit: "millisecond" },
|
|
||||||
{ type: "literal", value: " " },
|
|
||||||
{ type: "integer", value: "456", unit: "microsecond" },
|
|
||||||
{ type: "unit", value: "μs", unit: "microsecond" },
|
|
||||||
{ type: "literal", value: " " },
|
|
||||||
{ type: "integer", value: "789", unit: "nanosecond" },
|
|
||||||
{ type: "unit", value: "ns", unit: "nanosecond" },
|
|
||||||
],
|
|
||||||
digital: [
|
|
||||||
{ type: "integer", value: "7", unit: "hour" },
|
|
||||||
{ type: "literal", value: ":", unit: "hour" },
|
|
||||||
{ type: "integer", value: "08", unit: "minute" },
|
|
||||||
{ type: "literal", value: ":", unit: "minute" },
|
|
||||||
{ type: "integer", value: "09", unit: "second" },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const style in testsData) {
|
|
||||||
let df = new Intl.DurationFormat('en', { style });
|
|
||||||
compare(df.formatToParts(duration), testsData[style], `Using style : ${style}`);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user