Unified Intl.NumberFormat: Various tests (#2275)

* Unified Intl.NumberFormat: Test compact notation with various locales.

* Unified Intl.NumberFormat: Test compactDisplay constructor option.

* Unified Intl.NumberFormat: Test signDisplay constructor option.

* Unified Intl.NumberFormat: Test signDisplay with various locales.

* Unified Intl.NumberFormat: Test signDisplay with accounting currencySign in various locales.

* Unified Intl.NumberFormat: Test engineering and scientific notations in various locales.

* Unified Intl.NumberFormat: Test unit handling.

* Unified Intl.NumberFormat: Test notation constructor option.

* Unified Intl.NumberFormat: Test engineering and scientific notations with negative exponents.

* Unified Intl.NumberFormat: Test near-zero arguments with signDisplay.

* Unified Intl.NumberFormat: Test units.

* Unified Intl.NumberFormat: Test unit arguments.

* Unified Intl.NumberFormat: Add a generic test for unit arguments.

* Unified Intl.NumberFormat: Test the unitDisplay argument.
This commit is contained in:
Ms2ger 2019-08-14 18:47:05 +02:00 committed by Leo Balter
parent 3ff5c0a115
commit 70a07985a5
58 changed files with 3698 additions and 0 deletions

View File

@ -0,0 +1,44 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
info: |
InitializeNumberFormat ( numberFormat, locales, options )
19. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
20. If notation is "compact", then
a. Set numberFormat.[[CompactDisplay]] to compactDisplay.
includes: [compareArray.js]
features: [Intl.NumberFormat-unified]
---*/
const values = [
[undefined, "short"],
["short"],
["long"],
];
for (const [value, expected = value] of values) {
const callOrder = [];
const nf = new Intl.NumberFormat([], {
get notation() {
callOrder.push("notation");
return "compact";
},
get compactDisplay() {
callOrder.push("compactDisplay");
return value;
}
});
const resolvedOptions = nf.resolvedOptions();
assert.sameValue("compactDisplay" in resolvedOptions, true);
assert.sameValue(resolvedOptions.compactDisplay, expected);
assert.compareArray(callOrder, [
"notation",
"compactDisplay",
]);
}

View File

@ -0,0 +1,53 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
info: |
InitializeNumberFormat ( numberFormat, locales, options )
19. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
20. If notation is "compact", then
a. Set numberFormat.[[CompactDisplay]] to compactDisplay.
includes: [compareArray.js]
features: [Intl.NumberFormat-unified]
---*/
const values = [
[undefined, "short"],
["short"],
["long"],
];
const notations = [
undefined,
"standard",
"scientific",
"engineering",
];
for (const notation of notations) {
for (const [value, expected = value] of values) {
const callOrder = [];
const nf = new Intl.NumberFormat([], {
get notation() {
callOrder.push("notation");
return notation;
},
get compactDisplay() {
callOrder.push("compactDisplay");
return value;
}
});
const resolvedOptions = nf.resolvedOptions();
assert.sameValue("compactDisplay" in resolvedOptions, false);
assert.sameValue(resolvedOptions.compactDisplay, undefined);
assert.compareArray(callOrder, [
"notation",
"compactDisplay",
]);
}
}

View File

@ -0,0 +1,31 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: Checks handling of the notation option to the NumberFormat constructor.
info: |
InitializeNumberFormat ( numberFormat, locales, options )
16. Let notation be ? GetOption(options, "notation", "string", « "standard", "scientific", "engineering", "compact" », "standard").
17. Set numberFormat.[[Notation]] to notation.
features: [Intl.NumberFormat-unified]
---*/
const values = [
[undefined, "standard"],
["standard"],
["scientific"],
["engineering"],
["compact"],
];
for (const [value, expected = value] of values) {
const nf = new Intl.NumberFormat([], {
notation: value,
});
const resolvedOptions = nf.resolvedOptions();
assert.sameValue("notation" in resolvedOptions, true);
assert.sameValue(resolvedOptions.notation, expected);
}

View File

@ -0,0 +1,31 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
info: |
InitializeNumberFormat ( numberFormat, locales, options )
23. Let signDisplay be ? GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero" », "auto").
24. Set numberFormat.[[SignDisplay]] to signDisplay.
features: [Intl.NumberFormat-unified]
---*/
const values = [
[undefined, "auto"],
["auto"],
["never"],
["always"],
["exceptZero"],
];
for (const [value, expected = value] of values) {
const nf = new Intl.NumberFormat([], {
signDisplay: value,
});
const resolvedOptions = nf.resolvedOptions();
assert.sameValue("signDisplay" in resolvedOptions, true);
assert.sameValue(resolvedOptions.signDisplay, expected);
}

View File

@ -0,0 +1,40 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: Checks handling of the unit style.
features: [Intl.NumberFormat-unified]
---*/
assert.throws(TypeError, () => {
new Intl.NumberFormat([], {
style: "unit",
})
});
for (const unit of [undefined, "test", "MILE", "kB"]) {
assert.throws(unit === undefined ? TypeError : RangeError, () => {
new Intl.NumberFormat([], {
style: "unit",
unit,
})
});
for (const style of [undefined, "decimal", "currency"]) {
let called = 0;
const nf = new Intl.NumberFormat([], {
style,
get unit() { ++called; return unit; },
currency: "USD",
});
assert.sameValue(nf.resolvedOptions().unit, undefined);
assert.sameValue(called, 1);
}
}
const nf = new Intl.NumberFormat([], {
style: "percent",
});
assert.sameValue(nf.resolvedOptions().style, "percent");
assert.sameValue(nf.resolvedOptions().unit, undefined);

View File

@ -0,0 +1,32 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
info: |
InitializeNumberFormat ( numberFormat, locales, options )
23. Let signDisplay be ? GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero" », "auto").
24. Set numberFormat.[[SignDisplay]] to signDisplay.
features: [Intl.NumberFormat-unified]
---*/
const values = [
[undefined, "short"],
["short"],
["narrow"],
["long"],
];
for (const [value, expected = value] of values) {
const nf = new Intl.NumberFormat([], {
style: "unit",
unitDisplay: value,
unit: "hour",
});
const resolvedOptions = nf.resolvedOptions();
assert.sameValue("unitDisplay" in resolvedOptions, true);
assert.sameValue(resolvedOptions.unitDisplay, expected);
}

View File

@ -0,0 +1,61 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the engineering and scientific notations.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"0.000345",
"345E-6",
"3,45E-4",
],
[
"0.345",
"345E-3",
"3,45E-1",
],
[
"3.45",
"3,45E0",
"3,45E0",
],
[
"34.5",
"34,5E0",
"3,45E1",
],
[
"543",
"543E0",
"5,43E2",
],
[
"5430",
"5,43E3",
"5,43E3",
],
[
"543000",
"543E3",
"5,43E5",
],
[
"543211.1",
"543,211E3",
"5,432E5",
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("de-DE", { notation: "engineering" }));
assert.sameValue(nfEngineering.format(number), engineering);
const nfScientific = (new Intl.NumberFormat("de-DE", { notation: "scientific" }));
assert.sameValue(nfScientific.format(number), scientific);
}

