Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] Tokenizer / numeric separators backfill: fix all known issues #2771

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Dec 17, 2019

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 testNoBackfill()

Add tests to verify 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.

Tokenizer / numeric separators backfill: fix incorrect token types

Tokenizer / numeric separators backfill: fix incorrect token types

When the final content of a numeric token is more than PHP_INT_MAX or when a numeric token contains a . or an E/e, it should be tokenized as T_DNUMBER.

This fixes the first set of the unit test failures.

Tokenizer / numeric separators backfill: fix parse errors being handled by the backfill

The prevents the backfill from kicking in when confronted with invalid use of the numeric literal separator which would be a parse error in PHP 7.4 anyway.

This fixes the remaining unit test failures.

Fixes all currently known issues which remained after #2546


Note: on Windows the unit tests will currently not pass when run against PHP 7.4.0 due to a bug in PHP itself. See: https://bugs.php.net/bug.php?id=78978

@jrfnl jrfnl force-pushed the feature/fix-php-7.4-numeric-separators-backfill branch 7 times, most recently from bc6a0f2 to fa1f283 Compare December 19, 2019 01:29
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
When the final content of a numeric token is more than PHP_INT_MAX or when a numeric token contains a `.` or an `E/e`, it should be tokenized as `T_DNUMBER`.

This fixes the first set of the unit test failures.
@jrfnl jrfnl force-pushed the feature/fix-php-7.4-numeric-separators-backfill branch from fa1f283 to adadcd5 Compare December 19, 2019 01:38
…ed by the backfill

The prevents the backfill from kicking in when confronted with invalid use of the numeric literal separator which would be a parse error in PHP 7.4 anyway.

This fixes the remaining unit test failures.
@jrfnl jrfnl force-pushed the feature/fix-php-7.4-numeric-separators-backfill branch from adadcd5 to bb9216e Compare December 20, 2019 01:44
@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 23, 2019

@gsherwood Could this PR please be milestoned for 3.5.4 ? This issue is a blocker for PHPCSUtils.

@gsherwood gsherwood added this to the 3.5.4 milestone Dec 27, 2019
gsherwood added a commit that referenced this pull request Jan 6, 2020
@gsherwood gsherwood merged commit bb9216e into squizlabs:master Jan 6, 2020
@gsherwood
Copy link
Member

Thanks for doing all this work to make it more accurate.

@jrfnl
Copy link
Contributor Author

jrfnl commented Jan 6, 2020

@gsherwood Thanks for the merge! This one was a bit of a thorn in my side ;-)

@jrfnl jrfnl deleted the feature/fix-php-7.4-numeric-separators-backfill branch January 6, 2020 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants