intl: increase coverage for NumberFormat.format

Increase test coverage for Intl.NumberFormat.prototype.format by adding
a check for testing if it calls ToNumber (7.1.3) on its argument.
This commit is contained in:
Ujjwal Sharma 2018-09-20 01:53:52 +05:30 committed by Rick Waldron
parent a6412918d2
commit 7a87bde265
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-number-format-functions
description: >
Tests that Intl.NumberFormat.prototype.format converts its argument
(called value) to a number using ToNumber (7.1.3).
info: |
11.1.4Number 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 = pair[0];
const result = pair[1];
assert.sameValue(nf.format(value), nf.format(result));
});
assert.throws(
TypeError,
() => nf.format(Symbol()),
"ToNumber(arg) throws a TypeError when arg is of type 'Symbol'"
);