@@ -18,21 +18,23 @@ final class BackfillNumericSeparatorTest extends AbstractMethodUnitTest
18
18
/**
19
19
* Test that numbers using numeric separators are tokenized correctly.
20
20
*
21
- * @param array $testData The data required for the specific test case.
21
+ * @param string $marker The comment which prefaces the target token in the test file.
22
+ * @param string $type The expected token type.
23
+ * @param string $value The expected token content.
22
24
*
23
25
* @dataProvider dataTestBackfill
24
26
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
25
27
*
26
28
* @return void
27
29
*/
28
- public function testBackfill ($ testData )
30
+ public function testBackfill ($ marker , $ type , $ value )
29
31
{
30
32
$ tokens = self ::$ phpcsFile ->getTokens ();
31
- $ number = $ this ->getTargetToken ($ testData [ ' marker ' ] , [T_LNUMBER , T_DNUMBER ]);
33
+ $ number = $ this ->getTargetToken ($ marker , [T_LNUMBER , T_DNUMBER ]);
32
34
33
- $ this ->assertSame (constant ($ testData [ ' type ' ] ), $ tokens [$ number ]['code ' ]);
34
- $ this ->assertSame ($ testData [ ' type ' ] , $ tokens [$ number ]['type ' ]);
35
- $ this ->assertSame ($ testData [ ' value ' ] , $ tokens [$ number ]['content ' ]);
35
+ $ this ->assertSame (constant ($ type ), $ tokens [$ number ]['code ' ]);
36
+ $ this ->assertSame ($ type , $ tokens [$ number ]['type ' ]);
37
+ $ this ->assertSame ($ value , $ tokens [$ number ]['content ' ]);
36
38
37
39
}//end testBackfill()
38
40
@@ -42,7 +44,7 @@ public function testBackfill($testData)
42
44
*
43
45
* @see testBackfill()
44
46
*
45
- * @return array
47
+ * @return array<string, array<string, string>>
46
48
*/
47
49
public static function dataTestBackfill ()
48
50
{
@@ -62,96 +64,70 @@ public static function dataTestBackfill()
62
64
}
63
65
64
66
return [
65
- [
66
- [
67
- 'marker ' => '/* testSimpleLNumber */ ' ,
68
- 'type ' => 'T_LNUMBER ' ,
69
- 'value ' => '1_000_000_000 ' ,
70
- ],
67
+ 'decimal integer ' => [
68
+ 'marker ' => '/* testSimpleLNumber */ ' ,
69
+ 'type ' => 'T_LNUMBER ' ,
70
+ 'value ' => '1_000_000_000 ' ,
71
71
],
72
- [
73
- [
74
- 'marker ' => '/* testSimpleDNumber */ ' ,
75
- 'type ' => 'T_DNUMBER ' ,
76
- 'value ' => '107_925_284.88 ' ,
77
- ],
72
+ 'float ' => [
73
+ 'marker ' => '/* testSimpleDNumber */ ' ,
74
+ 'type ' => 'T_DNUMBER ' ,
75
+ 'value ' => '107_925_284.88 ' ,
78
76
],
79
- [
80
- [
81
- 'marker ' => '/* testFloat */ ' ,
82
- 'type ' => 'T_DNUMBER ' ,
83
- 'value ' => '6.674_083e-11 ' ,
84
- ],
77
+ 'float, scientific notation, negative exponent with sigh ' => [
78
+ 'marker ' => '/* testFloat */ ' ,
79
+ 'type ' => 'T_DNUMBER ' ,
80
+ 'value ' => '6.674_083e-11 ' ,
85
81
],
86
- [
87
- [
88
- 'marker ' => '/* testFloat2 */ ' ,
89
- 'type ' => 'T_DNUMBER ' ,
90
- 'value ' => '6.674_083e+11 ' ,
91
- ],
82
+ 'float, scientific notation, positive exponent with sign ' => [
83
+ 'marker ' => '/* testFloat2 */ ' ,
84
+ 'type ' => 'T_DNUMBER ' ,
85
+ 'value ' => '6.674_083e+11 ' ,
92
86
],
93
- [
94
- [
95
- 'marker ' => '/* testFloat3 */ ' ,
96
- 'type ' => 'T_DNUMBER ' ,
97
- 'value ' => '1_2.3_4e1_23 ' ,
98
- ],
87
+ 'float, scientific notation, positive exponent without sign ' => [
88
+ 'marker ' => '/* testFloat3 */ ' ,
89
+ 'type ' => 'T_DNUMBER ' ,
90
+ 'value ' => '1_2.3_4e1_23 ' ,
99
91
],
100
- [
101
- [
102
- 'marker ' => '/* testHex */ ' ,
103
- 'type ' => $ testHexType ,
104
- 'value ' => '0xCAFE_F00D ' ,
105
- ],
92
+ 'hexidecimal integer/float ' => [
93
+ 'marker ' => '/* testHex */ ' ,
94
+ 'type ' => $ testHexType ,
95
+ 'value ' => '0xCAFE_F00D ' ,
106
96
],
107
- [
108
- [
109
- 'marker ' => '/* testHexMultiple */ ' ,
110
- 'type ' => $ testHexMultipleType ,
111
- 'value ' => '0x42_72_6F_77_6E ' ,
112
- ],
97
+ 'hexidecimal integer/float with multiple underscores ' => [
98
+ 'marker ' => '/* testHexMultiple */ ' ,
99
+ 'type ' => $ testHexMultipleType ,
100
+ 'value ' => '0x42_72_6F_77_6E ' ,
113
101
],
114
- [
115
- [
116
- 'marker ' => '/* testHexInt */ ' ,
117
- 'type ' => 'T_LNUMBER ' ,
118
- 'value ' => '0x42_72_6F ' ,
119
- ],
102
+ 'hexidecimal integer ' => [
103
+ 'marker ' => '/* testHexInt */ ' ,
104
+ 'type ' => 'T_LNUMBER ' ,
105
+ 'value ' => '0x42_72_6F ' ,
120
106
],
121
- [
122
- [
123
- 'marker ' => '/* testBinary */ ' ,
124
- 'type ' => 'T_LNUMBER ' ,
125
- 'value ' => '0b0101_1111 ' ,
126
- ],
107
+ 'binary integer ' => [
108
+ 'marker ' => '/* testBinary */ ' ,
109
+ 'type ' => 'T_LNUMBER ' ,
110
+ 'value ' => '0b0101_1111 ' ,
127
111
],
128
- [
129
- [
130
- 'marker ' => '/* testOctal */ ' ,
131
- 'type ' => 'T_LNUMBER ' ,
132
- 'value ' => '0137_041 ' ,
133
- ],
112
+ 'octal integer ' => [
113
+ 'marker ' => '/* testOctal */ ' ,
114
+ 'type ' => 'T_LNUMBER ' ,
115
+ 'value ' => '0137_041 ' ,
134
116
],
135
- [
136
- [
137
- 'marker ' => '/* testExplicitOctal */ ' ,
138
- 'type ' => 'T_LNUMBER ' ,
139
- 'value ' => '0o137_041 ' ,
140
- ],
117
+ 'octal integer using explicit octal notation ' => [
118
+ 'marker ' => '/* testExplicitOctal */ ' ,
119
+ 'type ' => 'T_LNUMBER ' ,
120
+ 'value ' => '0o137_041 ' ,
141
121
],
142
- [
143
- [
144
- 'marker ' => '/* testExplicitOctalCapitalised */ ' ,
145
- 'type ' => 'T_LNUMBER ' ,
146
- 'value ' => '0O137_041 ' ,
147
- ],
122
+ 'octal integer using explicit octal notation with capital O ' => [
123
+ 'marker ' => '/* testExplicitOctalCapitalised */ ' ,
124
+ 'type ' => 'T_LNUMBER ' ,
125
+ 'value ' => '0O137_041 ' ,
148
126
],
149
- [
150
- [
151
- 'marker ' => '/* testIntMoreThanMax */ ' ,
152
- 'type ' => $ testIntMoreThanMaxType ,
153
- 'value ' => '10_223_372_036_854_775_807 ' ,
154
- ],
127
+ 'integer more than PHP_INT_MAX becomes a float ' => [
128
+ 'marker ' => '/* testIntMoreThanMax */ ' ,
129
+ 'type ' => $ testIntMoreThanMaxType ,
130
+ 'value ' => '10_223_372_036_854_775_807 ' ,
155
131
],
156
132
];
157
133
@@ -162,8 +138,8 @@ public static function dataTestBackfill()
162
138
* Test that numbers using numeric separators which are considered parse errors and/or
163
139
* which aren't relevant to the backfill, do not incorrectly trigger the backfill anyway.
164
140
*
165
- * @param string $testMarker The comment which prefaces the target token in the test file.
166
- * @param array $expectedTokens The token type and content of the expected token sequence.
141
+ * @param string $testMarker The comment which prefaces the target token in the test file.
142
+ * @param array<array<string, int|string>> $expectedTokens The token type and content of the expected token sequence.
167
143
*
168
144
* @dataProvider dataNoBackfill
169
145
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
@@ -189,14 +165,14 @@ public function testNoBackfill($testMarker, $expectedTokens)
189
165
*
190
166
* @see testBackfill()
191
167
*
192
- * @return array
168
+ * @return array<string, array<string, string|array<array<string, int|string>>>>
193
169
*/
194
170
public static function dataNoBackfill ()
195
171
{
196
172
return [
197
- [
198
- '/* testInvalid1 */ ' ,
199
- [
173
+ ' invalid: trailing underscore ' => [
174
+ 'testMarker ' => ' /* testInvalid1 */ ' ,
175
+ ' expectedTokens ' => [
200
176
[
201
177
'code ' => T_LNUMBER ,
202
178
'content ' => '100 ' ,
@@ -207,9 +183,9 @@ public static function dataNoBackfill()
207
183
],
208
184
],
209
185
],
210
- [
211
- '/* testInvalid2 */ ' ,
212
- [
186
+ ' invalid: two consecutive underscores ' => [
187
+ 'testMarker ' => ' /* testInvalid2 */ ' ,
188
+ ' expectedTokens ' => [
213
189
[
214
190
'code ' => T_LNUMBER ,
215
191
'content ' => '1 ' ,
@@ -220,9 +196,9 @@ public static function dataNoBackfill()
220
196
],
221
197
],
222
198
],
223
- [
224
- '/* testInvalid3 */ ' ,
225
- [
199
+ ' invalid: underscore directly before decimal point ' => [
200
+ 'testMarker ' => ' /* testInvalid3 */ ' ,
201
+ ' expectedTokens ' => [
226
202
[
227
203
'code ' => T_LNUMBER ,
228
204
'content ' => '1 ' ,
@@ -237,9 +213,9 @@ public static function dataNoBackfill()
237
213
],
238
214
],
239
215
],
240
- [
241
- '/* testInvalid4 */ ' ,
242
- [
216
+ ' invalid: underscore directly after decimal point ' => [
217
+ 'testMarker ' => ' /* testInvalid4 */ ' ,
218
+ ' expectedTokens ' => [
243
219
[
244
220
'code ' => T_DNUMBER ,
245
221
'content ' => '1. ' ,
@@ -250,9 +226,9 @@ public static function dataNoBackfill()
250
226
],
251
227
],
252
228
],
253
- [
254
- '/* testInvalid5 */ ' ,
255
- [
229
+ ' invalid: hex int - underscore directly after x ' => [
230
+ 'testMarker ' => ' /* testInvalid5 */ ' ,
231
+ ' expectedTokens ' => [
256
232
[
257
233
'code ' => T_LNUMBER ,
258
234
'content ' => '0 ' ,
@@ -263,9 +239,9 @@ public static function dataNoBackfill()
263
239
],
264
240
],
265
241
],
266
- [
267
- '/* testInvalid6 */ ' ,
268
- [
242
+ ' invalid: binary int - underscore directly after b ' => [
243
+ 'testMarker ' => ' /* testInvalid6 */ ' ,
244
+ ' expectedTokens ' => [
269
245
[
270
246
'code ' => T_LNUMBER ,
271
247
'content ' => '0 ' ,
@@ -276,9 +252,9 @@ public static function dataNoBackfill()
276
252
],
277
253
],
278
254
],
279
- [
280
- '/* testInvalid7 */ ' ,
281
- [
255
+ ' invalid: scientific float - underscore directly before e ' => [
256
+ 'testMarker ' => ' /* testInvalid7 */ ' ,
257
+ ' expectedTokens ' => [
282
258
[
283
259
'code ' => T_LNUMBER ,
284
260
'content ' => '1 ' ,
@@ -289,9 +265,9 @@ public static function dataNoBackfill()
289
265
],
290
266
],
291
267
],
292
- [
293
- '/* testInvalid8 */ ' ,
294
- [
268
+ ' invalid: scientific float - underscore directly after e ' => [
269
+ 'testMarker ' => ' /* testInvalid8 */ ' ,
270
+ ' expectedTokens ' => [
295
271
[
296
272
'code ' => T_LNUMBER ,
297
273
'content ' => '1 ' ,
@@ -302,9 +278,9 @@ public static function dataNoBackfill()
302
278
],
303
279
],
304
280
],
305
- [
306
- '/* testInvalid9 */ ' ,
307
- [
281
+ ' invalid: space between parts of the number ' => [
282
+ 'testMarker ' => ' /* testInvalid9 */ ' ,
283
+ ' expectedTokens ' => [
308
284
[
309
285
'code ' => T_LNUMBER ,
310
286
'content ' => '107_925_284 ' ,
@@ -319,9 +295,9 @@ public static function dataNoBackfill()
319
295
],
320
296
],
321
297
],
322
- [
323
- '/* testInvalid10 */ ' ,
324
- [
298
+ ' invalid: comment within the number ' => [
299
+ 'testMarker ' => ' /* testInvalid10 */ ' ,
300
+ ' expectedTokens ' => [
325
301
[
326
302
'code ' => T_LNUMBER ,
327
303
'content ' => '107_925_284 ' ,
@@ -336,9 +312,9 @@ public static function dataNoBackfill()
336
312
],
337
313
],
338
314
],
339
- [
340
- '/* testInvalid11 */ ' ,
341
- [
315
+ ' invalid: explicit octal int - underscore directly after o ' => [
316
+ 'testMarker ' => ' /* testInvalid11 */ ' ,
317
+ ' expectedTokens ' => [
342
318
[
343
319
'code ' => T_LNUMBER ,
344
320
'content ' => '0 ' ,
@@ -349,9 +325,9 @@ public static function dataNoBackfill()
349
325
],
350
326
],
351
327
],
352
- [
353
- '/* testInvalid12 */ ' ,
354
- [
328
+ ' invalid: explicit octal int - underscore directly after capital O ' => [
329
+ 'testMarker ' => ' /* testInvalid12 */ ' ,
330
+ ' expectedTokens ' => [
355
331
[
356
332
'code ' => T_LNUMBER ,
357
333
'content ' => '0 ' ,
@@ -362,9 +338,9 @@ public static function dataNoBackfill()
362
338
],
363
339
],
364
340
],
365
- [
366
- '/* testCalc1 */ ' ,
367
- [
341
+ ' calculations should be untouched - int - int ' => [
342
+ 'testMarker ' => ' /* testCalc1 */ ' ,
343
+ ' expectedTokens ' => [
368
344
[
369
345
'code ' => T_LNUMBER ,
370
346
'content ' => '667_083 ' ,
@@ -387,9 +363,9 @@ public static function dataNoBackfill()
387
363
],
388
364
],
389
365
],
390
- [
391
- '/* test Calc2 */ ' ,
392
- [
366
+ ' calculations should be untouched - scientific float + int ' => [
367
+ 'testMarker ' => ' /* test Calc2 */ ' ,
368
+ ' expectedTokens ' => [
393
369
[
394
370
'code ' => T_DNUMBER ,
395
371
'content ' => '6.674_08e3 ' ,
0 commit comments