-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support for PHP 8.1 Explicit Octal Notation in the Tokenizer #3481
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
Merged
gsherwood
merged 8 commits into
squizlabs:master
from
MarkBaker:PHP8.1_Support-for-explicit-octal-notation
Dec 17, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a3eef6
Unit tests for converting an explicit PHP 8.1 octal reference (e.g."0…
8ada8fc
Tokenizer code changes for converting an explicit PHP 8.1 octal refer…
8a6979d
Unit tests to verify that the PHP 7.4 underscore in numeric values st…
8adefd4
Adjust explicit octal tag in NumericSeparator test
9a78378
Rename test files to identify that this is backfill functionality
b11f021
Additional test case for capital O when expressing explicit octal values
a0bc9d6
We should only be testing for T_LNUMBER
b363a7c
Move code block down after the initial comment processing logic.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?php | ||
|
|
||
| /* testExplicitOctal */ | ||
| $foo = 0o137041; | ||
|
|
||
| /* testExplicitOctal capitalised */ | ||
| $bar = 0O137041; |
70 changes: 70 additions & 0 deletions
70
tests/Core/Tokenizer/BackfillExplicitOctalNotationTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
| /** | ||
| * Tests the tokenization of explicit octal notation to PHP < 8.1. | ||
| * | ||
| * @author Mark Baker <[email protected]> | ||
| * @copyright 2019 Squiz Pty Ltd (ABN 77 084 670 600) | ||
| * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
| */ | ||
|
|
||
| namespace PHP_CodeSniffer\Tests\Core\Tokenizer; | ||
|
|
||
| use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; | ||
|
|
||
| class BackfillExplicitOctalNotationTest extends AbstractMethodUnitTest | ||
| { | ||
|
|
||
|
|
||
| /** | ||
| * Test that explicitly-defined octal values are tokenized as a single number and not as a number and a string. | ||
| * | ||
| * @param array $testData The data required for the specific test case. | ||
| * | ||
| * @dataProvider dataExplicitOctalNotation | ||
| * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize | ||
| * | ||
| * @return void | ||
| */ | ||
| public function testExplicitOctalNotation($testData) | ||
| { | ||
| $tokens = self::$phpcsFile->getTokens(); | ||
|
|
||
| $number = $this->getTargetToken($testData['marker'], [T_LNUMBER]); | ||
|
|
||
| $this->assertSame(constant($testData['type']), $tokens[$number]['code']); | ||
| $this->assertSame($testData['type'], $tokens[$number]['type']); | ||
| $this->assertSame($testData['value'], $tokens[$number]['content']); | ||
|
|
||
| }//end testExplicitOctalNotation() | ||
|
|
||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @see testExplicitOctalNotation() | ||
| * | ||
| * @return array | ||
| */ | ||
| public function dataExplicitOctalNotation() | ||
| { | ||
| return [ | ||
| [ | ||
| [ | ||
| 'marker' => '/* testExplicitOctal */', | ||
| 'type' => 'T_LNUMBER', | ||
| 'value' => '0o137041', | ||
| ], | ||
| ], | ||
| [ | ||
| [ | ||
| 'marker' => '/* testExplicitOctal capitalised */', | ||
| 'type' => 'T_LNUMBER', | ||
| 'value' => '0O137041', | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| }//end dataExplicitOctalNotation() | ||
|
|
||
|
|
||
| }//end class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.