View File

@ -0,0 +1,61 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the engineering and scientific notations.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"0.000345",
"345E-6",
"3.45E-4",
],
[
"0.345",
"345E-3",
"3.45E-1",
],
[
"3.45",
"3.45E0",
"3.45E0",
],
[
"34.5",
"34.5E0",
"3.45E1",
],
[
"543",
"543E0",
"5.43E2",
],
[
"5430",
"5.43E3",
"5.43E3",
],
[
"543000",
"543E3",
"5.43E5",
],
[
"543211.1",
"543.211E3",
"5.432E5",
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("en-US", { notation: "engineering" }));
assert.sameValue(nfEngineering.format(number), engineering);
const nfScientific = (new Intl.NumberFormat("en-US", { notation: "scientific" }));
assert.sameValue(nfScientific.format(number), scientific);
}

View File

@ -0,0 +1,61 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the engineering and scientific notations.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"0.000345",
"345E-6",
"3.45E-4",
],
[
"0.345",
"345E-3",
"3.45E-1",
],
[
"3.45",
"3.45E0",
"3.45E0",
],
[
"34.5",
"34.5E0",
"3.45E1",
],
[
"543",
"543E0",
"5.43E2",
],
[
"5430",
"5.43E3",
"5.43E3",
],
[
"543000",
"543E3",
"5.43E5",
],
[
"543211.1",
"543.211E3",
"5.432E5",
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("ja-JP", { notation: "engineering" }));
assert.sameValue(nfEngineering.format(number), engineering);
const nfScientific = (new Intl.NumberFormat("ja-JP", { notation: "scientific" }));
assert.sameValue(nfScientific.format(number), scientific);
}

View File

@ -0,0 +1,61 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the engineering and scientific notations.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"0.000345",
"345E-6",
"3.45E-4",
],
[
"0.345",
"345E-3",
"3.45E-1",
],
[
"3.45",
"3.45E0",
"3.45E0",
],
[
"34.5",
"34.5E0",
"3.45E1",
],
[
"543",
"543E0",
"5.43E2",
],
[
"5430",
"5.43E3",
"5.43E3",
],
[
"543000",
"543E3",
"5.43E5",
],
[
"543211.1",
"543.211E3",
"5.432E5",
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("ko-KR", { notation: "engineering" }));
assert.sameValue(nfEngineering.format(number), engineering);
const nfScientific = (new Intl.NumberFormat("ko-KR", { notation: "scientific" }));
assert.sameValue(nfScientific.format(number), scientific);
}

View File

@ -0,0 +1,61 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the engineering and scientific notations.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"0.000345",
"345E-6",
"3.45E-4",
],
[
"0.345",
"345E-3",
"3.45E-1",
],
[
"3.45",
"3.45E0",
"3.45E0",
],
[
"34.5",
"34.5E0",
"3.45E1",
],
[
"543",
"543E0",
"5.43E2",
],
[
"5430",
"5.43E3",
"5.43E3",
],
[
"543000",
"543E3",
"5.43E5",
],
[
"543211.1",
"543.211E3",
"5.432E5",
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("zh-TW", { notation: "engineering" }));
assert.sameValue(nfEngineering.format(number), engineering);
const nfScientific = (new Intl.NumberFormat("zh-TW", { notation: "scientific" }));
assert.sameValue(nfScientific.format(number), scientific);
}

View File

@ -0,0 +1,40 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
const nfShort = new Intl.NumberFormat("de-DE", {
notation: "compact",
compactDisplay: "short",
});
assert.sameValue(nfShort.format(987654321), "988\u00a0Mio.");
assert.sameValue(nfShort.format(98765432), "99\u00a0Mio.");
assert.sameValue(nfShort.format(98765), "98.765");
assert.sameValue(nfShort.format(9876), "9876");
assert.sameValue(nfShort.format(159), "159");
assert.sameValue(nfShort.format(15.9), "16");
assert.sameValue(nfShort.format(1.59), "1,6");
assert.sameValue(nfShort.format(0.159), "0,16");
assert.sameValue(nfShort.format(0.0159), "0,016");
assert.sameValue(nfShort.format(0.00159), "0,0016");
const nfLong = new Intl.NumberFormat("de-DE", {
notation: "compact",
compactDisplay: "long",
});
assert.sameValue(nfLong.format(987654321), "988 Millionen");
assert.sameValue(nfLong.format(98765432), "99 Millionen");
assert.sameValue(nfLong.format(98765), "99 Tausend");
assert.sameValue(nfLong.format(9876), "9,9 Tausend");
assert.sameValue(nfLong.format(159), "159");
assert.sameValue(nfLong.format(15.9), "16");
assert.sameValue(nfLong.format(1.59), "1,6");
assert.sameValue(nfLong.format(0.159), "0,16");
assert.sameValue(nfLong.format(0.0159), "0,016");
assert.sameValue(nfLong.format(0.00159), "0,0016");

