tor-browser

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

currency-sign-accounting.js (7372B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 const {
      4    Nan, Inf, Integer, MinusSign, PlusSign, Decimal, Fraction,
      5    Currency, Literal,
      6 } = NumberFormatParts;
      7 
      8 const testcases = [
      9    // "auto": Show the sign on negative numbers only.
     10    {
     11        locale: "en",
     12        options: {
     13            style: "currency",
     14            currency: "USD",
     15            currencySign: "accounting",
     16            signDisplay: "auto",
     17        },
     18        values: [
     19            {value: +0, string: "$0.00",
     20             parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
     21            {value: -0, string: "($0.00)",
     22             parts: [Literal("("), Currency("$"), Integer("0"), Decimal("."), Fraction("00"), Literal(")")]},
     23 
     24            {value:  1, string: "$1.00",
     25             parts: [Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
     26            {value: -1, string: "($1.00)",
     27             parts: [Literal("("), Currency("$"), Integer("1"), Decimal("."), Fraction("00"), Literal(")")]},
     28 
     29            {value:  Infinity, string: "$∞", parts: [Currency("$"), Inf("∞")]},
     30            {value: -Infinity, string: "($∞)", parts: [Literal("("), Currency("$"), Inf("∞"), Literal(")")]},
     31 
     32            {value:  NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
     33            {value: -NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
     34        ],
     35    },
     36 
     37    // "never": Show the sign on neither positive nor negative numbers.
     38    {
     39        locale: "en",
     40        options: {
     41            style: "currency",
     42            currency: "USD",
     43            currencySign: "accounting",
     44            signDisplay: "never",
     45        },
     46        values: [
     47            {value: +0, string: "$0.00", parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
     48            {value: -0, string: "$0.00", parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
     49 
     50            {value:  1, string: "$1.00", parts: [Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
     51            {value: -1, string: "$1.00", parts: [Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
     52 
     53            {value:  Infinity, string: "$∞", parts: [Currency("$"), Inf("∞")]},
     54            {value: -Infinity, string: "$∞", parts: [Currency("$"), Inf("∞")]},
     55 
     56            {value:  NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
     57            {value: -NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
     58        ],
     59    },
     60 
     61    // "always": Show the sign on positive and negative numbers including zero.
     62    {
     63        locale: "en",
     64        options: {
     65            style: "currency",
     66            currency: "USD",
     67            currencySign: "accounting",
     68            signDisplay: "always",
     69        },
     70        values: [
     71            {value: +0, string: "+$0.00",
     72             parts: [PlusSign("+"), Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
     73            {value: -0, string: "($0.00)",
     74             parts: [Literal("("), Currency("$"), Integer("0"), Decimal("."), Fraction("00"), Literal(")")]},
     75 
     76            {value:  1, string: "+$1.00",
     77             parts: [PlusSign("+"), Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
     78            {value: -1, string: "($1.00)",
     79             parts: [Literal("("), Currency("$"), Integer("1"), Decimal("."), Fraction("00"), Literal(")")]},
     80 
     81            {value:  Infinity, string: "+$∞", parts: [PlusSign("+"), Currency("$"), Inf("∞")]},
     82            {value: -Infinity, string: "($∞)", parts: [Literal("("), Currency("$"), Inf("∞"), Literal(")")]},
     83 
     84            {value:  NaN, string: "+$NaN", parts: [PlusSign("+"), Currency("$"), Nan("NaN")]},
     85            {value: -NaN, string: "+$NaN", parts: [PlusSign("+"), Currency("$"), Nan("NaN")]},
     86        ],
     87    },
     88 
     89    // "exceptZero": Show the sign on positive and negative numbers but not zero.
     90    {
     91        locale: "en",
     92        options: {
     93            style: "currency",
     94            currency: "USD",
     95            currencySign: "accounting",
     96            signDisplay: "exceptZero",
     97        },
     98        values: [
     99            {value: +0, string: "$0.00",
    100             parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
    101            {value: -0, string: "$0.00",
    102             parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
    103 
    104            {value:  1, string: "+$1.00",
    105             parts: [PlusSign("+"), Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
    106            {value: -1, string: "($1.00)",
    107             parts: [Literal("("), Currency("$"), Integer("1"), Decimal("."), Fraction("00"), Literal(")")]},
    108 
    109            {value:  Infinity, string: "+$∞", parts: [PlusSign("+"), Currency("$"), Inf("∞")]},
    110            {value: -Infinity, string: "($∞)", parts: [Literal("("), Currency("$"), Inf("∞"), Literal(")")]},
    111 
    112            {value:  NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
    113            {value: -NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
    114        ],
    115    },
    116 
    117    // Tests with suppressed fractional digits.
    118 
    119    // "auto": Show the sign on negative numbers only.
    120    {
    121        locale: "en",
    122        options: {
    123            style: "currency",
    124            currency: "USD",
    125            currencySign: "accounting",
    126            signDisplay: "auto",
    127            minimumFractionDigits: 0,
    128            maximumFractionDigits: 0,
    129        },
    130        values: [
    131            {value: +0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
    132            {value: -0.1, string: "($0)", parts: [Literal("("), Currency("$"), Integer("0"), Literal(")")]},
    133        ],
    134    },
    135 
    136    // "never": Show the sign on neither positive nor negative numbers.
    137    {
    138        locale: "en",
    139        options: {
    140            style: "currency",
    141            currency: "USD",
    142            currencySign: "accounting",
    143            signDisplay: "never",
    144            minimumFractionDigits: 0,
    145            maximumFractionDigits: 0,
    146        },
    147        values: [
    148            {value: +0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
    149            {value: -0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
    150        ],
    151    },
    152 
    153    // "always": Show the sign on positive and negative numbers including zero.
    154    {
    155        locale: "en",
    156        options: {
    157            style: "currency",
    158            currency: "USD",
    159            currencySign: "accounting",
    160            signDisplay: "always",
    161            minimumFractionDigits: 0,
    162            maximumFractionDigits: 0,
    163        },
    164        values: [
    165            {value: +0.1, string: "+$0", parts: [PlusSign("+"), Currency("$"), Integer("0")]},
    166            {value: -0.1, string: "($0)", parts: [Literal("("), Currency("$"), Integer("0"), Literal(")")]},
    167        ],
    168    },
    169 
    170    // "exceptZero": Show the sign on positive and negative numbers but not zero.
    171    {
    172        locale: "en",
    173        options: {
    174            style: "currency",
    175            currency: "USD",
    176            currencySign: "accounting",
    177            signDisplay: "exceptZero",
    178            minimumFractionDigits: 0,
    179            maximumFractionDigits: 0,
    180        },
    181 
    182        values: [
    183            {value: +0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
    184            {value: -0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
    185        ],
    186    }
    187 ];
    188 
    189 runNumberFormattingTestcases(testcases);
    190 
    191 if (typeof reportCompare === "function")
    192    reportCompare(true, true);