intl: rework Intl.NumberFormat.prototype.formatToParts tests

Rework the available tests for Intl.NumberFormat.prototype.formatToParts
to improve consistency and readability.
This commit is contained in:
Ujjwal Sharma 2018-09-27 05:07:46 +05:30 committed by Rick Waldron
parent 41bf0ee344
commit 5fae9deb1f
4 changed files with 79 additions and 57 deletions

View File

@ -1,17 +0,0 @@
// Copyright 2016 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Property type and descriptor.
includes: [propertyHelper.js]
---*/
assert.sameValue(
typeof Intl.NumberFormat.prototype.formatToParts,
'function',
'`typeof Intl.NumberFormat.prototype.formatToParts` is `function`'
);
verifyNotEnumerable(Intl.NumberFormat.prototype, 'formatToParts');
verifyWritable(Intl.NumberFormat.prototype, 'formatToParts');
verifyConfigurable(Intl.NumberFormat.prototype, 'formatToParts');

View File

@ -0,0 +1,37 @@
// Copyright 2016 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: >
"formatToParts" property of Intl.NumberFormat.prototype.
info: |
11.4.4 Intl.NumberFormat.prototype.formatToParts
7 Requirements for Standard Built-in ECMAScript Objects
Unless specified otherwise in this document, the objects, functions, and constructors
described in this standard are subject to the generic requirements and restrictions
specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language
Specification, 9th edition, clause 17, or successor.
17 ECMAScript Standard Built-in Objects:
Every accessor property described in clauses 18 through 26 and in Annex B.2 has the
attributes { [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified.
If only a get accessor function is described, the set accessor function is the default
value, undefined. If only a set accessor is described the get accessor is the default
value, undefined.
includes: [propertyHelper.js]
---*/
assert.sameValue(
typeof Intl.NumberFormat.prototype.formatToParts,
'function',
'`typeof Intl.NumberFormat.prototype.formatToParts` is `function`'
);
verifyNotEnumerable(Intl.NumberFormat.prototype, 'formatToParts');
verifyWritable(Intl.NumberFormat.prototype, 'formatToParts');
verifyConfigurable(Intl.NumberFormat.prototype, 'formatToParts');

View File

@ -1,40 +0,0 @@
// Copyright 2016 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
//
/*---
description: >
Return abrupt completions from ToNumber(date)
info: |
Intl.NumberFormat.prototype.formatToParts ([ value ])
5. Let _x_ be ? ToNumber(_value_).
features: [Symbol]
---*/
var obj1 = {
valueOf: function() {
throw new Test262Error();
}
};
var obj2 = {
toString: function() {
throw new Test262Error();
}
};
var nf = new Intl.NumberFormat(["pt-BR"]);
assert.throws(Test262Error, function() {
nf.formatToParts(obj1);
}, "valueOf");
assert.throws(Test262Error, function() {
nf.formatToParts(obj2);
}, "toString");
var s = Symbol('1');
assert.throws(TypeError, function() {
nf.formatToParts(s);
}, "symbol");

View File

@ -0,0 +1,42 @@
// Copyright 2016 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.formattoparts
description: >
Tests that Intl.NumberFormat.prototype.formatToParts converts
its argument (called value) to a number using ToNumber (7.1.3).
info: |
11.1.4 Number Format Functions
4. Let x be ? ToNumber(value).
features: [Symbol]
---*/
const toNumberResults = [
[undefined, NaN],
[null, +0],
[true, 1],
[false, 0],
['42', 42],
['foo', NaN]
];
const nf = new Intl.NumberFormat();
toNumberResults.forEach(pair => {
const [value, result] = pair;
assert.sameValue(nf.formatToParts(value), nf.formatToParts(result));
});
let count = 0;
const dummy = {};
dummy[Symbol.toPrimitive] = hint => (hint === 'number' ? ++count : NaN);
assert.sameValue(nf.formatToParts(dummy), nf.formatToParts(count));
assert.sameValue(count, 1);
assert.throws(
TypeError,
() => nf.formatToParts(Symbol()),
"ToNumber(arg) throws a TypeError when arg is of type 'Symbol'"
);