View File

@ -0,0 +1,39 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
const nfShort = new Intl.NumberFormat("en-US", {
notation: "compact",
compactDisplay: "short",
});
assert.sameValue(nfShort.format(987654321), "988M");
assert.sameValue(nfShort.format(98765432), "99M");
assert.sameValue(nfShort.format(98765), "99K");
assert.sameValue(nfShort.format(9876), "9.9K");
assert.sameValue(nfShort.format(159), "159");
assert.sameValue(nfShort.format(15.9), "16");
assert.sameValue(nfShort.format(1.59), "1.6");
assert.sameValue(nfShort.format(0.159), "0.16");
assert.sameValue(nfShort.format(0.0159), "0.016");
assert.sameValue(nfShort.format(0.00159), "0.0016");
const nfLong = new Intl.NumberFormat("en-US", {
notation: "compact",
compactDisplay: "long",
});
assert.sameValue(nfLong.format(987654321), "988 million");
assert.sameValue(nfLong.format(98765432), "99 million");
assert.sameValue(nfLong.format(98765), "99 thousand");
assert.sameValue(nfLong.format(9876), "9.9 thousand");
assert.sameValue(nfLong.format(159), "159");
assert.sameValue(nfLong.format(15.9), "16");
assert.sameValue(nfLong.format(1.59), "1.6");
assert.sameValue(nfLong.format(0.159), "0.16");
assert.sameValue(nfLong.format(0.0159), "0.016");
assert.sameValue(nfLong.format(0.00159), "0.0016");

View File

@ -0,0 +1,39 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
const nfShort = new Intl.NumberFormat("ja-JP", {
notation: "compact",
compactDisplay: "short",
});
assert.sameValue(nfShort.format(987654321), "9.9億");
assert.sameValue(nfShort.format(98765432), "9877万");
assert.sameValue(nfShort.format(98765), "9.9万");
assert.sameValue(nfShort.format(9876), "9876");
assert.sameValue(nfShort.format(159), "159");
assert.sameValue(nfShort.format(15.9), "16");
assert.sameValue(nfShort.format(1.59), "1.6");
assert.sameValue(nfShort.format(0.159), "0.16");
assert.sameValue(nfShort.format(0.0159), "0.016");
assert.sameValue(nfShort.format(0.00159), "0.0016");
const nfLong = new Intl.NumberFormat("ja-JP", {
notation: "compact",
compactDisplay: "long",
});
assert.sameValue(nfLong.format(987654321), "9.9億");
assert.sameValue(nfLong.format(98765432), "9877万");
assert.sameValue(nfLong.format(98765), "9.9万");
assert.sameValue(nfLong.format(9876), "9876");
assert.sameValue(nfLong.format(159), "159");
assert.sameValue(nfLong.format(15.9), "16");
assert.sameValue(nfLong.format(1.59), "1.6");
assert.sameValue(nfLong.format(0.159), "0.16");
assert.sameValue(nfLong.format(0.0159), "0.016");
assert.sameValue(nfLong.format(0.00159), "0.0016");

View File

@ -0,0 +1,39 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
const nfShort = new Intl.NumberFormat("ko-KR", {
notation: "compact",
compactDisplay: "short",
});
assert.sameValue(nfShort.format(987654321), "9.9억");
assert.sameValue(nfShort.format(98765432), "9877만");
assert.sameValue(nfShort.format(98765), "9.9만");
assert.sameValue(nfShort.format(9876), "9.9천");
assert.sameValue(nfShort.format(159), "159");
assert.sameValue(nfShort.format(15.9), "16");
assert.sameValue(nfShort.format(1.59), "1.6");
assert.sameValue(nfShort.format(0.159), "0.16");
assert.sameValue(nfShort.format(0.0159), "0.016");
assert.sameValue(nfShort.format(0.00159), "0.0016");
const nfLong = new Intl.NumberFormat("ko-KR", {
notation: "compact",
compactDisplay: "long",
});
assert.sameValue(nfLong.format(987654321), "9.9억");
assert.sameValue(nfLong.format(98765432), "9877만");
assert.sameValue(nfLong.format(98765), "9.9만");
assert.sameValue(nfLong.format(9876), "9.9천");
assert.sameValue(nfLong.format(159), "159");
assert.sameValue(nfLong.format(15.9), "16");
assert.sameValue(nfLong.format(1.59), "1.6");
assert.sameValue(nfLong.format(0.159), "0.16");
assert.sameValue(nfLong.format(0.0159), "0.016");
assert.sameValue(nfLong.format(0.00159), "0.0016");

View File

