constructor-locales-toobject.js (1440B)
1 // Copyright (C) 2018 Ujjwal Sharma. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-initializenumberformat 6 description: > 7 Tests that Intl.NumberFormat contructor converts the locales argument 8 to an object using `ToObject` (7.1.13). 9 info: | 10 9.2.1 CanonicalizeLocaleList 11 12 4.a. Let O be ? ToObject(locales). 13 ---*/ 14 15 const toObjectResults = [ 16 [true, new Boolean(true)], 17 [42, new Number(42)], 18 [{}, {}], 19 [Symbol(), Object(Symbol())] 20 ]; 21 22 // Test if ToObject is used to convert primitives to Objects. 23 toObjectResults.forEach(pair => { 24 const [value, result] = pair; 25 const actual = new Intl.NumberFormat(value).resolvedOptions(); 26 const expected = new Intl.NumberFormat(result).resolvedOptions() 27 28 assert.sameValue(actual.locale, expected.locale); 29 assert.sameValue(actual.minimumIntegerDigits, expected.minimumIntegerDigits); 30 assert.sameValue(actual.minimumFractionDigits, expected.minimumFractionDigits); 31 assert.sameValue(actual.maximumFractionDigits, expected.maximumFractionDigits); 32 assert.sameValue(actual.numberingSystem, expected.numberingSystem); 33 assert.sameValue(actual.style, expected.style); 34 assert.sameValue(actual.useGrouping, expected.useGrouping); 35 }); 36 37 // ToObject throws a TypeError for undefined and null, but it's not called 38 // when locales is undefined. 39 assert.throws(TypeError, () => new Intl.NumberFormat(null)); 40 41 reportCompare(0, 0);