From bb7585bdafacac7a533b842c4c3030cb76c0f160 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Fri, 28 Sep 2018 14:56:07 +0530 Subject: [PATCH] intl: increase coverage for NumberFormat constructor Increase coverage for the Intl.NumberFormat class contructor by adding tests for checking that it calls ToObject on the options argument. --- .../constructor-options-toobject.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/intl402/NumberFormat/constructor-options-toobject.js diff --git a/test/intl402/NumberFormat/constructor-options-toobject.js b/test/intl402/NumberFormat/constructor-options-toobject.js new file mode 100644 index 0000000000..a305512b54 --- /dev/null +++ b/test/intl402/NumberFormat/constructor-options-toobject.js @@ -0,0 +1,32 @@ +// Copyright (C) 2018 Ujjwal Sharma. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializenumberformat +description: > + Tests that Intl.NumberFormat contructor converts the options argument + to an object using `ToObject` (7.1.13). +info: | + 11.1.2 InitializeNumberFormat + + 3.a. Let options be ? ToObject(options). +---*/ + +const toObjectResults = [ + [true, new Boolean(true)], + [42, new Number(42)], + ['foo', new String('foo')] +]; + +// Test if ToObject is used to convert primitives to Objects. +toObjectResults.forEach(pair => { + const [value, result] = pair; + assert.sameValue( + new Intl.NumberFormat(['en-US'], value).resolvedOptions(), + new Intl.NumberFormat(['en-US'], result).resolvedOptions() + ); +}); + +// ToObject throws a TypeError for undefined and null, but it's not called +// when options is undefined. +assert.throws(TypeError, () => new Intl.NumberFormat(['en-US'], null));