Skip to content

Commit

Permalink
Tokenizer / numeric separators backfill: improve the unit tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrfnl committed Dec 19, 2019
1 parent 90b719d commit f80915e
Show file tree
Hide file tree
Showing 2 changed files with 340 additions and 11 deletions.
59 changes: 58 additions & 1 deletion tests/Core/Tokenizer/BackfillNumericSeparatorTest.inc
Original file line number Diff line number Diff line change
@@ -1,25 +1,82 @@
<?php

/*
* Numbers with PHP 7.4 underscore separators.
*/

/* testSimpleLNumber */
$foo = 1_000_000_000;

/* testSimpleDNumber */
$foo = 107_925_284.88;
$foo = 107_925_284.88;

/* testFloat */
$foo = 6.674_083e-11;

/* testFloat2 */
$foo = 6.674_083e+11;

/* testFloat3 */
$foo = 1_2.3_4e1_23;

/* testHex */
$foo = 0xCAFE_F00D;

/* testHexMultiple */
$foo = 0x42_72_6F_77_6E;

/* testHexInt */
$foo = 0x42_72_6F;

/* testBinary */
$foo = 0b0101_1111;

/* testOctal */
$foo = 0137_041;

/* testIntMoreThanMax */
$foo = 10_223_372_036_854_775_807;

/*
* Invalid use of numeric separators. These should not be touched by the backfill.
*/

/* testInvalid1 */
$a = 100_; // trailing

/* testInvalid2 */
$a = 1__1; // next to underscore

/* testInvalid3 */
$a = 1_.0; // next to decimal point

/* testInvalid4 */
$a = 1._0; // next to decimal point

/* testInvalid5 */
$a = 0x_123; // next to x

/* testInvalid6 */
$a = 0b_101; // next to b

/* testInvalid7 */
$a = 1_e2; // next to e

/* testInvalid8 */
$a = 1e_2; // next to e

/* testInvalid9 */
$testValue = 107_925_284 .88;

/* testInvalid10 */
$testValue = 107_925_284/*comment*/.88;

/*
* Ensure that legitimate calculations are not touched by the backfill.
*/

/* testCalc1 */
$a = 667_083 - 11; // Calculation.

/* test Calc2 */
$a = 6.674_08e3 + 11; // Calculation.
Loading

0 comments on commit f80915e

Please sign in to comment.