2012-08-27 05:50:24 +02:00
|
|
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
2022-01-11 07:56:30 +01:00
|
|
|
// Copyright 2022 Apple Inc. All rights reserved.
|
2022-09-02 14:19:38 +02:00
|
|
|
// Copyright 2022 Igalia, S.L. All rights reserved.
|
2012-08-27 05:50:24 +02:00
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
|
2014-07-22 01:09:02 +02:00
|
|
|
/*---
|
2014-07-25 00:41:42 +02:00
|
|
|
es5id: 11.1.1_34
|
2014-07-22 01:09:02 +02:00
|
|
|
description: Tests that the option useGrouping is processed correctly.
|
2021-11-06 00:09:10 +01:00
|
|
|
info: |
|
|
|
|
The "Intl.NumberFormat v3" proposal contradicts the behavior required by the
|
2022-09-02 14:19:38 +02:00
|
|
|
latest revision of ECMA402.
|
2014-07-22 01:09:02 +02:00
|
|
|
author: Norbert Lindenberg
|
2022-01-11 07:56:30 +01:00
|
|
|
features: [Intl.NumberFormat-v3]
|
2014-07-22 01:09:02 +02:00
|
|
|
---*/
|
2012-08-27 05:50:24 +02:00
|
|
|
|
2022-01-11 07:56:30 +01:00
|
|
|
function resolveUseGrouping(option) {
|
|
|
|
return new Intl.NumberFormat(undefined, { useGrouping: option }).resolvedOptions().useGrouping;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let string of ["min2", "auto", "always"]) {
|
|
|
|
assert.sameValue(resolveUseGrouping(string), string);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.sameValue(resolveUseGrouping(true), "always");
|
|
|
|
assert.sameValue(resolveUseGrouping(false), false);
|
|
|
|
assert.sameValue(resolveUseGrouping(undefined), "auto");
|
2022-09-02 14:19:38 +02:00
|
|
|
assert.sameValue(resolveUseGrouping("true"), "auto");
|
|
|
|
assert.sameValue(resolveUseGrouping("false"), "auto");
|
2022-01-11 07:56:30 +01:00
|
|
|
|
|
|
|
for (let falsy of [0, null, ""]) {
|
|
|
|
assert.sameValue(resolveUseGrouping(falsy), false);
|
|
|
|
}
|
|
|
|
|
2022-09-13 10:45:41 +02:00
|
|
|
for (let invalidOptions of [42, "MIN2", {} , "True", "TRUE" , "FALSE" , "False" , "Undefined" , "undefined"]) {
|
2022-09-02 14:19:38 +02:00
|
|
|
assert.throws(RangeError, function () {
|
|
|
|
return new Intl.NumberFormat(undefined, { useGrouping: invalidOptions });
|
|
|
|
}, "Throws RangeError when useGrouping value is not supported");
|
2022-01-11 07:56:30 +01:00
|
|
|
}
|
2022-09-02 14:19:38 +02:00
|
|
|
|
|
|
|
|