mirror of https://github.com/tc39/test262.git
intl: refactor tests for NumberFormat
This commit is contained in:
parent
21f0cc4b29
commit
0c89259da5
|
@ -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.`
|
||||
);
|
||||
});
|
|
@ -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()");
|
|
@ -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");
|
||||
|
21
test/intl402/NumberFormat/prototype/formatToParts/this-value-not-numberformat.js
vendored
Normal file
21
test/intl402/NumberFormat/prototype/formatToParts/this-value-not-numberformat.js
vendored
Normal 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.`
|
||||
);
|
||||
});
|
21
test/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js
vendored
Normal file
21
test/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js
vendored
Normal 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.`
|
||||
);
|
||||
});
|
|
@ -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.");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue