browser_num-l10n.js (1764B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that the localization utils work properly. 7 8 function test() { 9 const l10n = new LocalizationHelper(); 10 11 is( 12 l10n.numberWithDecimals(1234.56789, 2), 13 "1,234.57", 14 "The first number was properly localized." 15 ); 16 is( 17 l10n.numberWithDecimals(0.0001, 2), 18 "0", 19 "The second number was properly localized." 20 ); 21 is( 22 l10n.numberWithDecimals(1.0001, 2), 23 "1", 24 "The third number was properly localized." 25 ); 26 is(l10n.numberWithDecimals(NaN, 2), "0", "NaN was properly localized."); 27 is(l10n.numberWithDecimals(null, 2), "0", "`null` was properly localized."); 28 is( 29 l10n.numberWithDecimals(undefined, 2), 30 "0", 31 "`undefined` was properly localized." 32 ); 33 is( 34 l10n.numberWithDecimals(-1234.56789, 2), 35 "-1,234.57", 36 "Negative number was properly localized." 37 ); 38 is( 39 l10n.numberWithDecimals(1234.56789, 0), 40 "1,235", 41 "Number was properly localized with decimals set 0." 42 ); 43 is( 44 l10n.numberWithDecimals(-1234.56789, 0), 45 "-1,235", 46 "Negative number was properly localized with decimals set 0." 47 ); 48 is( 49 l10n.numberWithDecimals(12, 2), 50 "12", 51 "The integer was properly localized, without decimals." 52 ); 53 is( 54 l10n.numberWithDecimals(-12, 2), 55 "-12", 56 "The negative integer was properly localized, without decimals." 57 ); 58 is( 59 l10n.numberWithDecimals(1200, 2), 60 "1,200", 61 "The big integer was properly localized, no decimals but with a separator." 62 ); 63 is( 64 l10n.numberWithDecimals(-1200, 2), 65 "-1,200", 66 "The negative big integer was properly localized, no decimals but with a separator." 67 ); 68 69 finish(); 70 }