Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,13 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const testData = [
["short"],
["long"],
];
for (const [compactDisplay] of testData) {
nf = new Intl.NumberFormat("en", {compactDisplay, notation: "compact"});
assertEquals(compactDisplay, nf.resolvedOptions().compactDisplay);
}

View File

@ -0,0 +1,69 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Similar to constructor-order.js but also consider the new options
// in https://tc39-transfer.github.io/proposal-unified-intl-numberformat/
// Throws only once during construction.
// Check for all getters to prevent regression.
// Preserve the order of getter initialization.
let getCount = 0;
new Intl.NumberFormat(['en-US'], {
get localeMatcher() {
assertEquals(0, getCount++);
},
get style() {
assertEquals(1, getCount++);
},
get currency() {
assertEquals(2, getCount++);
},
get currencyDisplay() {
assertEquals(3, getCount++);
},
// Begin of new options
get currencySign() {
assertEquals(4, getCount++);
},
get unit() {
assertEquals(5, getCount++);
},
get unitDisplay() {
assertEquals(6, getCount++);
},
get notation() {
assertEquals(7, getCount++);
},
// End of new options
get minimumIntegerDigits() {
assertEquals(8, getCount++);
},
get minimumFractionDigits() {
assertEquals(9, getCount++);
},
get maximumFractionDigits() {
assertEquals(10, getCount++);
},
get minimumSignificantDigits() {
assertEquals(11, getCount++);
},
get maximumSignificantDigits() {
assertEquals(12, getCount++);
},
// Begin of new options
get compactDisplay() {
assertEquals(13, getCount++);
},
// End of new options
get useGrouping() {
assertEquals(14, getCount++);
},
// Begin of new options
get signDisplay() {
assertEquals(15, getCount++);
},
// End of new options
});
assertEquals(16, getCount);

View File

@ -0,0 +1,37 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test defaults
let nf = new Intl.NumberFormat();
assertEquals(undefined, nf.resolvedOptions().currencyDisplay);
nf = new Intl.NumberFormat("en");
assertEquals(undefined, nf.resolvedOptions().currencyDisplay);
nf = new Intl.NumberFormat("en", {style: "decimal"});
assertEquals(undefined, nf.resolvedOptions().currencyDisplay);
nf = new Intl.NumberFormat("en", {style: "percent"});
assertEquals(undefined, nf.resolvedOptions().currencyDisplay);
nf = new Intl.NumberFormat("en", {style: "unit", unit: "meter"});
assertEquals(undefined, nf.resolvedOptions().currencyDisplay);
nf = new Intl.NumberFormat("en", {style: "currency", currency: "TWD"});
assertEquals("symbol", nf.resolvedOptions().currencyDisplay);
const testData = [
["name", "123.00 New Taiwan dollars"],
["code", "TWD 123.00"],
["symbol", "NT$123.00"],
["narrowSymbol", "$123.00"], // new
];
for (const [currencyDisplay, expectation] of testData) {
nf = new Intl.NumberFormat("en",
{style: 'currency', currency: "TWD", currencyDisplay});
assertEquals('currency', nf.resolvedOptions().style);
assertEquals(currencyDisplay, nf.resolvedOptions().currencyDisplay);
assertEquals(expectation, nf.format(123));
}

View File

@ -0,0 +1,39 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test default.
let nf = new Intl.NumberFormat();
assertEquals(undefined, nf.resolvedOptions().currencySign);
nf = new Intl.NumberFormat("en");
assertEquals(undefined, nf.resolvedOptions().currencySign);
nf = new Intl.NumberFormat("en", {style: 'decimal'});
assertEquals(undefined, nf.resolvedOptions().currencySign);
nf = new Intl.NumberFormat("en", {style: 'percent'});
assertEquals(undefined, nf.resolvedOptions().currencySign);
nf = new Intl.NumberFormat("en", {style: 'unit', unit: "meter"});
assertEquals(undefined, nf.resolvedOptions().currencySign);
nf = new Intl.NumberFormat("en", {style: 'currency', currency: "TWD"});
assertEquals("standard", nf.resolvedOptions().currencySign);
const testData = [
["standard", "-NT$123.40", "-NT$0.00", "NT$0.00", "NT$123.40"],
["accounting", "(NT$123.40)", "(NT$0.00)", "NT$0.00", "NT$123.40"],
];
for (const [currencySign, neg, negZero, zero, pos] of testData) {
nf = new Intl.NumberFormat("en", {style: 'currency', currency: "TWD",
currencySign});
assertEquals('currency', nf.resolvedOptions().style);
assertEquals(currencySign, nf.resolvedOptions().currencySign);
assertEquals(neg, nf.format(-123.4));
assertEquals(negZero, nf.format(-0));
assertEquals(zero, nf.format(0));
assertEquals(pos, nf.format(123.4));
}

