constructor-roundingIncrement.js (1262B)
1 // Copyright 2021 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-initializenumberformat 5 description: Checks handling of the roundingIncrement option to the NumberFormat constructor. 6 includes: [compareArray.js] 7 features: [Intl.NumberFormat-v3] 8 ---*/ 9 10 const values = [ 11 [undefined, 1], 12 [1, 1], 13 [2, 2], 14 [5, 5], 15 [10, 10], 16 [20, 20], 17 [25, 25], 18 [50, 50], 19 [100, 100], 20 [200, 200], 21 [250, 250], 22 [500, 500], 23 [1000, 1000], 24 [2000, 2000], 25 [2500, 2500], 26 [5000, 5000], 27 [true, 1], 28 ["2", 2], 29 [{valueOf: function() { return 5; }}, 5], 30 ]; 31 32 for (const [value, expected] of values) { 33 const callOrder = []; 34 const nf = new Intl.NumberFormat([], { 35 get notation() { 36 callOrder.push("notation"); 37 return "standard"; 38 }, 39 get roundingIncrement() { 40 callOrder.push("roundingIncrement"); 41 return value; 42 }, 43 minimumFractionDigits: 3 44 }); 45 const resolvedOptions = nf.resolvedOptions(); 46 assert("roundingIncrement" in resolvedOptions, "has property for value " + value); 47 assert.sameValue(resolvedOptions.roundingIncrement, expected); 48 49 assert.compareArray(callOrder, ["notation", "roundingIncrement"]); 50 } 51 52 reportCompare(0, 0);