From 0c89259da59be6a18ea736d9327a60eb4803f92b Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma <usharma1998@gmail.com> Date: Tue, 18 Sep 2018 23:34:15 +0530 Subject: [PATCH] intl: refactor tests for NumberFormat --- .../format/this-value-not-numberformat.js | 21 ++++++++++ .../this-has-not-internal-throws.js | 17 -------- .../this-is-not-object-throws.js | 39 ------------------- .../this-value-not-numberformat.js | 21 ++++++++++ .../this-value-not-numberformat.js | 21 ++++++++++ .../prototype/this-value-not-numberformat.js | 27 ------------- 6 files changed, 63 insertions(+), 83 deletions(-) create mode 100644 test/intl402/NumberFormat/prototype/format/this-value-not-numberformat.js delete mode 100644 test/intl402/NumberFormat/prototype/formatToParts/this-has-not-internal-throws.js delete mode 100644 test/intl402/NumberFormat/prototype/formatToParts/this-is-not-object-throws.js create mode 100644 test/intl402/NumberFormat/prototype/formatToParts/this-value-not-numberformat.js create mode 100644 test/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js delete mode 100644 test/intl402/NumberFormat/prototype/this-value-not-numberformat.js diff --git a/test/intl402/NumberFormat/prototype/format/this-value-not-numberformat.js b/test/intl402/NumberFormat/prototype/format/this-value-not-numberformat.js new file mode 100644 index 0000000000..50e9c2ac07 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/format/this-value-not-numberformat.js @@ -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.` + ); +}); diff --git a/test/intl402/NumberFormat/prototype/formatToParts/this-has-not-internal-throws.js b/test/intl402/NumberFormat/prototype/formatToParts/this-has-not-internal-throws.js deleted file mode 100644 index c478c92c5c..0000000000 --- a/test/intl402/NumberFormat/prototype/formatToParts/this-has-not-internal-throws.js +++ /dev/null @@ -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()"); diff --git a/test/intl402/NumberFormat/prototype/formatToParts/this-is-not-object-throws.js b/test/intl402/NumberFormat/prototype/formatToParts/this-is-not-object-throws.js deleted file mode 100644 index def58e3d54..0000000000 --- a/test/intl402/NumberFormat/prototype/formatToParts/this-is-not-object-throws.js +++ /dev/null @@ -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"); - diff --git a/test/intl402/NumberFormat/prototype/formatToParts/this-value-not-numberformat.js b/test/intl402/NumberFormat/prototype/formatToParts/this-value-not-numberformat.js new file mode 100644 index 0000000000..2bba25c1f7 --- /dev/null +++ b/test/intl402/NumberFormat/prototype/formatToParts/this-value-not-numberformat.js @@ -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.` + ); +}); diff --git a/test/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js b/test/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js new file mode 100644 index 0000000000..bed737badd --- /dev/null +++ b/test/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js @@ -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.` + ); +}); diff --git a/test/intl402/NumberFormat/prototype/this-value-not-numberformat.js b/test/intl402/NumberFormat/prototype/this-value-not-numberformat.js deleted file mode 100644 index a5bfcbddc9..0000000000 --- a/test/intl402/NumberFormat/prototype/this-value-not-numberformat.js +++ /dev/null @@ -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."); - }); -}); -- GitLab