-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 7.4 numeric separators are now tokenized in the same way when usi…
…ng older PHP versions (ref #2546)
- Loading branch information
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,22 @@ | ||
<?php | ||
|
||
/* testSimpleLNumber */ | ||
$foo = 1_000_000_000; | ||
|
||
/* testSimpleDNumber */ | ||
$foo = 107_925_284.88; | ||
|
||
/* testFloat */ | ||
$foo = 6.674_083e-11; | ||
|
||
/* testHex */ | ||
$foo = 0xCAFE_F00D; | ||
|
||
/* testHexMultiple */ | ||
$foo = 0x42_72_6F_77_6E; | ||
|
||
/* testBinary */ | ||
$foo = 0b0101_1111; | ||
|
||
/* testOctal */ | ||
$foo = 0137_041; |
This file contains 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,101 @@ | ||
<?php | ||
/** | ||
* Tests the backfilling of numeric seperators to PHP < 7.4. | ||
* | ||
* @author Greg Sherwood <gsherwood@squiz.net> | ||
* @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 BackfillNumericSeparatorTest extends AbstractMethodUnitTest | ||
{ | ||
|
||
|
||
/** | ||
* Test that numbers using numeric seperators are tokenized correctly. | ||
* | ||
* @param array $testData The data required for the specific test case. | ||
* | ||
* @dataProvider dataTestBackfill | ||
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize | ||
* | ||
* @return void | ||
*/ | ||
public function testBackfill($testData) | ||
{ | ||
$tokens = self::$phpcsFile->getTokens(); | ||
$number = $this->getTargetToken($testData['marker'], $testData['type']); | ||
$this->assertSame($tokens[$number]['content'], $testData['value']); | ||
|
||
}//end testBackfill() | ||
|
||
|
||
/** | ||
* Data provider. | ||
* | ||
* @see testBackfill() | ||
* | ||
* @return array | ||
*/ | ||
public function dataTestBackfill() | ||
{ | ||
return [ | ||
[ | ||
[ | ||
'marker' => '/* testSimpleLNumber */', | ||
'type' => T_LNUMBER, | ||
'value' => '1_000_000_000', | ||
], | ||
], | ||
[ | ||
[ | ||
'marker' => '/* testSimpleDNumber */', | ||
'type' => T_DNUMBER, | ||
'value' => '107_925_284.88', | ||
], | ||
], | ||
[ | ||
[ | ||
'marker' => '/* testFloat */', | ||
'type' => T_DNUMBER, | ||
'value' => '6.674_083e-11', | ||
], | ||
], | ||
[ | ||
[ | ||
'marker' => '/* testHex */', | ||
'type' => T_LNUMBER, | ||
'value' => '0xCAFE_F00D', | ||
], | ||
], | ||
[ | ||
[ | ||
'marker' => '/* testHexMultiple */', | ||
'type' => T_LNUMBER, | ||
'value' => '0x42_72_6F_77_6E', | ||
], | ||
], | ||
[ | ||
[ | ||
'marker' => '/* testBinary */', | ||
'type' => T_LNUMBER, | ||
'value' => '0b0101_1111', | ||
], | ||
], | ||
[ | ||
[ | ||
'marker' => '/* testOctal */', | ||
'type' => T_LNUMBER, | ||
'value' => '0137_041', | ||
], | ||
], | ||
]; | ||
|
||
}//end dataTestBackfill() | ||
|
||
|
||
}//end class |