Skip to content

Commit f42f61f

Browse files
committed
Rewrite tests
1 parent 1c78d0c commit f42f61f

File tree

3 files changed

+222
-86
lines changed

3 files changed

+222
-86
lines changed

test/no-zero-fractions.mjs

Lines changed: 14 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ import {getTester} from './utils/test.mjs';
22

33
const {test} = getTester(import.meta);
44

5-
const MESSAGE_ZERO_FRACTION = 'zero-fraction';
6-
const MESSAGE_DANGLING_DOT = 'dangling-dot';
7-
const errorZeroFraction = {
8-
messageId: MESSAGE_ZERO_FRACTION
9-
};
10-
const errorDanglingDot = {
11-
messageId: MESSAGE_DANGLING_DOT
12-
};
13-
14-
test({
5+
test.snapshot({
156
valid: [
167
'const foo = "123.1000"',
178
'foo("123.1000")',
@@ -24,84 +15,21 @@ test({
2415
'const foo = 123123123.4',
2516
'const foo = 1e3'
2617
],
27-
invalid: [
28-
{
29-
code: 'const foo = 1.0',
30-
output: 'const foo = 1',
31-
errors: [errorZeroFraction]
32-
},
33-
{
34-
code: 'const foo = 1.0 + 1',
35-
output: 'const foo = 1 + 1',
36-
errors: [errorZeroFraction]
37-
},
38-
{
39-
code: 'foo(1.0 + 1)',
40-
output: 'foo(1 + 1)',
41-
errors: [errorZeroFraction]
42-
},
43-
{
44-
code: 'const foo = 1.00',
45-
output: 'const foo = 1',
46-
errors: [errorZeroFraction]
47-
},
48-
{
49-
code: 'const foo = 1.00000',
50-
output: 'const foo = 1',
51-
errors: [errorZeroFraction]
52-
},
53-
{
54-
code: 'const foo = -1.0',
55-
output: 'const foo = -1',
56-
errors: [errorZeroFraction]
57-
},
58-
{
59-
code: 'const foo = 123123123.0',
60-
output: 'const foo = 123123123',
61-
errors: [errorZeroFraction]
62-
},
63-
{
64-
code: 'const foo = 123.11100000000',
65-
output: 'const foo = 123.111',
66-
errors: [errorZeroFraction]
67-
},
68-
{
69-
code: 'const foo = 1.',
70-
output: 'const foo = 1',
71-
errors: [errorDanglingDot]
72-
},
73-
{
74-
code: 'const foo = +1.',
75-
output: 'const foo = +1',
76-
errors: [errorDanglingDot]
77-
},
78-
{
79-
code: 'const foo = -1.',
80-
output: 'const foo = -1',
81-
errors: [errorDanglingDot]
82-
},
83-
{
84-
code: 'const foo = 1.e10',
85-
output: 'const foo = 1e10',
86-
errors: [errorDanglingDot]
87-
},
88-
{
89-
code: 'const foo = +1.e-10',
90-
output: 'const foo = +1e-10',
91-
errors: [errorDanglingDot]
92-
},
93-
{
94-
code: 'const foo = -1.e+10',
95-
output: 'const foo = -1e+10',
96-
errors: [errorDanglingDot]
97-
}
98-
]
99-
});
100-
101-
test.snapshot({
102-
valid: [],
10318
invalid: [
10419
'const foo = 1.0',
20+
'const foo = 1.0 + 1',
21+
'foo(1.0 + 1)',
22+
'const foo = 1.00',
23+
'const foo = 1.00000',
24+
'const foo = -1.0',
25+
'const foo = 123123123.0',
26+
'const foo = 123.11100000000',
27+
'const foo = 1.',
28+
'const foo = +1.',
29+
'const foo = -1.',
30+
'const foo = 1.e10',
31+
'const foo = +1.e-10',
32+
'const foo = -1.e+10',
10533
'const foo = (1.).toString()'
10634
]
10735
});

test/snapshots/no-zero-fractions.mjs.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,214 @@ Generated by [AVA](https://avajs.dev).
2121
`
2222

2323
## Invalid #2
24+
1 | const foo = 1.0 + 1
25+
26+
> Output
27+
28+
`␊
29+
1 | const foo = 1 + 1␊
30+
`
31+
32+
> Error 1/1
33+
34+
`␊
35+
> 1 | const foo = 1.0 + 1␊
36+
| ^^^ Don't use a zero fraction in the number.␊
37+
`
38+
39+
## Invalid #3
40+
1 | foo(1.0 + 1)
41+
42+
> Output
43+
44+
`␊
45+
1 | foo(1 + 1)␊
46+
`
47+
48+
> Error 1/1
49+
50+
`␊
51+
> 1 | foo(1.0 + 1)␊
52+
| ^^^ Don't use a zero fraction in the number.␊
53+
`
54+
55+
## Invalid #4
56+
1 | const foo = 1.00
57+
58+
> Output
59+
60+
`␊
61+
1 | const foo = 1␊
62+
`
63+
64+
> Error 1/1
65+
66+
`␊
67+
> 1 | const foo = 1.00␊
68+
| ^^^^ Don't use a zero fraction in the number.␊
69+
`
70+
71+
## Invalid #5
72+
1 | const foo = 1.00000
73+
74+
> Output
75+
76+
`␊
77+
1 | const foo = 1␊
78+
`
79+
80+
> Error 1/1
81+
82+
`␊
83+
> 1 | const foo = 1.00000␊
84+
| ^^^^^^^ Don't use a zero fraction in the number.␊
85+
`
86+
87+
## Invalid #6
88+
1 | const foo = -1.0
89+
90+
> Output
91+
92+
`␊
93+
1 | const foo = -1␊
94+
`
95+
96+
> Error 1/1
97+
98+
`␊
99+
> 1 | const foo = -1.0␊
100+
| ^^^ Don't use a zero fraction in the number.␊
101+
`
102+
103+
## Invalid #7
104+
1 | const foo = 123123123.0
105+
106+
> Output
107+
108+
`␊
109+
1 | const foo = 123123123␊
110+
`
111+
112+
> Error 1/1
113+
114+
`␊
115+
> 1 | const foo = 123123123.0␊
116+
| ^^^^^^^^^^^ Don't use a zero fraction in the number.␊
117+
`
118+
119+
## Invalid #8
120+
1 | const foo = 123.11100000000
121+
122+
> Output
123+
124+
`␊
125+
1 | const foo = 123.111␊
126+
`
127+
128+
> Error 1/1
129+
130+
`␊
131+
> 1 | const foo = 123.11100000000␊
132+
| ^^^^^^^^^^^^^^^ Don't use a zero fraction in the number.␊
133+
`
134+
135+
## Invalid #9
136+
1 | const foo = 1.
137+
138+
> Output
139+
140+
`␊
141+
1 | const foo = 1␊
142+
`
143+
144+
> Error 1/1
145+
146+
`␊
147+
> 1 | const foo = 1.␊
148+
| ^^ Don't use a dangling dot in the number.␊
149+
`
150+
151+
## Invalid #10
152+
1 | const foo = +1.
153+
154+
> Output
155+
156+
`␊
157+
1 | const foo = +1␊
158+
`
159+
160+
> Error 1/1
161+
162+
`␊
163+
> 1 | const foo = +1.␊
164+
| ^^ Don't use a dangling dot in the number.␊
165+
`
166+
167+
## Invalid #11
168+
1 | const foo = -1.
169+
170+
> Output
171+
172+
`␊
173+
1 | const foo = -1␊
174+
`
175+
176+
> Error 1/1
177+
178+
`␊
179+
> 1 | const foo = -1.␊
180+
| ^^ Don't use a dangling dot in the number.␊
181+
`
182+
183+
## Invalid #12
184+
1 | const foo = 1.e10
185+
186+
> Output
187+
188+
`␊
189+
1 | const foo = 1e10␊
190+
`
191+
192+
> Error 1/1
193+
194+
`␊
195+
> 1 | const foo = 1.e10␊
196+
| ^^^^^ Don't use a dangling dot in the number.␊
197+
`
198+
199+
## Invalid #13
200+
1 | const foo = +1.e-10
201+
202+
> Output
203+
204+
`␊
205+
1 | const foo = +1e-10␊
206+
`
207+
208+
> Error 1/1
209+
210+
`␊
211+
> 1 | const foo = +1.e-10␊
212+
| ^^^^^^ Don't use a dangling dot in the number.␊
213+
`
214+
215+
## Invalid #14
216+
1 | const foo = -1.e+10
217+
218+
> Output
219+
220+
`␊
221+
1 | const foo = -1e+10␊
222+
`
223+
224+
> Error 1/1
225+
226+
`␊
227+
> 1 | const foo = -1.e+10␊
228+
| ^^^^^^ Don't use a dangling dot in the number.␊
229+
`
230+
231+
## Invalid #15
24232
1 | const foo = (1.).toString()
25233

26234
> Output
552 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)