Skip to content

Commit f80915e

Browse files
committed
Tokenizer / numeric separators backfill: improve the unit tests
Test case file: 1. Remove a stray invisible whitespace character/null byte from the test case file. 2. Add a large number of additional test cases. Test file `testBackfill()`: 1. Fixed reversed order of the parameters in the `assertSame()`. The first parameter is `$expected`, the second `$result`. Having the parameters in the correct order makes debugging the tests easier as the messages send by PHPUnit will be correct. 2. Test that the final token has the correct code **and** the correct type. 3. Correct the expected type for two test cases based on how PHP 7.4 tokenizes these. 4. Add datasets for the new test cases which are to be handled by the backfill. Test file new `testNoBackfil()` Add test that numbers using numeric separators which are considered parse errors and/or which aren't relevant to the backfill, do not incorrectly trigger the backfill anyway. This test verifies that the final token sequence is in line with the token sequence PHP 7.4 would give. ADD TO: unit tests
1 parent 90b719d commit f80915e

File tree

2 files changed

+340
-11
lines changed

2 files changed

+340
-11
lines changed
Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,82 @@
11
<?php
22

3+
/*
4+
* Numbers with PHP 7.4 underscore separators.
5+
*/
6+
37
/* testSimpleLNumber */
48
$foo = 1_000_000_000;
59

610
/* testSimpleDNumber */
7-
$foo = 107_925_284.88;
11+
$foo = 107_925_284.88;
812

913
/* testFloat */
1014
$foo = 6.674_083e-11;
1115

1216
/* testFloat2 */
1317
$foo = 6.674_083e+11;
1418

19+
/* testFloat3 */
20+
$foo = 1_2.3_4e1_23;
21+
1522
/* testHex */
1623
$foo = 0xCAFE_F00D;
1724

1825
/* testHexMultiple */
1926
$foo = 0x42_72_6F_77_6E;
2027

28+
/* testHexInt */
29+
$foo = 0x42_72_6F;
30+
2131
/* testBinary */
2232
$foo = 0b0101_1111;
2333

2434
/* testOctal */
2535
$foo = 0137_041;
36+
37+
/* testIntMoreThanMax */
38+
$foo = 10_223_372_036_854_775_807;
39+
40+
/*
41+
* Invalid use of numeric separators. These should not be touched by the backfill.
42+
*/
43+
44+
/* testInvalid1 */
45+
$a = 100_; // trailing
46+
47+
/* testInvalid2 */
48+
$a = 1__1; // next to underscore
49+
50+
/* testInvalid3 */
51+
$a = 1_.0; // next to decimal point
52+
53+
/* testInvalid4 */
54+
$a = 1._0; // next to decimal point
55+
56+
/* testInvalid5 */
57+
$a = 0x_123; // next to x
58+
59+
/* testInvalid6 */
60+
$a = 0b_101; // next to b
61+
62+
/* testInvalid7 */
63+
$a = 1_e2; // next to e
64+
65+
/* testInvalid8 */
66+
$a = 1e_2; // next to e
67+
68+
/* testInvalid9 */
69+
$testValue = 107_925_284 .88;
70+
71+
/* testInvalid10 */
72+
$testValue = 107_925_284/*comment*/.88;
73+
74+
/*
75+
* Ensure that legitimate calculations are not touched by the backfill.
76+
*/
77+
78+
/* testCalc1 */
79+
$a = 667_083 - 11; // Calculation.
80+
81+
/* test Calc2 */
82+
$a = 6.674_08e3 + 11; // Calculation.

0 commit comments

Comments
 (0)