View File

@ -0,0 +1,28 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Except when the notation is "compact", the resolvedOptions().compactDisplay
// should be undefined.
//
// Test default
let nf = new Intl.NumberFormat();
assertEquals(undefined, nf.resolvedOptions().compactDisplay);
nf = new Intl.NumberFormat("en");
assertEquals(undefined, nf.resolvedOptions().compactDisplay);
const testData = [
["scientific"],
["engineering"],
["standard"],
];
for (const [notation] of testData) {
nf = new Intl.NumberFormat("en", {notation});
assertEquals(undefined, nf.resolvedOptions().compactDisplay);
for (const compactDisplay of ["short", "long"]) {
nf = new Intl.NumberFormat("en", {compactDisplay, notation});
assertEquals(undefined, nf.resolvedOptions().compactDisplay);
}
}

View File

@ -0,0 +1,158 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test notation: "engineering" with formatToParts.
const nf = Intl.NumberFormat("en", {notation: "engineering"});
let parts = nf.formatToParts(123.456);
// [{type: "integer", value: "123"}, {type: "decimal", value: "."},
// {type: "fraction", value: "456"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "0"}]
assertEquals("integer", parts[0].type);
assertEquals("123", parts[0].value);
assertEquals("decimal", parts[1].type);
assertEquals(".", parts[1].value);
assertEquals("fraction", parts[2].type);
assertEquals("456", parts[2].value);
assertEquals("exponentSeparator", parts[3].type);
assertEquals("E", parts[3].value);
assertEquals("exponentInteger", parts[4].type);
assertEquals("0", parts[4].value);
assertEquals(5, parts.length);
parts = nf.formatToParts(-123.456);
// [{type: "minusSign", value: "-"}, {type: "integer", value: "123"},
// {type: "decimal", value: "."}, {type: "fraction", value: "456"},
// {type: "exponentSeparator", value: "E"}, {type: "exponentInteger", value: "0"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("123", parts[1].value);
assertEquals("decimal", parts[2].type);
assertEquals(".", parts[2].value);
assertEquals("fraction", parts[3].type);
assertEquals("456", parts[3].value);
assertEquals("exponentSeparator", parts[4].type);
assertEquals("E", parts[4].value);
assertEquals("exponentInteger", parts[5].type);
assertEquals("0", parts[5].value);
assertEquals(6, parts.length);
parts = nf.formatToParts(12345678901234567890);
// [{type: "integer", value: "12"}, {type: "decimal", value: "."},
// {type: "fraction", value: "346"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "18"}]
assertEquals("integer", parts[0].type);
assertEquals("12", parts[0].value);
assertEquals("decimal", parts[1].type);
assertEquals(".", parts[1].value);
assertEquals("fraction", parts[2].type);
assertEquals("346", parts[2].value);
assertEquals("exponentSeparator", parts[3].type);
assertEquals("E", parts[3].value);
assertEquals("exponentInteger", parts[4].type);
assertEquals("18", parts[4].value);
assertEquals(5, parts.length);
parts = nf.formatToParts(-12345678901234567890);
// [{type: "minusSign", value: "-"}, {type: "integer", value: "12"},
// {type: "decimal", value: "."}, {type: "fraction", value: "346"},
// {type: "exponentSeparator", value: "E"}, {type: "exponentInteger", value: "18"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("12", parts[1].value);
assertEquals("decimal", parts[2].type);
assertEquals(".", parts[2].value);
assertEquals("fraction", parts[3].type);
assertEquals("346", parts[3].value);
assertEquals("exponentSeparator", parts[4].type);
assertEquals("E", parts[4].value);
assertEquals("exponentInteger", parts[5].type);
assertEquals("18", parts[5].value);
assertEquals(6, parts.length);
parts = nf.formatToParts(0.000000000000123456);
// [{type: "integer", value: "123"}, {type: "decimal", value: "."},
// {type: "fraction", value: "456"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentMinusSign", value: "-"}, {type: "exponentInteger", value: "15"}]
assertEquals("integer", parts[0].type);
assertEquals("123", parts[0].value);
assertEquals("decimal", parts[1].type);
assertEquals(".", parts[1].value);
assertEquals("fraction", parts[2].type);
assertEquals("456", parts[2].value);
assertEquals("exponentSeparator", parts[3].type);
assertEquals("E", parts[3].value);
assertEquals("exponentMinusSign", parts[4].type);
assertEquals("-", parts[4].value);
assertEquals("exponentInteger", parts[5].type);
assertEquals("15", parts[5].value);
assertEquals(6, parts.length);
parts = nf.formatToParts(-0.000000000000123456);
// [{type: "minusSign", value: "-"}, {type: "integer", value: "123"},
// {type: "decimal", value: "."}, {type: "fraction", value: "456"},
// {type: "exponentSeparator", value: "E"},
// {type: "exponentMinusSign", value: "-"}, {type: "exponentInteger", value: "15"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("123", parts[1].value);
assertEquals("decimal", parts[2].type);
assertEquals(".", parts[2].value);
assertEquals("fraction", parts[3].type);
assertEquals("456", parts[3].value);
assertEquals("exponentSeparator", parts[4].type);
assertEquals("E", parts[4].value);
assertEquals("exponentMinusSign", parts[5].type);
assertEquals("-", parts[5].value);
assertEquals("exponentInteger", parts[6].type);
assertEquals("15", parts[6].value);
assertEquals(7, parts.length);
parts = nf.formatToParts(0);
// [{type: "integer", value: "0"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "0"}]
assertEquals("integer", parts[0].type);
assertEquals("0", parts[0].value);
assertEquals("exponentSeparator", parts[1].type);
assertEquals("E", parts[1].value);
assertEquals("exponentInteger", parts[2].type);
assertEquals("0", parts[2].value);
assertEquals(3, parts.length);
parts = nf.formatToParts(-0);
// [{type: "minusSign", value: "-"}, {type: "integer", value: "0"},
// {type: "exponentSeparator", value: "E"}, {type: "exponentInteger", value: "0"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("0", parts[1].value);
assertEquals("exponentSeparator", parts[2].type);
assertEquals("E", parts[2].value);
assertEquals("exponentInteger", parts[3].type);
assertEquals("0", parts[3].value);
assertEquals(4, parts.length);
parts = nf.formatToParts(Infinity);
// [{type: "infinity", value: "∞"}]
assertEquals("infinity", parts[0].type);
assertEquals("∞", parts[0].value);
assertEquals(1, parts.length);
parts = nf.formatToParts(-Infinity);
// [{type: "minusSign", value: "-"}, {type: "infinity", value: "∞"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("infinity", parts[1].type);
assertEquals("∞", parts[1].value);
assertEquals(2, parts.length);
parts = nf.formatToParts(NaN);
// [{type: "nan", value: "NaN"}]
assertEquals("nan", parts[0].type);
assertEquals("NaN", parts[0].value);
assertEquals(1, parts.length);

