]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-loss-of-precision.js
update to 7.1.0 sources
[pve-eslint.git] / eslint / tests / lib / rules / no-loss-of-precision.js
1 /**
2 *@fileoverview Tests for no-loss-of-precision rule.
3 *@author Jacob Moore
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-loss-of-precision"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Helpers
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-loss-of-precision", rule, {
22 valid: [
23 "var x = 12345",
24 "var x = 123.456",
25 "var x = -123.456",
26 "var x = -123456",
27 "var x = 123e34",
28 "var x = 123.0e34",
29 "var x = 123e-34",
30 "var x = -123e34",
31 "var x = -123e-34",
32 "var x = 12.3e34",
33 "var x = 12.3e-34",
34 "var x = -12.3e34",
35 "var x = -12.3e-34",
36 "var x = 12300000000000000000000000",
37 "var x = -12300000000000000000000000",
38 "var x = 0.00000000000000000000000123",
39 "var x = -0.00000000000000000000000123",
40 "var x = 9007199254740991",
41 "var x = 0",
42 "var x = 0.0",
43 "var x = 0.000000000000000000000000000000000000000000000000000000000000000000000000000000",
44 "var x = -0",
45 "var x = 123.0000000000000000000000",
46 "var x = 019.5",
47 "var x = 0195",
48 "var x = 0e5",
49
50
51 { code: "var x = 0b11111111111111111111111111111111111111111111111111111", parserOptions: { ecmaVersion: 6 } },
52 { code: "var x = 0B11111111111111111111111111111111111111111111111111111", parserOptions: { ecmaVersion: 6 } },
53
54 { code: "var x = 0o377777777777777777", parserOptions: { ecmaVersion: 6 } },
55 { code: "var x = 0O377777777777777777", parserOptions: { ecmaVersion: 6 } },
56 "var x = 0377777777777777777",
57
58 "var x = 0x1FFFFFFFFFFFFF",
59 "var x = 0X1FFFFFFFFFFFFF",
60 "var x = true",
61 "var x = 'abc'",
62 "var x = ''",
63 "var x = null",
64 "var x = undefined",
65 "var x = {}",
66 "var x = ['a', 'b']",
67 "var x = new Date()",
68 "var x = '9007199254740993'"
69
70 ],
71 invalid: [
72 {
73 code: "var x = 9007199254740993",
74 errors: [{ messageId: "noLossOfPrecision" }]
75 },
76 {
77 code: "var x = 9007199254740.993e3",
78 errors: [{ messageId: "noLossOfPrecision" }]
79 },
80 {
81 code: "var x = 9.007199254740993e15",
82 errors: [{ messageId: "noLossOfPrecision" }]
83 },
84 {
85 code: "var x = -9007199254740993",
86 errors: [{ messageId: "noLossOfPrecision" }]
87 },
88 {
89 code: "var x = 900719.9254740994",
90 errors: [{ messageId: "noLossOfPrecision" }]
91 },
92 {
93 code: "var x = -900719.9254740994",
94 errors: [{ messageId: "noLossOfPrecision" }]
95 },
96
97 {
98 code: "var x = 5123000000000000000000000000001",
99 errors: [{ messageId: "noLossOfPrecision" }]
100 },
101 {
102 code: "var x = -5123000000000000000000000000001",
103 errors: [{ messageId: "noLossOfPrecision" }]
104 },
105 {
106 code: "var x = 1230000000000000000000000.0",
107 errors: [{ messageId: "noLossOfPrecision" }]
108 },
109 {
110 code: "var x = 1.0000000000000000000000123",
111 errors: [{ messageId: "noLossOfPrecision" }]
112 },
113 {
114 code: "var x = 17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430592",
115 errors: [{ messageId: "noLossOfPrecision" }]
116 },
117 {
118 code: "var x = 2e999",
119 errors: [{ messageId: "noLossOfPrecision" }]
120 },
121 {
122 code: "var x = .1230000000000000000000000",
123 errors: [{ messageId: "noLossOfPrecision" }]
124 },
125 {
126 code: "var x = 0b100000000000000000000000000000000000000000000000000001",
127 parserOptions: { ecmaVersion: 6 },
128 errors: [{ messageId: "noLossOfPrecision" }]
129 },
130 {
131 code: "var x = 0B100000000000000000000000000000000000000000000000000001",
132 parserOptions: { ecmaVersion: 6 },
133 errors: [{ messageId: "noLossOfPrecision" }]
134 },
135 {
136 code: "var x = 0o400000000000000001",
137 parserOptions: { ecmaVersion: 6 },
138 errors: [{ messageId: "noLossOfPrecision" }]
139 },
140 {
141 code: "var x = 0O400000000000000001",
142 parserOptions: { ecmaVersion: 6 },
143 errors: [{ messageId: "noLossOfPrecision" }]
144 },
145 {
146 code: "var x = 0400000000000000001",
147 errors: [{ messageId: "noLossOfPrecision" }]
148 },
149 {
150 code: "var x = 0x20000000000001",
151 errors: [{ messageId: "noLossOfPrecision" }]
152 },
153 {
154 code: "var x = 0X20000000000001",
155 errors: [{ messageId: "noLossOfPrecision" }]
156 }
157
158 ]
159 });