@ -0,0 +1,39 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
const nfShort = new Intl.NumberFormat("zh-TW", {
notation: "compact",
compactDisplay: "short",
});
assert.sameValue(nfShort.format(987654321), "9.9億");
assert.sameValue(nfShort.format(98765432), "9877萬");
assert.sameValue(nfShort.format(98765), "9.9萬");
assert.sameValue(nfShort.format(9876), "9876");
assert.sameValue(nfShort.format(159), "159");
assert.sameValue(nfShort.format(15.9), "16");
assert.sameValue(nfShort.format(1.59), "1.6");
assert.sameValue(nfShort.format(0.159), "0.16");
assert.sameValue(nfShort.format(0.0159), "0.016");
assert.sameValue(nfShort.format(0.00159), "0.0016");
const nfLong = new Intl.NumberFormat("zh-TW", {
notation: "compact",
compactDisplay: "long",
});
assert.sameValue(nfLong.format(987654321), "9.9億");
assert.sameValue(nfLong.format(98765432), "9877萬");
assert.sameValue(nfLong.format(98765), "9.9萬");
assert.sameValue(nfLong.format(9876), "9876");
assert.sameValue(nfLong.format(159), "159");
assert.sameValue(nfLong.format(15.9), "16");
assert.sameValue(nfLong.format(1.59), "1.6");
assert.sameValue(nfLong.format(0.159), "0.16");
assert.sameValue(nfLong.format(0.0159), "0.016");
assert.sameValue(nfLong.format(0.00159), "0.0016");

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"-987,00 $",
"-0,00 $",
"-0,00 $",
"0,00 $",
"0,00 $",
"987,00 $",
],
[
"always",
"-987,00 $",
"-0,00 $",
"-0,00 $",
"+0,00 $",
"+0,00 $",
"+987,00 $",
],
[
"never",
"987,00 $",
"0,00 $",
"0,00 $",
"0,00 $",
"0,00 $",
"987,00 $",
],
[
"exceptZero",
"-987,00 $",
"-0,00 $",
"-0,00 $",
"0,00 $",
"+0,00 $",
"+987,00 $",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("de-DE", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"($987.00)",
"($0.00)",
"($0.00)",
"$0.00",
"$0.00",
"$987.00",
],
[
"always",
"($987.00)",
"($0.00)",
"($0.00)",
"+$0.00",
"+$0.00",
"+$987.00",
],
[
"never",
"$987.00",
"$0.00",
"$0.00",
"$0.00",
"$0.00",
"$987.00",
],
[
"exceptZero",
"($987.00)",
"($0.00)",
"($0.00)",
"$0.00",
"+$0.00",
"+$987.00",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"($987.00)",
"($0.00)",
"($0.00)",
"$0.00",
"$0.00",
"$987.00",
],
[
"always",
"($987.00)",
"($0.00)",
"($0.00)",
"+$0.00",
"+$0.00",
"+$987.00",
],
[
"never",
"$987.00",
"$0.00",
"$0.00",
"$0.00",
"$0.00",
"$987.00",
],
[
"exceptZero",
"($987.00)",
"($0.00)",
"($0.00)",
"$0.00",
"+$0.00",
"+$987.00",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ja-JP", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"(US$987.00)",
"(US$0.00)",
"(US$0.00)",
"US$0.00",
"US$0.00",
"US$987.00",
],
[
"always",
"(US$987.00)",
"(US$0.00)",
"(US$0.00)",
"+US$0.00",
"+US$0.00",
"+US$987.00",
],
[
"never",
"US$987.00",
"US$0.00",
"US$0.00",
"US$0.00",
"US$0.00",
"US$987.00",
],
[
"exceptZero",
"(US$987.00)",
"(US$0.00)",
"(US$0.00)",
"US$0.00",
"+US$0.00",
"+US$987.00",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ko-KR", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"(US$987.00)",
"(US$0.00)",
"(US$0.00)",
"US$0.00",
"US$0.00",
"US$987.00",
],
[
"always",
"(US$987.00)",
"(US$0.00)",
"(US$0.00)",
"+US$0.00",
"+US$0.00",
"+US$987.00",
],
[
"never",
"US$987.00",
"US$0.00",
"US$0.00",
"US$0.00",
"US$0.00",
"US$987.00",
],
[
"exceptZero",
"(US$987.00)",
"(US$0.00)",
"(US$0.00)",
"US$0.00",
"+US$0.00",
"+US$987.00",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("zh-TW", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"-987",
"-0",
"-0",
"0",
"0",
"987",
],
[
"always",
"-987",
"-0",
"-0",
"+0",
"+0",
"+987",
],
[
"never",
"987",
"0",
"0",
"0",
"0",
"987",
],
[
"exceptZero",
"-987",
"-0",
"-0",
"0",
"+0",
"+987",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("de-DE", {signDisplay});
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"-987",
"-0",
"-0",
"0",
"0",
"987",
],
[
"always",
"-987",
"-0",
"-0",
"+0",
"+0",
"+987",
],
[
"never",
"987",
"0",
"0",
"0",
"0",
"987",
],
[
"exceptZero",
"-987",
"-0",
"-0",
"0",
"+0",
"+987",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("en-US", {signDisplay});
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"-987",
"-0",
"-0",
"0",
"0",
"987",
],
[
"always",
"-987",
"-0",
"-0",
"+0",
"+0",
"+987",
],
[
"never",
"987",
"0",
"0",
"0",
"0",
"987",
],
[
"exceptZero",
"-987",
"-0",
"-0",
"0",
"+0",
"+987",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ja-JP", {signDisplay});
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"-987",
"-0",
"-0",
"0",
"0",
"987",
],
[
"always",
"-987",
"-0",
"-0",
"+0",
"+0",
"+987",
],
[
"never",
"987",
"0",
"0",
"0",
"0",
"987",
],
[
"exceptZero",
"-987",
"-0",
"-0",
"0",
"+0",
"+987",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ko-KR", {signDisplay});
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
"auto",
"-987",
"-0",
"-0",
"0",
"0",
"987",
],
[
"always",
"-987",
"-0",
"-0",
"+0",
"+0",
"+987",
],
[
"never",
"987",
"0",
"0",
"0",
"0",
"987",
],
[
"exceptZero",
"-987",
"-0",
"-0",
"0",
"+0",
"+987",
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("zh-TW", {signDisplay});
assert.sameValue(nf.format(-987), negative);
assert.sameValue(nf.format(-0.0001), negativeNearZero);
assert.sameValue(nf.format(-0), negativeZero);
assert.sameValue(nf.format(0), zero);
assert.sameValue(nf.format(0.0001), positiveNearZero);
assert.sameValue(nf.format(987), positive);
}

View File

@ -0,0 +1,69 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the unit style.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
-987,
{
"short": "-987 m",
"narrow": "-987 m",
"long": "-987 Meter",
}
],
[
-0.001,
{
"short": "-0,001 m",
"narrow": "-0,001 m",
"long": "-0,001 Meter",
}
],
[
-0,
{
"short": "-0 m",
"narrow": "-0 m",
"long": "-0 Meter",
}
],
[
0,
{
"short": "0 m",
"narrow": "0 m",
"long": "0 Meter",
}
],
[
0.001,
{
"short": "0,001 m",
"narrow": "0,001 m",
"long": "0,001 Meter",
}
],
[
987,
{
"short": "987 m",
"narrow": "987 m",
"long": "987 Meter",
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("de-DE", { style: "unit", unit: "meter", unitDisplay });
assert.sameValue(nf.format(number), expected);
}
}

View File

@ -0,0 +1,69 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the unit style.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
-987,
{
"short": "-987 m",
"narrow": "-987m",
"long": "-987 meters",
}
],
[
-0.001,
{
"short": "-0.001 m",
"narrow": "-0.001m",
"long": "-0.001 meters",
}
],
[
-0,
{
"short": "-0 m",
"narrow": "-0m",
"long": "-0 meters",
}
],
[
0,
{
"short": "0 m",
"narrow": "0m",
"long": "0 meters",
}
],
[
0.001,
{
"short": "0.001 m",
"narrow": "0.001m",
"long": "0.001 meters",
}
],
[
987,
{
"short": "987 m",
"narrow": "987m",
"long": "987 meters",
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("en-US", { style: "unit", unit: "meter", unitDisplay });
assert.sameValue(nf.format(number), expected);
}
}

