]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-loss-of-precision.js
c690dd7e1bc45cdd0a0f445e4f0660d6fe4d8e18
2 *@fileoverview Tests for no-loss-of-precision rule.
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-loss-of-precision"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("no-loss-of-precision", rule
, {
36 "var x = 12300000000000000000000000",
37 "var x = -12300000000000000000000000",
38 "var x = 0.00000000000000000000000123",
39 "var x = -0.00000000000000000000000123",
40 "var x = 9007199254740991",
43 "var x = 0.000000000000000000000000000000000000000000000000000000000000000000000000000000",
45 "var x = 123.0000000000000000000000",
50 { code
: "var x = 12_34_56", parserOptions
: { ecmaVersion
: 2021 } },
51 { code
: "var x = 12_3.4_56", parserOptions
: { ecmaVersion
: 2021 } },
52 { code
: "var x = -12_3.4_56", parserOptions
: { ecmaVersion
: 2021 } },
53 { code
: "var x = -12_34_56", parserOptions
: { ecmaVersion
: 2021 } },
54 { code
: "var x = 12_3e3_4", parserOptions
: { ecmaVersion
: 2021 } },
55 { code
: "var x = 123.0e3_4", parserOptions
: { ecmaVersion
: 2021 } },
56 { code
: "var x = 12_3e-3_4", parserOptions
: { ecmaVersion
: 2021 } },
57 { code
: "var x = 12_3.0e-3_4", parserOptions
: { ecmaVersion
: 2021 } },
58 { code
: "var x = -1_23e-3_4", parserOptions
: { ecmaVersion
: 2021 } },
59 { code
: "var x = -1_23.8e-3_4", parserOptions
: { ecmaVersion
: 2021 } },
60 { code
: "var x = 1_230000000_00000000_00000_000", parserOptions
: { ecmaVersion
: 2021 } },
61 { code
: "var x = -1_230000000_00000000_00000_000", parserOptions
: { ecmaVersion
: 2021 } },
62 { code
: "var x = 0.0_00_000000000_000000000_00123", parserOptions
: { ecmaVersion
: 2021 } },
63 { code
: "var x = -0.0_00_000000000_000000000_00123", parserOptions
: { ecmaVersion
: 2021 } },
64 { code
: "var x = 0e5_3", parserOptions
: { ecmaVersion
: 2021 } },
66 { code
: "var x = 0b11111111111111111111111111111111111111111111111111111", parserOptions
: { ecmaVersion
: 6 } },
67 { code
: "var x = 0b111_111_111_111_1111_11111_111_11111_1111111111_11111111_111_111", parserOptions
: { ecmaVersion
: 2021 } },
69 { code
: "var x = 0B11111111111111111111111111111111111111111111111111111", parserOptions
: { ecmaVersion
: 6 } },
70 { code
: "var x = 0B111_111_111_111_1111_11111_111_11111_1111111111_11111111_111_111", parserOptions
: { ecmaVersion
: 2021 } },
72 { code
: "var x = 0o377777777777777777", parserOptions
: { ecmaVersion
: 6 } },
73 { code
: "var x = 0o3_77_777_777_777_777_777", parserOptions
: { ecmaVersion
: 2021 } },
74 { code
: "var x = 0O377777777777777777", parserOptions
: { ecmaVersion
: 6 } },
76 "var x = 0377777777777777777",
77 "var x = 0x1FFFFFFFFFFFFF",
78 "var x = 0X1FFFFFFFFFFFFF",
87 "var x = '9007199254740993'",
89 { code
: "var x = 0x1FFF_FFFF_FFF_FFF", parserOptions
: { ecmaVersion
: 2021 } },
90 { code
: "var x = 0X1_FFF_FFFF_FFF_FFF", parserOptions
: { ecmaVersion
: 2021 } }
94 code
: "var x = 9007199254740993",
95 errors
: [{ messageId
: "noLossOfPrecision" }]
98 code
: "var x = 9007199254740.993e3",
99 errors
: [{ messageId
: "noLossOfPrecision" }]
102 code
: "var x = 9.007199254740993e15",
103 errors
: [{ messageId
: "noLossOfPrecision" }]
106 code
: "var x = -9007199254740993",
107 errors
: [{ messageId
: "noLossOfPrecision" }]
110 code
: "var x = 900719.9254740994",
111 errors
: [{ messageId
: "noLossOfPrecision" }]
114 code
: "var x = -900719.9254740994",
115 errors
: [{ messageId
: "noLossOfPrecision" }]
118 code
: "var x = 900719925474099_3",
119 parserOptions
: { ecmaVersion
: 2021 },
120 errors
: [{ messageId
: "noLossOfPrecision" }]
123 code
: "var x = 90_0719925_4740.9_93e3",
124 parserOptions
: { ecmaVersion
: 2021 },
125 errors
: [{ messageId
: "noLossOfPrecision" }]
128 code
: "var x = 9.0_0719925_474099_3e15",
129 parserOptions
: { ecmaVersion
: 2021 },
130 errors
: [{ messageId
: "noLossOfPrecision" }]
133 code
: "var x = -9_00719_9254_740993",
134 parserOptions
: { ecmaVersion
: 2021 },
135 errors
: [{ messageId
: "noLossOfPrecision" }]
138 code
: "var x = 900_719.92_54740_994",
139 parserOptions
: { ecmaVersion
: 2021 },
140 errors
: [{ messageId
: "noLossOfPrecision" }]
143 code
: "var x = -900_719.92_5474_0994",
144 parserOptions
: { ecmaVersion
: 2021 },
145 errors
: [{ messageId
: "noLossOfPrecision" }]
148 code
: "var x = 5123000000000000000000000000001",
149 errors
: [{ messageId
: "noLossOfPrecision" }]
152 code
: "var x = -5123000000000000000000000000001",
153 errors
: [{ messageId
: "noLossOfPrecision" }]
156 code
: "var x = 1230000000000000000000000.0",
157 errors
: [{ messageId
: "noLossOfPrecision" }]
160 code
: "var x = 1.0000000000000000000000123",
161 errors
: [{ messageId
: "noLossOfPrecision" }]
164 code
: "var x = 17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430592",
165 errors
: [{ messageId
: "noLossOfPrecision" }]
168 code
: "var x = 2e999",
169 errors
: [{ messageId
: "noLossOfPrecision" }]
172 code
: "var x = .1230000000000000000000000",
173 errors
: [{ messageId
: "noLossOfPrecision" }]
176 code
: "var x = 0b100000000000000000000000000000000000000000000000000001",
177 parserOptions
: { ecmaVersion
: 6 },
178 errors
: [{ messageId
: "noLossOfPrecision" }]
181 code
: "var x = 0B100000000000000000000000000000000000000000000000000001",
182 parserOptions
: { ecmaVersion
: 6 },
183 errors
: [{ messageId
: "noLossOfPrecision" }]
186 code
: "var x = 0o400000000000000001",
187 parserOptions
: { ecmaVersion
: 6 },
188 errors
: [{ messageId
: "noLossOfPrecision" }]
191 code
: "var x = 0O400000000000000001",
192 parserOptions
: { ecmaVersion
: 6 },
193 errors
: [{ messageId
: "noLossOfPrecision" }]
196 code
: "var x = 0400000000000000001",
197 errors
: [{ messageId
: "noLossOfPrecision" }]
200 code
: "var x = 0x20000000000001",
201 errors
: [{ messageId
: "noLossOfPrecision" }]
204 code
: "var x = 0X20000000000001",
205 errors
: [{ messageId
: "noLossOfPrecision" }]
208 code
: "var x = 5123_00000000000000000000000000_1",
209 parserOptions
: { ecmaVersion
: 2021 },
210 errors
: [{ messageId
: "noLossOfPrecision" }]
213 code
: "var x = -5_12300000000000000000000_0000001",
214 parserOptions
: { ecmaVersion
: 2021 },
215 errors
: [{ messageId
: "noLossOfPrecision" }]
218 code
: "var x = 123_00000000000000000000_00.0_0",
219 parserOptions
: { ecmaVersion
: 2021 },
220 errors
: [{ messageId
: "noLossOfPrecision" }]
223 code
: "var x = 1.0_00000000000000000_0000123",
224 parserOptions
: { ecmaVersion
: 2021 },
225 errors
: [{ messageId
: "noLossOfPrecision" }]
228 code
: "var x = 174_980057982_640953949800178169_409709228253554471456994_914061648512796239935950073857881054_1618443059_2",
229 parserOptions
: { ecmaVersion
: 2021 },
230 errors
: [{ messageId
: "noLossOfPrecision" }]
233 code
: "var x = 2e9_99",
234 parserOptions
: { ecmaVersion
: 2021 },
235 errors
: [{ messageId
: "noLossOfPrecision" }]
238 code
: "var x = .1_23000000000000_00000_0000_0",
239 parserOptions
: { ecmaVersion
: 2021 },
240 errors
: [{ messageId
: "noLossOfPrecision" }]
243 code
: "var x = 0b1_0000000000000000000000000000000000000000000000000000_1",
244 parserOptions
: { ecmaVersion
: 2021 },
245 errors
: [{ messageId
: "noLossOfPrecision" }]
248 code
: "var x = 0B10000000000_0000000000000000000000000000_000000000000001",
249 parserOptions
: { ecmaVersion
: 2021 },
250 errors
: [{ messageId
: "noLossOfPrecision" }]
253 code
: "var x = 0o4_00000000000000_001",
254 parserOptions
: { ecmaVersion
: 2021 },
255 errors
: [{ messageId
: "noLossOfPrecision" }]
258 code
: "var x = 0O4_0000000000000000_1",
259 parserOptions
: { ecmaVersion
: 2021 },
260 errors
: [{ messageId
: "noLossOfPrecision" }]
263 code
: "var x = 0x2_0000000000001",
264 parserOptions
: { ecmaVersion
: 2021 },
265 errors
: [{ messageId
: "noLossOfPrecision" }]
268 code
: "var x = 0X200000_0000000_1",
269 parserOptions
: { ecmaVersion
: 2021 },
270 errors
: [{ messageId
: "noLossOfPrecision" }]