View File

@ -0,0 +1,160 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test notation: "scientific" with formatToParts.
const nf = Intl.NumberFormat("en", {notation: "scientific"});
let parts = nf.formatToParts(123.456);
// [{type: "integer", value: "1"}, {type: "decimal", value: "."},
// {type: "fraction", value: "235"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "2"}]
assertEquals("integer", parts[0].type);
assertEquals("1", parts[0].value);
assertEquals("decimal", parts[1].type);
assertEquals(".", parts[1].value);
assertEquals("fraction", parts[2].type);
assertEquals("235", parts[2].value);
assertEquals("exponentSeparator", parts[3].type);
assertEquals("E", parts[3].value);
assertEquals("exponentInteger", parts[4].type);
assertEquals("2", parts[4].value);
assertEquals(5, parts.length);
parts = nf.formatToParts(-123.456);
// [{type: "minusSign", value: "-"},i
// {type: "integer", value: "1"}, {type: "decimal", value: "."},
// {type: "fraction", value: "235"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "2"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("1", parts[1].value);
assertEquals("decimal", parts[2].type);
assertEquals(".", parts[2].value);
assertEquals("fraction", parts[3].type);
assertEquals("235", parts[3].value);
assertEquals("exponentSeparator", parts[4].type);
assertEquals("E", parts[4].value);
assertEquals("exponentInteger", parts[5].type);
assertEquals("2", parts[5].value);
assertEquals(6, parts.length);
parts = nf.formatToParts(12345678901234567890);
// [{type: "integer", value: "1"}, {type: "decimal", value: "."},
// {type: "fraction", value: "235"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "19"}]
assertEquals("integer", parts[0].type);
assertEquals("1", parts[0].value);
assertEquals("decimal", parts[1].type);
assertEquals(".", parts[1].value);
assertEquals("fraction", parts[2].type);
assertEquals("235", parts[2].value);
assertEquals("exponentSeparator", parts[3].type);
assertEquals("E", parts[3].value);
assertEquals("exponentInteger", parts[4].type);
assertEquals("19", parts[4].value);
assertEquals(5, parts.length);
parts = nf.formatToParts(-12345678901234567890);
// [{type: "minusSign", value: "-"},
// {type: "integer", value: "1"}, {type: "decimal", value: "."},
// {type: "fraction", value: "235"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "19"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("1", parts[1].value);
assertEquals("decimal", parts[2].type);
assertEquals(".", parts[2].value);
assertEquals("fraction", parts[3].type);
assertEquals("235", parts[3].value);
assertEquals("exponentSeparator", parts[4].type);
assertEquals("E", parts[4].value);
assertEquals("exponentInteger", parts[5].type);
assertEquals("19", parts[5].value);
assertEquals(6, parts.length);
parts = nf.formatToParts(0.000000000000123456);
// [{type: "integer", value: "1"}, {type: "decimal", value: "."},
// {type: "fraction", value: "235"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentMinusSign", value: "-"}, {type: "exponentInteger", value: "13"}]
assertEquals("integer", parts[0].type);
assertEquals("1", parts[0].value);
assertEquals("decimal", parts[1].type);
assertEquals(".", parts[1].value);
assertEquals("fraction", parts[2].type);
assertEquals("235", parts[2].value);
assertEquals("exponentSeparator", parts[3].type);
assertEquals("E", parts[3].value);
assertEquals("exponentMinusSign", parts[4].type);
assertEquals("-", parts[4].value);
assertEquals("exponentInteger", parts[5].type);
assertEquals("13", parts[5].value);
assertEquals(6, parts.length);
parts = nf.formatToParts(-0.000000000000123456);
// [{type: "minusSign", value: "-"}, {type: "integer", value: "1"},
// {type: "decimal", value: "."}, {type: "fraction", value: "235"},
// {type: "exponentSeparator", value: "E"},
// {type: "exponentMinusSign", value: "-"}, {type: "exponentInteger", value: "13"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("1", parts[1].value);
assertEquals("decimal", parts[2].type);
assertEquals(".", parts[2].value);
assertEquals("fraction", parts[3].type);
assertEquals("235", parts[3].value);
assertEquals("exponentSeparator", parts[4].type);
assertEquals("E", parts[4].value);
assertEquals("exponentMinusSign", parts[5].type);
assertEquals("-", parts[5].value);
assertEquals("exponentInteger", parts[6].type);
assertEquals("13", parts[6].value);
assertEquals(7, parts.length);
parts = nf.formatToParts(0);
// [{type: "integer", value: "0"}, {type: "exponentSeparator", value: "E"},
// {type: "exponentInteger", value: "0"}]
assertEquals("integer", parts[0].type);
assertEquals("0", parts[0].value);
assertEquals("exponentSeparator", parts[1].type);
assertEquals("E", parts[1].value);
assertEquals("exponentInteger", parts[2].type);
assertEquals("0", parts[2].value);
assertEquals(3, parts.length);
parts = nf.formatToParts(-0);
// [{type: "minusSign", value: "-"}, {type: "integer", value: "0"},
// {type: "exponentSeparator", value: "E"}, {type: "exponentInteger", value: "0"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("integer", parts[1].type);
assertEquals("0", parts[1].value);
assertEquals("exponentSeparator", parts[2].type);
assertEquals("E", parts[2].value);
assertEquals("exponentInteger", parts[3].type);
assertEquals("0", parts[3].value);
assertEquals(4, parts.length);
parts = nf.formatToParts(Infinity);
// [{type: "infinity", value: "∞"}]
assertEquals("infinity", parts[0].type);
assertEquals("∞", parts[0].value);
assertEquals(1, parts.length);
parts = nf.formatToParts(-Infinity);
// [{type: "minusSign", value: "-"}, {type: "infinity", value: "∞"}]
assertEquals("minusSign", parts[0].type);
assertEquals("-", parts[0].value);
assertEquals("infinity", parts[1].type);
assertEquals("∞", parts[1].value);
assertEquals(2, parts.length);
parts = nf.formatToParts(NaN);
// [{type: "nan", value: "NaN"}]
assertEquals("nan", parts[0].type);
assertEquals("NaN", parts[0].value);
assertEquals(1, parts.length);