View File

@ -0,0 +1,69 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the unit style.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
-987,
{
"short": "-987 m",
"narrow": "-987m",
"long": "-987 メートル",
}
],
[
-0.001,
{
"short": "-0.001 m",
"narrow": "-0.001m",
"long": "-0.001 メートル",
}
],
[
-0,
{
"short": "-0 m",
"narrow": "-0m",
"long": "-0 メートル",
}
],
[
0,
{
"short": "0 m",
"narrow": "0m",
"long": "0 メートル",
}
],
[
0.001,
{
"short": "0.001 m",
"narrow": "0.001m",
"long": "0.001 メートル",
}
],
[
987,
{
"short": "987 m",
"narrow": "987m",
"long": "987 メートル",
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("ja-JP", { style: "unit", unit: "meter", unitDisplay });
assert.sameValue(nf.format(number), expected);
}
}

View File

@ -0,0 +1,69 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the unit style.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
-987,
{
"short": "-987m",
"narrow": "-987m",
"long": "-987미터",
}
],
[
-0.001,
{
"short": "-0.001m",
"narrow": "-0.001m",
"long": "-0.001미터",
}
],
[
-0,
{
"short": "-0m",
"narrow": "-0m",
"long": "-0미터",
}
],
[
0,
{
"short": "0m",
"narrow": "0m",
"long": "0미터",
}
],
[
0.001,
{
"short": "0.001m",
"narrow": "0.001m",
"long": "0.001미터",
}
],
[
987,
{
"short": "987m",
"narrow": "987m",
"long": "987미터",
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("ko-KR", { style: "unit", unit: "meter", unitDisplay });
assert.sameValue(nf.format(number), expected);
}
}

View File

@ -0,0 +1,69 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the unit style.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
-987,
{
"short": "-987 公尺",
"narrow": "-987公尺",
"long": "-987 公尺",
}
],
[
-0.001,
{
"short": "-0.001 公尺",
"narrow": "-0.001公尺",
"long": "-0.001 公尺",
}
],
[
-0,
{
"short": "-0 公尺",
"narrow": "-0公尺",
"long": "-0 公尺",
}
],
[
0,
{
"short": "0 公尺",
"narrow": "0公尺",
"long": "0 公尺",
}
],
[
0.001,
{
"short": "0.001 公尺",
"narrow": "0.001公尺",
"long": "0.001 公尺",
}
],
[
987,
{
"short": "987 公尺",
"narrow": "987公尺",
"long": "987 公尺",
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("zh-TW", { style: "unit", unit: "meter", unitDisplay });
assert.sameValue(nf.format(number), expected);
}
}

View File

@ -0,0 +1,68 @@
// Copyright 2019 Igalia, S.L., Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of units.
features: [Intl.NumberFormat-unified]
---*/
function check(unit) {
const s1 = (123).toLocaleString(undefined, { style: "unit", unit: unit });
const s2 = (123).toLocaleString();
assert.notSameValue(s1, s2);
}
const units = [
"acre",
"bit",
"byte",
"celsius",
"centimeter",
"day",
"degree",
"fahrenheit",
"fluid-ounce",
"foot",
"gallon",
"gigabit",
"gigabyte",
"gram",
"hectare",
"hour",
"inch",
"kilobit",
"kilobyte",
"kilogram",
"kilometer",
"liter",
"megabit",
"megabyte",
"meter",
"mile",
"mile-scandinavian",
"millimeter",
"milliliter",
"millisecond",
"minute",
"month",
"ounce",
"percent",
"petabyte",
"pound",
"second",
"stone",
"terabit",
"terabyte",
"week",
"yard",
"year",
];
for (const simpleUnit of units) {
check(simpleUnit);
for (const simpleUnit2 of units) {
check(simpleUnit + "-per-" + simpleUnit2);
check(simpleUnit2 + "-per-" + simpleUnit);
}
}

View File

