Debian Codegraph @

js/src/tests/non262/Intl/NumberFormat/notation-compact-long.js

raw
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: "long",
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: "1 thousand", parts: [Integer("1"), Literal(" "), Compact("thousand")]},
24 {value: 10000, string: "10 thousand", parts: [Integer("10"), Literal(" "), Compact("thousand")]},
25 {value: 100000, string: "100 thousand", parts: [Integer("100"), Literal(" "), Compact("thousand")]},
26 {value: 1000000, string: "1 million", parts: [Integer("1"), Literal(" "), Compact("million")]},
27 {value: 10000000, string: "10 million", parts: [Integer("10"), Literal(" "), Compact("million")]},
28 {value: 100000000, string: "100 million", parts: [Integer("100"), Literal(" "), Compact("million")]},
29 {value: 1000000000, string: "1 billion", parts: [Integer("1"), Literal(" "), Compact("billion")]},
30 {value: 10000000000, string: "10 billion", parts: [Integer("10"), Literal(" "), Compact("billion")]},
31 {value: 100000000000, string: "100 billion", parts: [Integer("100"), Literal(" "), Compact("billion")]},
32 {value: 1000000000000, string: "1 trillion", parts: [Integer("1"), Literal(" "), Compact("trillion")]},
33 {value: 10000000000000, string: "10 trillion", parts: [Integer("10"), Literal(" "), Compact("trillion")]},
34 {value: 100000000000000, string: "100 trillion", parts: [Integer("100"), Literal(" "), Compact("trillion")]},
35 {value: 1000000000000000, string: "1000 trillion", parts: [Integer("1000"), Literal(" "), Compact("trillion")]},
36 {value: 10000000000000000, string: "10,000 trillion", parts: [Integer("10"), Group(","), Integer("000"), Literal(" "), Compact("trillion")]},
37 {value: 100000000000000000, string: "100,000 trillion", parts: [Integer("100"), Group(","), Integer("000"), Literal(" "), Compact("trillion")]},
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: "1 thousand", parts: [Integer("1"), Literal(" "), Compact("thousand")]},
43 {value: 10000n, string: "10 thousand", parts: [Integer("10"), Literal(" "), Compact("thousand")]},
44 {value: 100000n, string: "100 thousand", parts: [Integer("100"), Literal(" "), Compact("thousand")]},
45 {value: 1000000n, string: "1 million", parts: [Integer("1"), Literal(" "), Compact("million")]},
46 {value: 10000000n, string: "10 million", parts: [Integer("10"), Literal(" "), Compact("million")]},
47 {value: 100000000n, string: "100 million", parts: [Integer("100"), Literal(" "), Compact("million")]},
48 {value: 1000000000n, string: "1 billion", parts: [Integer("1"), Literal(" "), Compact("billion")]},
49 {value: 10000000000n, string: "10 billion", parts: [Integer("10"), Literal(" "), Compact("billion")]},
50 {value: 100000000000n, string: "100 billion", parts: [Integer("100"), Literal(" "), Compact("billion")]},
51 {value: 1000000000000n, string: "1 trillion", parts: [Integer("1"), Literal(" "), Compact("trillion")]},
52 {value: 10000000000000n, string: "10 trillion", parts: [Integer("10"), Literal(" "), Compact("trillion")]},
53 {value: 100000000000000n, string: "100 trillion", parts: [Integer("100"), Literal(" "), Compact("trillion")]},
54 {value: 1000000000000000n, string: "1000 trillion", parts: [Integer("1000"), Literal(" "), Compact("trillion")]},
55 {value: 10000000000000000n, string: "10,000 trillion", parts: [Integer("10"), Group(","), Integer("000"), Literal(" "), Compact("trillion")]},
56 {value: 100000000000000000n, string: "100,000 trillion", parts: [Integer("100"), Group(","), Integer("000"), Literal(" "), Compact("trillion")]},
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.2 thousand", parts: [Integer("1"), Decimal("."), Fraction("2"), Literal(" "), Compact("thousand")]},
69 {value: 12345, string: "12 thousand", parts: [Integer("12"), Literal(" "), Compact("thousand")]},
70 {value: 123456, string: "123 thousand", parts: [Integer("123"), Literal(" "), Compact("thousand")]},
71 {value: 1234567, string: "1.2 million", parts: [Integer("1"), Decimal("."), Fraction("2"), Literal(" "), Compact("million")]},
72 {value: 12345678, string: "12 million", parts: [Integer("12"), Literal(" "), Compact("million")]},
73 {value: 123456789, string: "123 million", parts: [Integer("123"), Literal(" "), Compact("million")]},
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 // The "{compactName}" placeholder may have different plural forms.
84 {
85 locale: "de",
86 options: {
87 notation: "compact",
88 compactDisplay: "long",
89 },
90 values: [
91 {value: 1e6, string: "1 Million", parts: [Integer("1"), Literal(" "), Compact("Million")]},
92 {value: 2e6, string: "2 Millionen", parts: [Integer("2"), Literal(" "), Compact("Millionen")]},
93 {value: 1e9, string: "1 Milliarde", parts: [Integer("1"), Literal(" "), Compact("Milliarde")]},
94 {value: 2e9, string: "2 Milliarden", parts: [Integer("2"), Literal(" "), Compact("Milliarden")]},
95 ],
96 },
97
98 // Digits are grouped in myriads (every 10,000) in Japanese.
99 {
100 locale: "ja",
101 options: {
102 notation: "compact",
103 compactDisplay: "long",
104 },
105 values: [
106 {value: 1, string: "1", parts: [Integer("1")]},
107 {value: 10, string: "10", parts: [Integer("10")]},
108 {value: 100, string: "100", parts: [Integer("100")]},
109 {value: 1000, string: "1000", parts: [Integer("1000")]},
110
111 {value: 10e3, string: "1\u4E07", parts: [Integer("1"), Compact("\u4E07")]},
112 {value: 100e3, string: "10\u4E07", parts: [Integer("10"), Compact("\u4E07")]},
113 {value: 1000e3, string: "100\u4E07", parts: [Integer("100"), Compact("\u4E07")]},
114 {value: 10000e3, string: "1000\u4E07", parts: [Integer("1000"), Compact("\u4E07")]},
115
116 {value: 10e7, string: "1\u5104", parts: [Integer("1"), Compact("\u5104")]},
117 {value: 100e7, string: "10\u5104", parts: [Integer("10"), Compact("\u5104")]},
118 {value: 1000e7, string: "100\u5104", parts: [Integer("100"), Compact("\u5104")]},
119 {value: 10000e7, string: "1000\u5104", parts: [Integer("1000"), Compact("\u5104")]},
120
121 {value: 10e11, string: "1\u5146", parts: [Integer("1"), Compact("\u5146")]},
122 {value: 100e11, string: "10\u5146", parts: [Integer("10"), Compact("\u5146")]},
123 {value: 1000e11, string: "100\u5146", parts: [Integer("100"), Compact("\u5146")]},
124 {value: 10000e11, string: "1000\u5146", parts: [Integer("1000"), Compact("\u5146")]},
125
126 {value: 10e15, string: "1\u4EAC", parts: [Integer("1"), Compact("\u4EAC")]},
127 {value: 100e15, string: "10\u4EAC", parts: [Integer("10"), Compact("\u4EAC")]},
128 {value: 1000e15, string: "100\u4EAC", parts: [Integer("100"), Compact("\u4EAC")]},
129 {value: 10000e15, string: "1000\u4EAC", parts: [Integer("1000"), Compact("\u4EAC")]},
130
131 {value: 100000e15, string: "10,000\u4EAC", parts: [Integer("10"), Group(","), Integer("000"), Compact("\u4EAC")]},
132 ],
133 },
134 ];
135
136 runNumberFormattingTestcases(testcases);
137
138 if (typeof reportCompare === "function")
139 reportCompare(true, true);