View File

@ -0,0 +1,87 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test defaults.
let nf = new Intl.NumberFormat();
assertEquals("standard", nf.resolvedOptions().notation);
nf = new Intl.NumberFormat("en");
assertEquals("standard", nf.resolvedOptions().notation);
nf = new Intl.NumberFormat("en", {style: "percent"});
assertEquals("standard", nf.resolvedOptions().notation);
const testData = [
["standard", undefined, "987,654,321"],
["scientific", undefined, "9.877E8"],
["engineering", undefined, "987.654E6"],
["compact", undefined, "988M"],
["compact", "short", "988M"],
["compact", "long", "988 million"],
];
for (const [notation, compactDisplay, expect1] of testData) {
nf = new Intl.NumberFormat("en", {notation, compactDisplay});
assertEquals(notation, nf.resolvedOptions().notation);
if (notation != "compact") {
assertEquals(undefined, nf.resolvedOptions().compactDisplay);
} else if (compactDisplay == "long") {
assertEquals("long", nf.resolvedOptions().compactDisplay);
} else {
assertEquals("short", nf.resolvedOptions().compactDisplay);
}
assertEquals(expect1, nf.format(987654321));
}
// Test Germany which has different decimal marks.
let notation = "compact";
nf = new Intl.NumberFormat("de", {notation, compactDisplay: "short"});
assertEquals("988 Mio.", nf.format(987654321));
assertEquals("99 Mio.", nf.format(98765432));
assertEquals("98.765", nf.format(98765));
assertEquals("9876", nf.format(9876));
nf = new Intl.NumberFormat("de", {notation, compactDisplay: "long"});
assertEquals("988 Millionen", nf.format(987654321));
assertEquals("99 Millionen", nf.format(98765432));
assertEquals("99 Tausend", nf.format(98765));
assertEquals("9,9 Tausend", nf.format(9876));
// Test Chinese, Japanese and Korean, which group by 4 digits.
nf = new Intl.NumberFormat("zh-TW", {notation, compactDisplay: "short"});
assertEquals("9.9億", nf.format(987654321));
assertEquals("9877萬", nf.format(98765432));
assertEquals("9.9萬", nf.format(98765));
assertEquals("9876", nf.format(9876));
nf = new Intl.NumberFormat("zh-TW", {notation, compactDisplay: "long"});
assertEquals("9.9億", nf.format(987654321));
assertEquals("9877萬", nf.format(98765432));
assertEquals("9.9萬", nf.format(98765));
assertEquals("9876", nf.format(9876));
// Test Japanese with compact.
nf = new Intl.NumberFormat("ja", {notation, compactDisplay: "short"});
assertEquals("9.9億", nf.format(987654321));
assertEquals("9877万", nf.format(98765432));
assertEquals("9.9万", nf.format(98765));
assertEquals("9876", nf.format(9876));
nf = new Intl.NumberFormat("ja", {notation, compactDisplay: "long"});
assertEquals("9.9億", nf.format(987654321));
assertEquals("9877万", nf.format(98765432));
assertEquals("9.9万", nf.format(98765));
assertEquals("9876", nf.format(9876));
// Test Korean with compact.
nf = new Intl.NumberFormat("ko", {notation, compactDisplay: "short"});
assertEquals("9.9억", nf.format(987654321));
assertEquals("9877만", nf.format(98765432));
assertEquals("9.9만", nf.format(98765));
assertEquals("9.9천", nf.format(9876));
assertEquals("987", nf.format(987));
nf = new Intl.NumberFormat("ko", {notation, compactDisplay: "long"});
assertEquals("9.9억", nf.format(987654321));
assertEquals("9877만", nf.format(98765432));
assertEquals("9.9만", nf.format(98765));
assertEquals("9.9천", nf.format(9876));
assertEquals("987", nf.format(987));

