mirror of https://github.com/tc39/test262.git
Add tests for "Intl NumberFormat v3" proposal
This patch is intended to cover only one aspect of the proposal for ECMA402: the "grouping enum" feature. It also includes coverage for the formatting option as already defined by the latest version of ECMA402.
This commit is contained in:
parent
de8faff7d7
commit
ef78452924
|
@ -0,0 +1,29 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [de-DE]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('de-DE', {});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '(omitted)');
|
||||
assert.sameValue(nf.format(1000), '1.000', '(omitted)');
|
||||
assert.sameValue(nf.format(10000), '10.000', '(omitted)');
|
||||
|
||||
nf = new Intl.NumberFormat('de-DE', {useGrouping: true});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'true');
|
||||
assert.sameValue(nf.format(1000), '1.000', 'true');
|
||||
assert.sameValue(nf.format(10000), '10.000', 'true');
|
||||
|
||||
nf = new Intl.NumberFormat('de-DE', {useGrouping: false});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'false');
|
||||
assert.sameValue(nf.format(1000), '1000', 'false');
|
||||
assert.sameValue(nf.format(10000), '10000', 'false');
|
|
@ -0,0 +1,29 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [en-US]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('en-US', {});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '(omitted)');
|
||||
assert.sameValue(nf.format(1000), '1,000', '(omitted)');
|
||||
assert.sameValue(nf.format(10000), '10,000', '(omitted)');
|
||||
|
||||
nf = new Intl.NumberFormat('en-US', {useGrouping: true});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'true');
|
||||
assert.sameValue(nf.format(1000), '1,000', 'true');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'true');
|
||||
|
||||
nf = new Intl.NumberFormat('en-US', {useGrouping: false});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'false');
|
||||
assert.sameValue(nf.format(1000), '1000', 'false');
|
||||
assert.sameValue(nf.format(10000), '10000', 'false');
|
|
@ -0,0 +1,30 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [de-DE]
|
||||
features: [Intl.NumberFormat-v3]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('de-DE', {useGrouping: 'always'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"always"');
|
||||
assert.sameValue(nf.format(1000), '1.000', '"always"');
|
||||
assert.sameValue(nf.format(10000), '10.000', '"always"');
|
||||
|
||||
nf = new Intl.NumberFormat('de-DE', {useGrouping: 'min2'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"min2"');
|
||||
assert.sameValue(nf.format(1000), '1000', '"min2"');
|
||||
assert.sameValue(nf.format(10000), '10.000', '"min2"');
|
||||
|
||||
nf = new Intl.NumberFormat('de-DE', {notation: 'compact'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(1000), '1000', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(10000), '10.000', 'notation: "compact"');
|
|
@ -0,0 +1,30 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [en-US]
|
||||
features: [Intl.NumberFormat-v3]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('en-US', {useGrouping: 'always'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"always"');
|
||||
assert.sameValue(nf.format(1000), '1,000', '"always"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"always"');
|
||||
|
||||
nf = new Intl.NumberFormat('en-US', {useGrouping: 'min2'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"min2"');
|
||||
assert.sameValue(nf.format(1000), '1000', '"min2"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"min2"');
|
||||
|
||||
nf = new Intl.NumberFormat('en-US', {notation: 'compact'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(1000), '1000', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'notation: "compact"');
|
|
@ -0,0 +1,30 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [ja-JP]
|
||||
features: [Intl.NumberFormat-v3]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('ja-JP', {useGrouping: 'always'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"always"');
|
||||
assert.sameValue(nf.format(1000), '1,000', '"always"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"always"');
|
||||
|
||||
nf = new Intl.NumberFormat('ja-JP', {useGrouping: 'min2'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"min2"');
|
||||
assert.sameValue(nf.format(1000), '1000', '"min2"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"min2"');
|
||||
|
||||
nf = new Intl.NumberFormat('ja-JP', {notation: 'compact'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(1000), '1000', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'notation: "compact"');
|
|
@ -0,0 +1,30 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [ko-KR]
|
||||
features: [Intl.NumberFormat-v3]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('ko-KR', {useGrouping: 'always'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"always"');
|
||||
assert.sameValue(nf.format(1000), '1,000', '"always"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"always"');
|
||||
|
||||
nf = new Intl.NumberFormat('ko-KR', {useGrouping: 'min2'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"min2"');
|
||||
assert.sameValue(nf.format(1000), '1000', '"min2"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"min2"');
|
||||
|
||||
nf = new Intl.NumberFormat('ko-KR', {notation: 'compact'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(1000), '1000', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'notation: "compact"');
|
|
@ -0,0 +1,30 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [zh-TW]
|
||||
features: [Intl.NumberFormat-v3]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('zh-TW', {useGrouping: 'always'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"always"');
|
||||
assert.sameValue(nf.format(1000), '1,000', '"always"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"always"');
|
||||
|
||||
nf = new Intl.NumberFormat('zh-TW', {useGrouping: 'min2'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '"min2"');
|
||||
assert.sameValue(nf.format(1000), '1000', '"min2"');
|
||||
assert.sameValue(nf.format(10000), '10,000', '"min2"');
|
||||
|
||||
nf = new Intl.NumberFormat('zh-TW', {notation: 'compact'});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(1000), '1000', 'notation: "compact"');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'notation: "compact"');
|
|
@ -0,0 +1,29 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [ja-JP]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('ja-JP', {});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '(omitted)');
|
||||
assert.sameValue(nf.format(1000), '1,000', '(omitted)');
|
||||
assert.sameValue(nf.format(10000), '10,000', '(omitted)');
|
||||
|
||||
nf = new Intl.NumberFormat('ja-JP', {useGrouping: true});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'true');
|
||||
assert.sameValue(nf.format(1000), '1,000', 'true');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'true');
|
||||
|
||||
nf = new Intl.NumberFormat('ja-JP', {useGrouping: false});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'false');
|
||||
assert.sameValue(nf.format(1000), '1000', 'false');
|
||||
assert.sameValue(nf.format(10000), '10000', 'false');
|
|
@ -0,0 +1,29 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [ko-KR]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('ko-KR', {});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '(omitted)');
|
||||
assert.sameValue(nf.format(1000), '1,000', '(omitted)');
|
||||
assert.sameValue(nf.format(10000), '10,000', '(omitted)');
|
||||
|
||||
nf = new Intl.NumberFormat('ko-KR', {useGrouping: true});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'true');
|
||||
assert.sameValue(nf.format(1000), '1,000', 'true');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'true');
|
||||
|
||||
nf = new Intl.NumberFormat('ko-KR', {useGrouping: false});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'false');
|
||||
assert.sameValue(nf.format(1000), '1000', 'false');
|
||||
assert.sameValue(nf.format(10000), '10000', 'false');
|
|
@ -0,0 +1,29 @@
|
|||
// 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: |
|
||||
Checks handling of the useGrouping option to the NumberFormat constructor.
|
||||
locale: [zh-TW]
|
||||
---*/
|
||||
|
||||
var nf;
|
||||
|
||||
nf = new Intl.NumberFormat('zh-TW', {});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', '(omitted)');
|
||||
assert.sameValue(nf.format(1000), '1,000', '(omitted)');
|
||||
assert.sameValue(nf.format(10000), '10,000', '(omitted)');
|
||||
|
||||
nf = new Intl.NumberFormat('zh-TW', {useGrouping: true});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'true');
|
||||
assert.sameValue(nf.format(1000), '1,000', 'true');
|
||||
assert.sameValue(nf.format(10000), '10,000', 'true');
|
||||
|
||||
nf = new Intl.NumberFormat('zh-TW', {useGrouping: false});
|
||||
|
||||
assert.sameValue(nf.format(100), '100', 'false');
|
||||
assert.sameValue(nf.format(1000), '1000', 'false');
|
||||
assert.sameValue(nf.format(10000), '10000', 'false');
|
|
@ -0,0 +1,53 @@
|
|||
// 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: Tests that the option useGrouping is processed correctly.
|
||||
info: |
|
||||
The "Intl.NumberFormat v3" proposal contradicts the behavior required by the
|
||||
latest revision of ECMA402. Likewise, this test contradicts
|
||||
test-option-useGrouping.js. Until the proposal is included in a published
|
||||
standard (when the tests' discrepancies can be resolved), implementations
|
||||
should only expect to pass one of these two tests.
|
||||
features: [Intl.NumberFormat-v3]
|
||||
---*/
|
||||
|
||||
function render(options) {
|
||||
var nf = new Intl.NumberFormat(undefined, options);
|
||||
return nf.resolvedOptions().useGrouping;
|
||||
}
|
||||
|
||||
assert.sameValue(render({}), 'auto', '(omitted)');
|
||||
assert.sameValue(render({useGrouping: undefined}), 'auto', 'undefined');
|
||||
assert.sameValue(render({useGrouping: 'auto'}), 'auto', '"auto"');
|
||||
assert.sameValue(render({useGrouping: true}), 'always', 'true');
|
||||
assert.sameValue(render({useGrouping: 'always'}), 'always', '"always"');
|
||||
assert.sameValue(render({useGrouping: false}), false, 'false');
|
||||
assert.sameValue(render({useGrouping: null}), false, 'null');
|
||||
assert.sameValue(render({useGrouping: 'min2'}), 'min2', '"min2"');
|
||||
|
||||
assert.sameValue(render({notation: 'compact'}), 'min2', 'compact, (omitted)');
|
||||
assert.sameValue(render({notation: 'compact', useGrouping: undefined}), 'min2', 'compact, undefined');
|
||||
assert.sameValue(render({notation: 'compact', useGrouping: 'auto'}), 'auto', 'compact, "auto"');
|
||||
assert.sameValue(render({notation: 'compact', useGrouping: true}), 'always', 'compact, true');
|
||||
assert.sameValue(render({notation: 'compact', useGrouping: 'always'}), 'always', 'compact, "always"');
|
||||
assert.sameValue(render({notation: 'compact', useGrouping: false}), false, 'compact, false');
|
||||
assert.sameValue(render({notation: 'compact', useGrouping: null}), false, 'compact, null');
|
||||
assert.sameValue(render({notation: 'compact', useGrouping: 'min2'}), 'min2', 'compact, "min2"');
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new Intl.NumberFormat(undefined, {useGrouping: 'undefined'});
|
||||
}, '"undefined"');
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new Intl.NumberFormat(undefined, {useGrouping: 'false'});
|
||||
}, '"false"');
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new Intl.NumberFormat(undefined, {useGrouping: 'true'});
|
||||
}, '"true"');
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new Intl.NumberFormat(undefined, {useGrouping: 'min3'});
|
||||
}, '"min3"');
|
|
@ -4,6 +4,12 @@
|
|||
/*---
|
||||
es5id: 11.1.1_34
|
||||
description: Tests that the option useGrouping is processed correctly.
|
||||
info: |
|
||||
The "Intl.NumberFormat v3" proposal contradicts the behavior required by the
|
||||
latest revision of ECMA402. Likewise, this test contradicts
|
||||
test-option-useGrouping-extended.js. Until the proposal is included in a
|
||||
published standard (when the tests' discrepancies can be resolved),
|
||||
implementations should only expect to pass one of these two tests.
|
||||
author: Norbert Lindenberg
|
||||
includes: [testIntl.js]
|
||||
---*/
|
||||
|
|
Loading…
Reference in New Issue