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