formatRangeToParts-approximately-sign-percent.js (1100B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 3 if (typeof getAvailableLocalesOf === "undefined") { 4 var getAvailableLocalesOf = SpecialPowers.Cu.getJSTestingFunctions().getAvailableLocalesOf; 5 } 6 7 const numbers = [ 8 0, 1, 2, 5, 10, 100, 1000, 10_000, 100_000, 1_000_000, 9 0.1, 0.2, 0.5, 1.5, 10 -0, -1, -2, -5, 11 Infinity, -Infinity, 12 ]; 13 14 const options = {style: "percent"}; 15 16 // List of known approximately sign in CLDR 46. 17 const approximatelySigns = [ 18 "-", "~", "∼", "≈", "≃", "ca.", "約", "dáàṣì", "dáàshì", 19 ]; 20 21 // Iterate over all locales and ensure we find exactly one approximately sign. 22 for (let locale of getAvailableLocalesOf("NumberFormat").sort()) { 23 let nf = new Intl.NumberFormat(locale, options); 24 for (let number of numbers) { 25 let parts = nf.formatRangeToParts(number, number); 26 let approx = parts.filter(part => part.type === "approximatelySign"); 27 28 assertEq(approx.length, 1); 29 assertEq(approximatelySigns.some(approxSign => approx[0].value.includes(approxSign)), true); 30 } 31 } 32 33 if (typeof reportCompare === "function") 34 reportCompare(true, true);