View File

@ -0,0 +1,63 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test the handling of "percent" w/ "unit"
let nf1 = new Intl.NumberFormat("en-US", {
style: "percent",
unitDisplay: "long" // Read, but ignored.
});
let resolved1 = nf1.resolvedOptions();
assertEquals("percent", resolved1.style);
assertEquals(undefined, resolved1.unit);
assertEquals(undefined, resolved1.unitDisplay);
let parts1 = nf1.formatToParts(100);
assertEquals(4, parts1.length);
assertEquals("integer", parts1[0].type);
assertEquals("10", parts1[0].value);
assertEquals("group", parts1[1].type);
assertEquals(",", parts1[1].value);
assertEquals("integer", parts1[2].type);
assertEquals("000", parts1[2].value);
assertEquals("percentSign", parts1[3].type);
assertEquals("%", parts1[3].value);
let nf2 = new Intl.NumberFormat("en-US", {
style: "unit",
unit: "percent",
unitDisplay: "long" // This is OK
});
let resolved2 = nf2.resolvedOptions();
assertEquals("unit", resolved2.style);
assertEquals("percent", resolved2.unit);
assertEquals("long", resolved2.unitDisplay);
let parts2 = nf2.formatToParts(100);
assertEquals(3, parts2.length);
assertEquals("integer", parts2[0].type);
assertEquals("100", parts2[0].value);
assertEquals("literal", parts2[1].type);
assertEquals(" ", parts2[1].value);
assertEquals("unit", parts2[2].type);
assertEquals("percent", parts2[2].value);
let nf3 = new Intl.NumberFormat("en-US", {
style: "unit",
unit: "percent"
});
let resolved3 = nf3.resolvedOptions();
assertEquals("unit", resolved3.style);
assertEquals("percent", resolved3.unit);
assertEquals("short", resolved3.unitDisplay);
let parts3 = nf3.formatToParts(100);
assertEquals(2, parts3.length);
assertEquals("integer", parts3[0].type);
assertEquals("100", parts3[0].value);
assertEquals("unit", parts3[1].type);
assertEquals("%", parts3[1].value);

