tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

notation-compact-short.js (8077B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 const {
      4    Nan, Inf, Integer, MinusSign, PlusSign, Decimal, Fraction, Group, Literal,
      5    Compact,
      6 } = NumberFormatParts;
      7 
      8 const testcases = [
      9    {
     10        locale: "en",
     11        options: {
     12            notation: "compact",
     13            compactDisplay: "short",
     14        },
     15        values: [
     16            {value: +0, string: "0", parts: [Integer("0")]},
     17            {value: -0, string: "-0", parts: [MinusSign("-"), Integer("0")]},
     18            {value: 0n, string: "0", parts: [Integer("0")]},
     19 
     20            {value: 1, string: "1", parts: [Integer("1")]},
     21            {value: 10, string: "10", parts: [Integer("10")]},
     22            {value: 100, string: "100", parts: [Integer("100")]},
     23            {value: 1000, string: "1K", parts: [Integer("1"), Compact("K")]},
     24            {value: 10000, string: "10K", parts: [Integer("10"), Compact("K")]},
     25            {value: 100000, string: "100K", parts: [Integer("100"), Compact("K")]},
     26            {value: 1000000, string: "1M", parts: [Integer("1"), Compact("M")]},
     27            {value: 10000000, string: "10M", parts: [Integer("10"), Compact("M")]},
     28            {value: 100000000, string: "100M", parts: [Integer("100"), Compact("M")]},
     29            {value: 1000000000, string: "1B", parts: [Integer("1"), Compact("B")]},
     30            {value: 10000000000, string: "10B", parts: [Integer("10"), Compact("B")]},
     31            {value: 100000000000, string: "100B", parts: [Integer("100"), Compact("B")]},
     32            {value: 1000000000000, string: "1T", parts: [Integer("1"), Compact("T")]},
     33            {value: 10000000000000, string: "10T", parts: [Integer("10"), Compact("T")]},
     34            {value: 100000000000000, string: "100T", parts: [Integer("100"), Compact("T")]},
     35            {value: 1000000000000000, string: "1000T", parts: [Integer("1000"), Compact("T")]},
     36            {value: 10000000000000000, string: "10,000T", parts: [Integer("10"), Group(","), Integer("000"), Compact("T")]},
     37            {value: 100000000000000000, string: "100,000T", parts: [Integer("100"), Group(","), Integer("000"), Compact("T")]},
     38 
     39            {value: 1n, string: "1", parts: [Integer("1")]},
     40            {value: 10n, string: "10", parts: [Integer("10")]},
     41            {value: 100n, string: "100", parts: [Integer("100")]},
     42            {value: 1000n, string: "1K", parts: [Integer("1"), Compact("K")]},
     43            {value: 10000n, string: "10K", parts: [Integer("10"), Compact("K")]},
     44            {value: 100000n, string: "100K", parts: [Integer("100"), Compact("K")]},
     45            {value: 1000000n, string: "1M", parts: [Integer("1"), Compact("M")]},
     46            {value: 10000000n, string: "10M", parts: [Integer("10"), Compact("M")]},
     47            {value: 100000000n, string: "100M", parts: [Integer("100"), Compact("M")]},
     48            {value: 1000000000n, string: "1B", parts: [Integer("1"), Compact("B")]},
     49            {value: 10000000000n, string: "10B", parts: [Integer("10"), Compact("B")]},
     50            {value: 100000000000n, string: "100B", parts: [Integer("100"), Compact("B")]},
     51            {value: 1000000000000n, string: "1T", parts: [Integer("1"), Compact("T")]},
     52            {value: 10000000000000n, string: "10T", parts: [Integer("10"), Compact("T")]},
     53            {value: 100000000000000n, string: "100T", parts: [Integer("100"), Compact("T")]},
     54            {value: 1000000000000000n, string: "1000T", parts: [Integer("1000"), Compact("T")]},
     55            {value: 10000000000000000n, string: "10,000T", parts: [Integer("10"), Group(","), Integer("000"), Compact("T")]},
     56            {value: 100000000000000000n, string: "100,000T", parts: [Integer("100"), Group(","), Integer("000"), Compact("T")]},
     57 
     58            {value: 0.1, string: "0.1", parts: [Integer("0"), Decimal("."), Fraction("1")]},
     59            {value: 0.01, string: "0.01", parts: [Integer("0"), Decimal("."), Fraction("01")]},
     60            {value: 0.001, string: "0.001", parts: [Integer("0"), Decimal("."), Fraction("001")]},
     61            {value: 0.0001, string: "0.0001", parts: [Integer("0"), Decimal("."), Fraction("0001")]},
     62            {value: 0.00001, string: "0.00001", parts: [Integer("0"), Decimal("."), Fraction("00001")]},
     63            {value: 0.000001, string: "0.000001", parts: [Integer("0"), Decimal("."), Fraction("000001")]},
     64            {value: 0.0000001, string: "0.0000001", parts: [Integer("0"), Decimal("."), Fraction("0000001")]},
     65 
     66            {value: 12, string: "12", parts: [Integer("12")]},
     67            {value: 123, string: "123", parts: [Integer("123")]},
     68            {value: 1234, string: "1.2K", parts: [Integer("1"), Decimal("."), Fraction("2"), Compact("K")]},
     69            {value: 12345, string: "12K", parts: [Integer("12"), Compact("K")]},
     70            {value: 123456, string: "123K", parts: [Integer("123"), Compact("K")]},
     71            {value: 1234567, string: "1.2M", parts: [Integer("1"), Decimal("."), Fraction("2"), Compact("M")]},
     72            {value: 12345678, string: "12M", parts: [Integer("12"), Compact("M")]},
     73            {value: 123456789, string: "123M", parts: [Integer("123"), Compact("M")]},
     74 
     75            {value:  Infinity, string: "∞", parts: [Inf("∞")]},
     76            {value: -Infinity, string: "-∞", parts: [MinusSign("-"), Inf("∞")]},
     77 
     78            {value:  NaN, string: "NaN", parts: [Nan("NaN")]},
     79            {value: -NaN, string: "NaN", parts: [Nan("NaN")]},
     80        ],
     81    },
     82 
     83    // Compact symbol can consist of multiple characters, e.g. when it's an abbreviation.
     84    {
     85        locale: "de",
     86        options: {
     87            notation: "compact",
     88            compactDisplay: "short",
     89        },
     90        values: [
     91            {value: 1e6, string: "1\u00A0Mio.", parts: [Integer("1"), Literal("\u00A0"), Compact("Mio.")]},
     92            {value: 1e9, string: "1\u00A0Mrd.", parts: [Integer("1"), Literal("\u00A0"), Compact("Mrd.")]},
     93            {value: 1e12, string: "1\u00A0Bio.", parts: [Integer("1"), Literal("\u00A0"), Compact("Bio.")]},
     94 
     95            // CLDR doesn't support "Billiarde" (Brd.), Trillion (Trill.), etc.
     96            {value: 1e15, string: "1000\u00A0Bio.", parts: [Integer("1000"), Literal("\u00A0"), Compact("Bio.")]},
     97        ],
     98    },
     99 
    100    // Digits are grouped in myriads (every 10,000) in Chinese.
    101    {
    102        locale: "zh",
    103        options: {
    104            notation: "compact",
    105            compactDisplay: "short",
    106        },
    107        values: [
    108            {value: 1, string: "1", parts: [Integer("1")]},
    109            {value: 10, string: "10", parts: [Integer("10")]},
    110            {value: 100, string: "100", parts: [Integer("100")]},
    111            {value: 1000, string: "1000", parts: [Integer("1000")]},
    112 
    113            {value: 10e3, string: "1\u4E07", parts: [Integer("1"), Compact("\u4E07")]},
    114            {value: 100e3, string: "10\u4E07", parts: [Integer("10"), Compact("\u4E07")]},
    115            {value: 1000e3, string: "100\u4E07", parts: [Integer("100"), Compact("\u4E07")]},
    116            {value: 10000e3, string: "1000\u4E07", parts: [Integer("1000"), Compact("\u4E07")]},
    117 
    118            {value: 10e7, string: "1\u4EBF", parts: [Integer("1"), Compact("\u4EBF")]},
    119            {value: 100e7, string: "10\u4EBF", parts: [Integer("10"), Compact("\u4EBF")]},
    120            {value: 1000e7, string: "100\u4EBF", parts: [Integer("100"), Compact("\u4EBF")]},
    121            {value: 10000e7, string: "1000\u4EBF", parts: [Integer("1000"), Compact("\u4EBF")]},
    122 
    123            {value: 10e11, string: "1\u4E07\u4EBF", parts: [Integer("1"), Compact("\u4E07\u4EBF")]},
    124            {value: 100e11, string: "10\u4E07\u4EBF", parts: [Integer("10"), Compact("\u4E07\u4EBF")]},
    125            {value: 1000e11, string: "100\u4E07\u4EBF", parts: [Integer("100"), Compact("\u4E07\u4EBF")]},
    126            {value: 10000e11, string: "1000\u4E07\u4EBF", parts: [Integer("1000"), Compact("\u4E07\u4EBF")]},
    127 
    128            {value: 100000e11, string: "10,000\u4E07\u4EBF", parts: [Integer("10"), Group(","), Integer("000"), Compact("\u4E07\u4EBF")]},
    129        ],
    130    },
    131 ];
    132 
    133 runNumberFormattingTestcases(testcases);
    134 
    135 if (typeof reportCompare === "function")
    136    reportCompare(true, true);