@ -0,0 +1,71 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the engineering and scientific notations.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"0.000345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"6"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":","},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"4"}],
],
[
"0.345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":","},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"1"}],
],
[
"3.45",
[{"type":"integer","value":"3"},{"type":"decimal","value":","},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":","},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
],
[
"34.5",
[{"type":"integer","value":"34"},{"type":"decimal","value":","},{"type":"fraction","value":"5"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":","},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"1"}],
],
[
"543",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":","},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"2"}],
],
[
"5430",
[{"type":"integer","value":"5"},{"type":"decimal","value":","},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":","},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
],
[
"543000",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":","},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
[
"543211.1",
[{"type":"integer","value":"543"},{"type":"decimal","value":","},{"type":"fraction","value":"211"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":","},{"type":"fraction","value":"432"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("de-DE", { notation: "engineering" }));
verifyFormatParts(nfEngineering.formatToParts(number), engineering, `${number} - engineering`);
const nfScientific = (new Intl.NumberFormat("de-DE", { notation: "scientific" }));
verifyFormatParts(nfScientific.formatToParts(number), scientific, `${number} - scientific`);
}

View File

@ -0,0 +1,71 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the engineering and scientific notations.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"0.000345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"6"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"4"}],
],
[
"0.345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"1"}],
],
[
"3.45",
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
],
[
"34.5",
[{"type":"integer","value":"34"},{"type":"decimal","value":"."},{"type":"fraction","value":"5"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"1"}],
],
[
"543",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"2"}],
],
[
"5430",
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
],
[
"543000",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
[
"543211.1",
[{"type":"integer","value":"543"},{"type":"decimal","value":"."},{"type":"fraction","value":"211"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"432"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("en-US", { notation: "engineering" }));
verifyFormatParts(nfEngineering.formatToParts(number), engineering, `${number} - engineering`);
const nfScientific = (new Intl.NumberFormat("en-US", { notation: "scientific" }));
verifyFormatParts(nfScientific.formatToParts(number), scientific, `${number} - scientific`);
}

View File

@ -0,0 +1,71 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the engineering and scientific notations.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"0.000345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"6"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"4"}],
],
[
"0.345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"1"}],
],
[
"3.45",
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
],
[
"34.5",
[{"type":"integer","value":"34"},{"type":"decimal","value":"."},{"type":"fraction","value":"5"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"1"}],
],
[
"543",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"2"}],
],
[
"5430",
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
],
[
"543000",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
[
"543211.1",
[{"type":"integer","value":"543"},{"type":"decimal","value":"."},{"type":"fraction","value":"211"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"432"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("ja-JP", { notation: "engineering" }));
verifyFormatParts(nfEngineering.formatToParts(number), engineering, `${number} - engineering`);
const nfScientific = (new Intl.NumberFormat("ja-JP", { notation: "scientific" }));
verifyFormatParts(nfScientific.formatToParts(number), scientific, `${number} - scientific`);
}

View File

@ -0,0 +1,71 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the engineering and scientific notations.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"0.000345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"6"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"4"}],
],
[
"0.345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"1"}],
],
[
"3.45",
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
],
[
"34.5",
[{"type":"integer","value":"34"},{"type":"decimal","value":"."},{"type":"fraction","value":"5"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"1"}],
],
[
"543",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"2"}],
],
[
"5430",
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
],
[
"543000",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
[
"543211.1",
[{"type":"integer","value":"543"},{"type":"decimal","value":"."},{"type":"fraction","value":"211"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"432"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("ko-KR", { notation: "engineering" }));
verifyFormatParts(nfEngineering.formatToParts(number), engineering, `${number} - engineering`);
const nfScientific = (new Intl.NumberFormat("ko-KR", { notation: "scientific" }));
verifyFormatParts(nfScientific.formatToParts(number), scientific, `${number} - scientific`);
}

View File

@ -0,0 +1,71 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the engineering and scientific notations.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"0.000345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"6"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"4"}],
],
[
"0.345",
[{"type":"integer","value":"345"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentMinusSign","value":"-"},{"type":"exponentInteger","value":"1"}],
],
[
"3.45",
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
],
[
"34.5",
[{"type":"integer","value":"34"},{"type":"decimal","value":"."},{"type":"fraction","value":"5"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"3"},{"type":"decimal","value":"."},{"type":"fraction","value":"45"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"1"}],
],
[
"543",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"0"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"2"}],
],
[
"5430",
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
],
[
"543000",
[{"type":"integer","value":"543"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"43"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
[
"543211.1",
[{"type":"integer","value":"543"},{"type":"decimal","value":"."},{"type":"fraction","value":"211"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"3"}],
[{"type":"integer","value":"5"},{"type":"decimal","value":"."},{"type":"fraction","value":"432"},{"type":"exponentSeparator","value":"E"},{"type":"exponentInteger","value":"5"}],
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("zh-TW", { notation: "engineering" }));
verifyFormatParts(nfEngineering.formatToParts(number), engineering, `${number} - engineering`);
const nfScientific = (new Intl.NumberFormat("zh-TW", { notation: "scientific" }));
verifyFormatParts(nfScientific.formatToParts(number), scientific, `${number} - scientific`);
}

View File

@ -0,0 +1,80 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
987654321,
[{"type":"integer","value":"988"},{"type":"literal","value":"\u00a0"},{"type":"compact","value":"Mio."}],
[{"type":"integer","value":"988"},{"type":"literal","value":" "},{"type":"compact","value":"Millionen"}],
],
[
98765432,
[{"type":"integer","value":"99"},{"type":"literal","value":"\u00a0"},{"type":"compact","value":"Mio."}],
[{"type":"integer","value":"99"},{"type":"literal","value":" "},{"type":"compact","value":"Millionen"}],
],
[
98765,
[{"type":"integer","value":"98"},{"type":"group","value":"."},{"type":"integer","value":"765"}],
[{"type":"integer","value":"99"},{"type":"literal","value":" "},{"type":"compact","value":"Tausend"}],
],
[
9876,
[{"type":"integer","value":"9876"}],
[{"type":"integer","value":"9"},{"type":"decimal","value":","},{"type":"fraction","value":"9"},{"type":"literal","value":" "},{"type":"compact","value":"Tausend"}],
],
[
159,
[{"type":"integer","value":"159"}],
],
[
15.9,
[{"type":"integer","value":"16"}],
],
[
1.59,
[{"type":"integer","value":"1"},{"type":"decimal","value":","},{"type":"fraction","value":"6"}],
],
[
0.159,
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"16"}],
],
[
0.0159,
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"016"}],
],
[
0.00159,
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"0016"}],
],
];
for (const [number, short, long = short] of tests) {
const nfShort = new Intl.NumberFormat("de-DE", {
notation: "compact",
compactDisplay: "short",
});
verifyFormatParts(nfShort.formatToParts(number), short, `Compact short: ${number}`);
const nfLong = new Intl.NumberFormat("de-DE", {
notation: "compact",
compactDisplay: "long",
});
verifyFormatParts(nfLong.formatToParts(number), long, `Compact long: ${number}`);
}

