@@ -18,21 +18,23 @@ final class BackfillNumericSeparatorTest extends AbstractMethodUnitTest
1818 /**
1919 * Test that numbers using numeric separators are tokenized correctly.
2020 *
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.
2224 *
2325 * @dataProvider dataTestBackfill
2426 * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
2527 *
2628 * @return void
2729 */
28- public function testBackfill ($ testData )
30+ public function testBackfill ($ marker , $ type , $ value )
2931 {
3032 $ tokens = self ::$ phpcsFile ->getTokens ();
31- $ number = $ this ->getTargetToken ($ testData [ ' marker ' ] , [T_LNUMBER , T_DNUMBER ]);
33+ $ number = $ this ->getTargetToken ($ marker , [T_LNUMBER , T_DNUMBER ]);
3234
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 ' ]);
3638
3739 }//end testBackfill()
3840
@@ -42,7 +44,7 @@ public function testBackfill($testData)
4244 *
4345 * @see testBackfill()
4446 *
45- * @return array
47+ * @return array<string, array<string, string>>
4648 */
4749 public static function dataTestBackfill ()
4850 {
@@ -62,96 +64,70 @@ public static function dataTestBackfill()
6264 }
6365
6466 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 ' ,
7171 ],
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 ' ,
7876 ],
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 ' ,
8581 ],
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 ' ,
9286 ],
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 ' ,
9991 ],
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 ' ,
10696 ],
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 ' ,
113101 ],
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 ' ,
120106 ],
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 ' ,
127111 ],
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 ' ,
134116 ],
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 ' ,
141121 ],
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 ' ,
148126 ],
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 ' ,
155131 ],
156132 ];
157133
@@ -162,8 +138,8 @@ public static function dataTestBackfill()
162138 * Test that numbers using numeric separators which are considered parse errors and/or
163139 * which aren't relevant to the backfill, do not incorrectly trigger the backfill anyway.
164140 *
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.
167143 *
168144 * @dataProvider dataNoBackfill
169145 * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
@@ -189,14 +165,14 @@ public function testNoBackfill($testMarker, $expectedTokens)
189165 *
190166 * @see testBackfill()
191167 *
192- * @return array
168+ * @return array<string, array<string, string|array<array<string, int|string>>>>
193169 */
194170 public static function dataNoBackfill ()
195171 {
196172 return [
197- [
198- '/* testInvalid1 */ ' ,
199- [
173+ ' invalid: trailing underscore ' => [
174+ 'testMarker ' => ' /* testInvalid1 */ ' ,
175+ ' expectedTokens ' => [
200176 [
201177 'code ' => T_LNUMBER ,
202178 'content ' => '100 ' ,
@@ -207,9 +183,9 @@ public static function dataNoBackfill()
207183 ],
208184 ],
209185 ],
210- [
211- '/* testInvalid2 */ ' ,
212- [
186+ ' invalid: two consecutive underscores ' => [
187+ 'testMarker ' => ' /* testInvalid2 */ ' ,
188+ ' expectedTokens ' => [
213189 [
214190 'code ' => T_LNUMBER ,
215191 'content ' => '1 ' ,
@@ -220,9 +196,9 @@ public static function dataNoBackfill()
220196 ],
221197 ],
222198 ],
223- [
224- '/* testInvalid3 */ ' ,
225- [
199+ ' invalid: underscore directly before decimal point ' => [
200+ 'testMarker ' => ' /* testInvalid3 */ ' ,
201+ ' expectedTokens ' => [
226202 [
227203 'code ' => T_LNUMBER ,
228204 'content ' => '1 ' ,
@@ -237,9 +213,9 @@ public static function dataNoBackfill()
237213 ],
238214 ],
239215 ],
240- [
241- '/* testInvalid4 */ ' ,
242- [
216+ ' invalid: underscore directly after decimal point ' => [
217+ 'testMarker ' => ' /* testInvalid4 */ ' ,
218+ ' expectedTokens ' => [
243219 [
244220 'code ' => T_DNUMBER ,
245221 'content ' => '1. ' ,
@@ -250,9 +226,9 @@ public static function dataNoBackfill()
250226 ],
251227 ],
252228 ],
253- [
254- '/* testInvalid5 */ ' ,
255- [
229+ ' invalid: hex int - underscore directly after x ' => [
230+ 'testMarker ' => ' /* testInvalid5 */ ' ,
231+ ' expectedTokens ' => [
256232 [
257233 'code ' => T_LNUMBER ,
258234 'content ' => '0 ' ,
@@ -263,9 +239,9 @@ public static function dataNoBackfill()
263239 ],
264240 ],
265241 ],
266- [
267- '/* testInvalid6 */ ' ,
268- [
242+ ' invalid: binary int - underscore directly after b ' => [
243+ 'testMarker ' => ' /* testInvalid6 */ ' ,
244+ ' expectedTokens ' => [
269245 [
270246 'code ' => T_LNUMBER ,
271247 'content ' => '0 ' ,
@@ -276,9 +252,9 @@ public static function dataNoBackfill()
276252 ],
277253 ],
278254 ],
279- [
280- '/* testInvalid7 */ ' ,
281- [
255+ ' invalid: scientific float - underscore directly before e ' => [
256+ 'testMarker ' => ' /* testInvalid7 */ ' ,
257+ ' expectedTokens ' => [
282258 [
283259 'code ' => T_LNUMBER ,
284260 'content ' => '1 ' ,
@@ -289,9 +265,9 @@ public static function dataNoBackfill()
289265 ],
290266 ],
291267 ],
292- [
293- '/* testInvalid8 */ ' ,
294- [
268+ ' invalid: scientific float - underscore directly after e ' => [
269+ 'testMarker ' => ' /* testInvalid8 */ ' ,
270+ ' expectedTokens ' => [
295271 [
296272 'code ' => T_LNUMBER ,
297273 'content ' => '1 ' ,
@@ -302,9 +278,9 @@ public static function dataNoBackfill()
302278 ],
303279 ],
304280 ],
305- [
306- '/* testInvalid9 */ ' ,
307- [
281+ ' invalid: space between parts of the number ' => [
282+ 'testMarker ' => ' /* testInvalid9 */ ' ,
283+ ' expectedTokens ' => [
308284 [
309285 'code ' => T_LNUMBER ,
310286 'content ' => '107_925_284 ' ,
@@ -319,9 +295,9 @@ public static function dataNoBackfill()
319295 ],
320296 ],
321297 ],
322- [
323- '/* testInvalid10 */ ' ,
324- [
298+ ' invalid: comment within the number ' => [
299+ 'testMarker ' => ' /* testInvalid10 */ ' ,
300+ ' expectedTokens ' => [
325301 [
326302 'code ' => T_LNUMBER ,
327303 'content ' => '107_925_284 ' ,
@@ -336,9 +312,9 @@ public static function dataNoBackfill()
336312 ],
337313 ],
338314 ],
339- [
340- '/* testInvalid11 */ ' ,
341- [
315+ ' invalid: explicit octal int - underscore directly after o ' => [
316+ 'testMarker ' => ' /* testInvalid11 */ ' ,
317+ ' expectedTokens ' => [
342318 [
343319 'code ' => T_LNUMBER ,
344320 'content ' => '0 ' ,
@@ -349,9 +325,9 @@ public static function dataNoBackfill()
349325 ],
350326 ],
351327 ],
352- [
353- '/* testInvalid12 */ ' ,
354- [
328+ ' invalid: explicit octal int - underscore directly after capital O ' => [
329+ 'testMarker ' => ' /* testInvalid12 */ ' ,
330+ ' expectedTokens ' => [
355331 [
356332 'code ' => T_LNUMBER ,
357333 'content ' => '0 ' ,
@@ -362,9 +338,9 @@ public static function dataNoBackfill()
362338 ],
363339 ],
364340 ],
365- [
366- '/* testCalc1 */ ' ,
367- [
341+ ' calculations should be untouched - int - int ' => [
342+ 'testMarker ' => ' /* testCalc1 */ ' ,
343+ ' expectedTokens ' => [
368344 [
369345 'code ' => T_LNUMBER ,
370346 'content ' => '667_083 ' ,
@@ -387,9 +363,9 @@ public static function dataNoBackfill()
387363 ],
388364 ],
389365 ],
390- [
391- '/* test Calc2 */ ' ,
392- [
366+ ' calculations should be untouched - scientific float + int ' => [
367+ 'testMarker ' => ' /* test Calc2 */ ' ,
368+ ' expectedTokens ' => [
393369 [
394370 'code ' => T_DNUMBER ,
395371 'content ' => '6.674_08e3 ' ,
0 commit comments