Add tests for "Intl NumberFormat v3" proposal

This patch is intended to cover only one aspect of the proposal for
ECMA402: the "rounding mode" feature.
This commit is contained in:
Mike Pennisi 2021-10-13 13:38:48 -04:00 committed by Rick Waldron
parent 37e2c66420
commit 057c8acec7
11 changed files with 315 additions and 0 deletions

View File

@ -178,6 +178,10 @@ coalesce-expression
# https://github.com/tc39-transfer/proposal-intl-displaynames
Intl.DisplayNames
# Intl.NumberFormat V3
# https://github.com/tc39/proposal-intl-numberformat-v3
Intl.NumberFormat-v3
# Promise.any
# https://github.com/tc39/proposal-promise-any
Promise.any

View File

@ -0,0 +1,17 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-initializenumberformat
description: >
Exception from accessing the "roundingMode" option for the NumberFormat
constructor should be propagated to the caller
features: [Intl.NumberFormat-v3]
---*/
assert.throws(Test262Error, function() {
new Intl.NumberFormat('en', {
get roundingMode() {
throw new Test262Error();
}
});
});

View File

@ -0,0 +1,32 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "ceil", rounding tends toward positive infinity
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'ceil', maximumSignificantDigits: 2},
{
'1.101': '1.2',
'1.15': '1.2',
'1.1999': '1.2',
'1.25': '1.3',
'0': '0',
'-0': '-0',
'-1.101': '-1.1',
'-1.15': '-1.1',
'-1.1999': '-1.1',
'-1.25': '-1.2'
}
);

View File

@ -0,0 +1,32 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "expand", rounding tends away from zero
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'expand', maximumSignificantDigits: 2},
{
'1.101': '1.2',
'1.15': '1.2',
'1.1999': '1.2',
'1.25': '1.3',
'0': '0',
'-0': '-0',
'-1.101': '-1.2',
'-1.15': '-1.2',
'-1.1999': '-1.2',
'-1.25': '-1.3'
}
);

View File

@ -0,0 +1,32 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "floor", rounding tends toward negative infinity
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'floor', maximumSignificantDigits: 2},
{
'1.101': '1.1',
'1.15': '1.1',
'1.1999': '1.1',
'1.25': '1.2',
'0': '0',
'-0': '-0',
'-1.101': '-1.2',
'-1.15': '-1.2',
'-1.1999': '-1.2',
'-1.25': '-1.3'
}
);

View File

@ -0,0 +1,33 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "halfExpand", rounding tends toward the closest value
with ties tending toward positive infinity
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'halfCeil', maximumSignificantDigits: 2},
{
'1.101': '1.1',
'1.15': '1.2',
'1.1999': '1.2',
'1.25': '1.3',
'0': '0',
'-0': '-0',
'-1.101': '-1.1',
'-1.15': '-1.1',
'-1.1999': '-1.2',
'-1.25': '-1.2'
}
);

View File

@ -0,0 +1,34 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "halfEven", rounding tends toward the closest value
with ties tending toward the value with even cardinality
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'halfEven', maximumSignificantDigits: 2},
{
'1.101': '1.1',
'1.15': '1.2',
'1.1999': '1.2',
'1.25': '1.2',
'0': '0',
'-0': '-0',
'-1.101': '-1.1',
'-1.15': '-1.2',
'-1.1999': '-1.2',
'-1.25': '-1.2'
}
);

View File

@ -0,0 +1,33 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "halfExpand", rounding tends toward the closest value
with ties tending away from zero
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'halfExpand', maximumSignificantDigits: 2},
{
'1.101': '1.1',
'1.15': '1.2',
'1.1999': '1.2',
'1.25': '1.3',
'0': '0',
'-0': '-0',
'-1.101': '-1.1',
'-1.15': '-1.2',
'-1.1999': '-1.2',
'-1.25': '-1.3'
}
);

View File

@ -0,0 +1,33 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "halfFloor", rounding tends toward the closest value
with ties tending toward negative infinity
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'halfFloor', maximumSignificantDigits: 2},
{
'1.101': '1.1',
'1.15': '1.1',
'1.1999': '1.2',
'1.25': '1.2',
'0': '0',
'-0': '-0',
'-1.101': '-1.1',
'-1.15': '-1.2',
'-1.1999': '-1.2',
'-1.25': '-1.3'
}
);

View File

@ -0,0 +1,33 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "halfTrunc", rounding tends toward the closest value
with ties tending toward zero
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'halfTrunc', maximumSignificantDigits: 2},
{
'1.101': '1.1',
'1.15': '1.1',
'1.1999': '1.2',
'1.25': '1.2',
'0': '0',
'-0': '-0',
'-1.101': '-1.1',
'-1.15': '-1.1',
'-1.1999': '-1.2',
'-1.25': '-1.2'
}
);

View File

@ -0,0 +1,32 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
When roundingMode is "trunc", rounding tends toward zero
features: [Intl.NumberFormat-v3]
includes: [testIntl.js]
---*/
var locales = [
new Intl.NumberFormat().resolvedOptions().locale, 'ar', 'de', 'th', 'ja'
];
var numberingSystems = ['arab', 'latn', 'thai', 'hanidec'];
testNumberFormat(
locales,
numberingSystems,
{useGrouping: false, roundingMode: 'trunc', maximumSignificantDigits: 2},
{
'1.101': '1.1',
'1.15': '1.1',
'1.1999': '1.1',
'1.25': '1.2',
'0': '0',
'-0': '-0',
'-1.101': '-1.1',
'-1.15': '-1.1',
'-1.1999': '-1.1',
'-1.25': '-1.2'
}
);