View File

@ -0,0 +1,80 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
987654321,
[{"type":"integer","value":"988"},{"type":"compact","value":"M"}],
[{"type":"integer","value":"988"},{"type":"literal","value":" "},{"type":"compact","value":"million"}],
],
[
98765432,
[{"type":"integer","value":"99"},{"type":"compact","value":"M"}],
[{"type":"integer","value":"99"},{"type":"literal","value":" "},{"type":"compact","value":"million"}],
],
[
98765,
[{"type":"integer","value":"99"},{"type":"compact","value":"K"}],
[{"type":"integer","value":"99"},{"type":"literal","value":" "},{"type":"compact","value":"thousand"}],
],
[
9876,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"K"}],
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"literal","value":" "},{"type":"compact","value":"thousand"}],
],
[
159,
[{"type":"integer","value":"159"}],
],
[
15.9,
[{"type":"integer","value":"16"}],
],
[
1.59,
[{"type":"integer","value":"1"},{"type":"decimal","value":"."},{"type":"fraction","value":"6"}],
],
[
0.159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"16"}],
],
[
0.0159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"016"}],
],
[
0.00159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"0016"}],
],
];
for (const [number, short, long = short] of tests) {
const nfShort = new Intl.NumberFormat("en-US", {
notation: "compact",
compactDisplay: "short",
});
verifyFormatParts(nfShort.formatToParts(number), short, `Compact short: ${number}`);
const nfLong = new Intl.NumberFormat("en-US", {
notation: "compact",
compactDisplay: "long",
});
verifyFormatParts(nfLong.formatToParts(number), long, `Compact long: ${number}`);
}

View File

@ -0,0 +1,76 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
987654321,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"億"}],
],
[
98765432,
[{"type":"integer","value":"9877"},{"type":"compact","value":"万"}],
],
[
98765,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"万"}],
],
[
9876,
[{"type":"integer","value":"9876"}],
],
[
159,
[{"type":"integer","value":"159"}],
],
[
15.9,
[{"type":"integer","value":"16"}],
],
[
1.59,
[{"type":"integer","value":"1"},{"type":"decimal","value":"."},{"type":"fraction","value":"6"}],
],
[
0.159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"16"}],
],
[
0.0159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"016"}],
],
[
0.00159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"0016"}],
],
];
for (const [number, short, long = short] of tests) {
const nfShort = new Intl.NumberFormat("ja-JP", {
notation: "compact",
compactDisplay: "short",
});
verifyFormatParts(nfShort.formatToParts(number), short, `Compact short: ${number}`);
const nfLong = new Intl.NumberFormat("ja-JP", {
notation: "compact",
compactDisplay: "long",
});
verifyFormatParts(nfLong.formatToParts(number), long, `Compact long: ${number}`);
}

View File

@ -0,0 +1,76 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
987654321,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"억"}],
],
[
98765432,
[{"type":"integer","value":"9877"},{"type":"compact","value":"만"}],
],
[
98765,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"만"}],
],
[
9876,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"천"}],
],
[
159,
[{"type":"integer","value":"159"}],
],
[
15.9,
[{"type":"integer","value":"16"}],
],
[
1.59,
[{"type":"integer","value":"1"},{"type":"decimal","value":"."},{"type":"fraction","value":"6"}],
],
[
0.159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"16"}],
],
[
0.0159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"016"}],
],
[
0.00159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"0016"}],
],
];
for (const [number, short, long = short] of tests) {
const nfShort = new Intl.NumberFormat("ko-KR", {
notation: "compact",
compactDisplay: "short",
});
verifyFormatParts(nfShort.formatToParts(number), short, `Compact short: ${number}`);
const nfLong = new Intl.NumberFormat("ko-KR", {
notation: "compact",
compactDisplay: "long",
});
verifyFormatParts(nfLong.formatToParts(number), long, `Compact long: ${number}`);
}

View File