View File

@ -0,0 +1,26 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test default.
let nf = new Intl.NumberFormat();
assertEquals("auto", nf.resolvedOptions().signDisplay);
nf = new Intl.NumberFormat("en");
assertEquals("auto", nf.resolvedOptions().signDisplay);
const testData = [
["auto", "-123", "-0", "0", "123"],
["always", "-123", "-0", "+0", "+123"],
["never", "123", "0", "0", "123"],
["exceptZero", "-123", "0", "0", "+123"],
];
for (const [signDisplay, neg, negZero, zero, pos] of testData) {
nf = new Intl.NumberFormat("en", {signDisplay});
assertEquals(signDisplay, nf.resolvedOptions().signDisplay);
assertEquals(neg, nf.format(-123));
assertEquals(negZero, nf.format(-0));
assertEquals(zero, nf.format(0));
assertEquals(pos, nf.format(123));
}

View File

@ -0,0 +1,180 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test default.
let nf = new Intl.NumberFormat();
assertEquals(undefined, nf.resolvedOptions().unit);
nf = new Intl.NumberFormat("en");
assertEquals(undefined, nf.resolvedOptions().unit);
nf = new Intl.NumberFormat("en", {style: 'decimal'});
assertEquals(undefined, nf.resolvedOptions().unit);
nf = new Intl.NumberFormat("en", {style: 'currency', currency: 'TWD'});
assertEquals(undefined, nf.resolvedOptions().unit);
nf = new Intl.NumberFormat("en", {style: 'percent'});
assertEquals(undefined, nf.resolvedOptions().unit);
assertThrows(() => new Intl.NumberFormat("en", {style: 'unit'}), TypeError);
const validUnits = [
// IsSanctionedSimpleUnitIdentifier
'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',
'microsecond',
'mile-scandinavian',
'mile',
'millimeter',
'milliliter',
'millisecond',
'minute',
'month',
'nanosecond',
'ounce',
'petabyte',
'pound',
'second',
'stone',
'terabit',
'terabyte',
'week',
'yard',
'year',
'percent',
'kilometer-per-hour',
'mile-per-hour',
'meter-per-second',
'yard-per-second',
'yard-per-hour',
// -per- in IsWellFormedUnitIdentifier
'liter-per-kilometer',
'mile-per-gallon',
];
for (const unit of validUnits) {
let resolved = new Intl.NumberFormat(
"en", {style: 'unit', unit}).resolvedOptions();
assertEquals('unit', resolved.style);
assertEquals(resolved.unit, unit);
}
function c(u) {
return new Intl.NumberFormat('en', { style: 'unit', unit: u});
}
assertThrows(() => c('acre-foot'), RangeError);
assertThrows(() => c('ampere'), RangeError);
assertThrows(() => c('arc-minute'), RangeError);
assertThrows(() => c('arc-second'), RangeError);
assertThrows(() => c('astronomical-unit'), RangeError);
assertThrows(() => c('bushel'), RangeError);
assertThrows(() => c('calorie'), RangeError);
assertThrows(() => c('carat'), RangeError);
assertThrows(() => c('centiliter'), RangeError);
assertThrows(() => c('century'), RangeError);
assertThrows(() => c('cubic-centimeter'), RangeError);
assertThrows(() => c('cubic-foot'), RangeError);
assertThrows(() => c('cubic-inch'), RangeError);
assertThrows(() => c('cubic-kilometer'), RangeError);
assertThrows(() => c('cubic-meter'), RangeError);
assertThrows(() => c('cubic-mile'), RangeError);
assertThrows(() => c('cubic-yard'), RangeError);
assertThrows(() => c('cup-metric'), RangeError);
assertThrows(() => c('cup'), RangeError);
assertThrows(() => c('day-person'), RangeError);
assertThrows(() => c('deciliter'), RangeError);
assertThrows(() => c('decimeter'), RangeError);
assertThrows(() => c('fathom'), RangeError);
assertThrows(() => c('foodcalorie'), RangeError);
assertThrows(() => c('furlong'), RangeError);
assertThrows(() => c('g-force'), RangeError);
assertThrows(() => c('gallon-imperial'), RangeError);
assertThrows(() => c('generic'), RangeError);
assertThrows(() => c('gigahertz'), RangeError);
assertThrows(() => c('gigawatt'), RangeError);
assertThrows(() => c('hectoliter'), RangeError);
assertThrows(() => c('hectopascal'), RangeError);
assertThrows(() => c('hertz'), RangeError);
assertThrows(() => c('horsepower'), RangeError);
assertThrows(() => c('inch-hg'), RangeError);
assertThrows(() => c('joule'), RangeError);
assertThrows(() => c('karat'), RangeError);
assertThrows(() => c('kelvin'), RangeError);
assertThrows(() => c('kilocalorie'), RangeError);
assertThrows(() => c('kilohertz'), RangeError);
assertThrows(() => c('kilojoule'), RangeError);
assertThrows(() => c('kilowatt-hour'), RangeError);
assertThrows(() => c('kilowatt'), RangeError);
assertThrows(() => c('knot'), RangeError);
assertThrows(() => c('light-year'), RangeError);
assertThrows(() => c('liter-per-100kilometers'), RangeError);
assertThrows(() => c('lux'), RangeError);
assertThrows(() => c('megahertz'), RangeError);
assertThrows(() => c('megaliter'), RangeError);
assertThrows(() => c('megawatt'), RangeError);
assertThrows(() => c('meter-per-second-squared'), RangeError);
assertThrows(() => c('metric-ton'), RangeError);
assertThrows(() => c('microgram'), RangeError);
assertThrows(() => c('micrometer'), RangeError);
assertThrows(() => c('mile-per-gallon-imperial'), RangeError);
assertThrows(() => c('milliampere'), RangeError);
assertThrows(() => c('millibar'), RangeError);
assertThrows(() => c('milligram-per-deciliter'), RangeError);
assertThrows(() => c('milligram'), RangeError);
assertThrows(() => c('millimeter-of-mercury'), RangeError);
assertThrows(() => c('millimole-per-liter'), RangeError);
assertThrows(() => c('milliwatt'), RangeError);
assertThrows(() => c('month-person'), RangeError);
assertThrows(() => c('nanometer'), RangeError);
assertThrows(() => c('nautical-mile'), RangeError);
assertThrows(() => c('ohm'), RangeError);
assertThrows(() => c('ounce-troy'), RangeError);
assertThrows(() => c('parsec'), RangeError);
assertThrows(() => c('part-per-million'), RangeError);
assertThrows(() => c('picometer'), RangeError);
assertThrows(() => c('pint-metric'), RangeError);
assertThrows(() => c('pint'), RangeError);
assertThrows(() => c('pound-per-square-inch'), RangeError);
assertThrows(() => c('quart'), RangeError);
assertThrows(() => c('radian'), RangeError);
assertThrows(() => c('revolution'), RangeError);
assertThrows(() => c('square-centimeter'), RangeError);
assertThrows(() => c('square-foot'), RangeError);
assertThrows(() => c('square-inch'), RangeError);
assertThrows(() => c('square-kilometer'), RangeError);
assertThrows(() => c('square-meter'), RangeError);
assertThrows(() => c('square-mile'), RangeError);
assertThrows(() => c('square-yard'), RangeError);
assertThrows(() => c('tablespoon'), RangeError);
assertThrows(() => c('teaspoon'), RangeError);
assertThrows(() => c('ton'), RangeError);
assertThrows(() => c('volt'), RangeError);
assertThrows(() => c('watt'), RangeError);
assertThrows(() => c('week-person'), RangeError);
assertThrows(() => c('year-person'), RangeError);

View File

@ -0,0 +1,34 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test default.
let nf = new Intl.NumberFormat();
assertEquals(undefined, nf.resolvedOptions().unitDisplay);
nf = new Intl.NumberFormat("en");
assertEquals(undefined, nf.resolvedOptions().unitDisplay);
nf = new Intl.NumberFormat("en", {style: 'decimal'});
assertEquals(undefined, nf.resolvedOptions().unitDisplay);
nf = new Intl.NumberFormat("en", {style: 'currency', currency: 'TWD'});
assertEquals(undefined, nf.resolvedOptions().unitDisplay);
nf = new Intl.NumberFormat("en", {style: 'unit', unit: "meter"});
assertEquals("short", nf.resolvedOptions().unitDisplay);
nf = new Intl.NumberFormat("en", {style: 'percent'});
assertEquals(undefined, nf.resolvedOptions().unitDisplay);
const testData = [
["short"],
["narrow"],
["long"],
];
for (const [unitDisplay] of testData) {
nf = new Intl.NumberFormat("en", {style: 'unit', unit: "meter", unitDisplay});
assertEquals('unit', nf.resolvedOptions().style);
assertEquals(unitDisplay, nf.resolvedOptions().unitDisplay);
}