intl: refactor tests for NumberFormat

This commit is contained in:
Ujjwal Sharma 2018-09-18 23:34:15 +05:30 committed by Rick Waldron
parent 21f0cc4b29
commit 0c89259da5
6 changed files with 63 additions and 83 deletions

View File

@ -0,0 +1,21 @@
// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: >
Tests that Intl.NumberFormat.prototype.format throws a TypeError
if called on a non-object value or an object that hasn't been
initialized as a NumberFormat.
---*/
const invalidTargets = [undefined, null, true, 0, 'NumberFormat', [], {}, Symbol()];
const fn = Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, 'format').get;
invalidTargets.forEach(target => {
assert.throws(
TypeError,
() => fn.call(target),
`Calling format getter on ${target} was not rejected.`
);
});

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: >
Throws a TypeError if this is not a NumberFormat object
---*/
var formatToParts = Intl.NumberFormat.prototype.formatToParts;
assert.throws(TypeError, function() {
formatToParts.call({});
}, "{}");
assert.throws(TypeError, function() {
formatToParts.call(new Number());
}, "new Number()");

View File

@ -1,39 +0,0 @@
// Copyright 2016 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Throws a TypeError if this is not Object
features: [Symbol]
---*/
var formatToParts = Intl.NumberFormat.prototype.formatToParts;
assert.throws(TypeError, function() {
formatToParts.call(undefined);
}, "undefined");
assert.throws(TypeError, function() {
formatToParts.call(null);
}, "null");
assert.throws(TypeError, function() {
formatToParts.call(42);
}, "number");
assert.throws(TypeError, function() {
formatToParts.call("foo");
}, "string");
assert.throws(TypeError, function() {
formatToParts.call(false);
}, "false");
assert.throws(TypeError, function() {
formatToParts.call(true);
}, "true");
var s = Symbol('1');
assert.throws(TypeError, function() {
formatToParts.call(s);
}, "symbol");

View File

@ -0,0 +1,21 @@
// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.NumberFormat.prototype.formatToParts
description: >
Tests that Intl.NumberFormat.prototype.formatToParts throws a
TypeError if called on a non-object value or an object that hasn't
been initialized as a NumberFormat.
---*/
const invalidTargets = [undefined, null, true, 0, 'NumberFormat', [], {}, Symbol()];
const fn = Intl.NumberFormat.prototype.formatToParts;
invalidTargets.forEach(target => {
assert.throws(
TypeError,
() => fn.call(target),
`Calling formatToParts on ${target} was not rejected.`
);
});

View File

@ -0,0 +1,21 @@
// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.NumberFormat.prototype.resolvedOptions
description: >
Tests that Intl.NumberFormat.prototype.resolvedOptions throws a
TypeError if called on a non-object value or an object that hasn't
been initialized as a NumberFormat.
---*/
const invalidTargets = [undefined, null, true, 0, 'NumberFormat', [], {}, Symbol()];
const fn = Intl.NumberFormat.prototype.resolvedOptions;
invalidTargets.forEach(target => {
assert.throws(
TypeError,
() => fn.call(target),
`Calling resolvedOptions on ${target} was not rejected.`
);
});

View File

@ -1,27 +0,0 @@
// Copyright 2012 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 11.3_b
description: >
Tests that Intl.NumberFormat.prototype functions throw a
TypeError if called on a non-object value or an object that hasn't
been initialized as a NumberFormat.
author: Norbert Lindenberg
---*/
var functions = {
"format getter": Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get,
formatToParts: Intl.NumberFormat.prototype.formatToParts,
resolvedOptions: Intl.NumberFormat.prototype.resolvedOptions
};
var invalidTargets = [undefined, null, true, 0, "NumberFormat", [], {}, Symbol()];
Object.getOwnPropertyNames(functions).forEach(function (functionName) {
var f = functions[functionName];
invalidTargets.forEach(function (target) {
assert.throws(TypeError, function() {
f.call(target);
}, "Calling " + functionName + " on " + target + " was not rejected.");
});
});