@ -0,0 +1,76 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
987654321,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"億"}],
],
[
98765432,
[{"type":"integer","value":"9877"},{"type":"compact","value":"萬"}],
],
[
98765,
[{"type":"integer","value":"9"},{"type":"decimal","value":"."},{"type":"fraction","value":"9"},{"type":"compact","value":"萬"}],
],
[
9876,
[{"type":"integer","value":"9876"}],
],
[
159,
[{"type":"integer","value":"159"}],
],
[
15.9,
[{"type":"integer","value":"16"}],
],
[
1.59,
[{"type":"integer","value":"1"},{"type":"decimal","value":"."},{"type":"fraction","value":"6"}],
],
[
0.159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"16"}],
],
[
0.0159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"016"}],
],
[
0.00159,
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"0016"}],
],
];
for (const [number, short, long = short] of tests) {
const nfShort = new Intl.NumberFormat("zh-TW", {
notation: "compact",
compactDisplay: "short",
});
verifyFormatParts(nfShort.formatToParts(number), short, `Compact short: ${number}`);
const nfLong = new Intl.NumberFormat("zh-TW", {
notation: "compact",
compactDisplay: "long",
});
verifyFormatParts(nfLong.formatToParts(number), long, `Compact long: ${number}`);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
],
[
"always",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
],
[
"never",
[{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
],
[
"exceptZero",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"},{"type":"decimal","value":","},{"type":"fraction","value":"00"},{"type":"literal","value":" "},{"type":"currency","value":"$"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("de-DE", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"always",
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"never",
[{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"exceptZero",
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"always",
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"never",
[{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"exceptZero",
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ja-JP", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"always",
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"never",
[{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"exceptZero",
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ko-KR", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"always",
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"never",
[{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
[
"exceptZero",
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"literal","value":"("},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"},{"type":"literal","value":")"}],
[{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
[{"type":"plusSign","value":"+"},{"type":"currency","value":"US$"},{"type":"integer","value":"987"},{"type":"decimal","value":"."},{"type":"fraction","value":"00"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("zh-TW", { style: "currency", currency: "USD", currencySign: "accounting", signDisplay });
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"always",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
[
"never",
[{"type":"integer","value":"987"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"exceptZero",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("de-DE", {signDisplay});
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"always",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
[
"never",
[{"type":"integer","value":"987"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"exceptZero",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("en-US", {signDisplay});
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"always",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
[
"never",
[{"type":"integer","value":"987"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"exceptZero",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ja-JP", {signDisplay});
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"always",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
[
"never",
[{"type":"integer","value":"987"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"exceptZero",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("ko-KR", {signDisplay});
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the compactDisplay option to the NumberFormat constructor.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
"auto",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"always",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
[
"never",
[{"type":"integer","value":"987"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"integer","value":"987"}],
],
[
"exceptZero",
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"}],
[{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"0"}],
[{"type":"plusSign","value":"+"},{"type":"integer","value":"987"}],
],
];
for (const [signDisplay, negative, negativeNearZero, negativeZero, zero, positiveNearZero, positive] of tests) {
const nf = new Intl.NumberFormat("zh-TW", {signDisplay});
verifyFormatParts(nf.formatToParts(-987), negative);
verifyFormatParts(nf.formatToParts(-0.0001), negativeNearZero);
verifyFormatParts(nf.formatToParts(-0), negativeZero);
verifyFormatParts(nf.formatToParts(0), zero);
verifyFormatParts(nf.formatToParts(0.0001), positiveNearZero);
verifyFormatParts(nf.formatToParts(987), positive);
}

View File

@ -0,0 +1,97 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the unit style.
locale: [de-DE]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
-987,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"Meter"}],
}
],
[
-0.001,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"Meter"}],
}
],
[
-0,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"Meter"}],
}
],
[
0,
{
"short":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"Meter"}],
}
],
[
0.001,
{
"short":
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"decimal","value":","},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"Meter"}],
}
],
[
987,
{
"short":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"Meter"}],
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("de-DE", { style: "unit", unit: "meter", unitDisplay });
verifyFormatParts(nf.formatToParts(number), expected);
}
}

View File

@ -0,0 +1,97 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the unit style.
locale: [en-US]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
-987,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"meters"}],
}
],
[
-0.001,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"meters"}],
}
],
[
-0,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"meters"}],
}
],
[
0,
{
"short":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"meters"}],
}
],
[
0.001,
{
"short":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"meters"}],
}
],
[
987,
{
"short":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"meters"}],
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("en-US", { style: "unit", unit: "meter", unitDisplay });
verifyFormatParts(nf.formatToParts(number), expected);
}
}

View File

@ -0,0 +1,97 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the unit style.
locale: [ja-JP]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
-987,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"メートル"}],
}
],
[
-0.001,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"メートル"}],
}
],
[
-0,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"メートル"}],
}
],
[
0,
{
"short":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"メートル"}],
}
],
[
0.001,
{
"short":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"メートル"}],
}
],
[
987,
{
"short":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"メートル"}],
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("ja-JP", { style: "unit", unit: "meter", unitDisplay });
verifyFormatParts(nf.formatToParts(number), expected);
}
}

View File

@ -0,0 +1,97 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the unit style.
locale: [ko-KR]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
-987,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"unit","value":"미터"}],
}
],
[
-0.001,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"미터"}],
}
],
[
-0,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"unit","value":"미터"}],
}
],
[
0,
{
"short":
[{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"unit","value":"미터"}],
}
],
[
0.001,
{
"short":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"미터"}],
}
],
[
987,
{
"short":
[{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"narrow":
[{"type":"integer","value":"987"},{"type":"unit","value":"m"}],
"long":
[{"type":"integer","value":"987"},{"type":"unit","value":"미터"}],
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("ko-KR", { style: "unit", unit: "meter", unitDisplay });
verifyFormatParts(nf.formatToParts(number), expected);
}
}

View File

@ -0,0 +1,97 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the unit style.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
function verifyFormatParts(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 < actual.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`);
assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`);
}
}
const tests = [
[
-987,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"unit","value":"公尺"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
}
],
[
-0.001,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"公尺"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
}
],
[
-0,
{
"short":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
"narrow":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"unit","value":"公尺"}],
"long":
[{"type":"minusSign","value":"-"},{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
}
],
[
0,
{
"short":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"unit","value":"公尺"}],
"long":
[{"type":"integer","value":"0"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
}
],
[
0.001,
{
"short":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
"narrow":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"unit","value":"公尺"}],
"long":
[{"type":"integer","value":"0"},{"type":"decimal","value":"."},{"type":"fraction","value":"001"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
}
],
[
987,
{
"short":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
"narrow":
[{"type":"integer","value":"987"},{"type":"unit","value":"公尺"}],
"long":
[{"type":"integer","value":"987"},{"type":"literal","value":" "},{"type":"unit","value":"公尺"}],
}
],
];
for (const [number, expectedData] of tests) {
for (const [unitDisplay, expected] of Object.entries(expectedData)) {
const nf = new Intl.NumberFormat("zh-TW", { style: "unit", unit: "meter", unitDisplay });
verifyFormatParts(nf.formatToParts(number), expected);
}
}

View File

@ -0,0 +1,25 @@
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: Checks handling of the unit style.
features: [Intl.NumberFormat-unified]
---*/
const numbers = [-987, -0.001, -0, 0, 0.001, 987];
const displays = [
"short",
"narrow",
"long",
];
for (const unitDisplay of displays) {
const nf = new Intl.NumberFormat("en-US", { style: "unit", unit: "meter", unitDisplay });
for (const number of numbers) {
const result = nf.formatToParts(number);
assert.sameValue(result.map(({ value }) => value).join(""), nf.format(number));
assert.sameValue(result.some(({ type }) => type === "unit"), true);
}
}