|
10 | 10 |
|
11 | 11 | namespace PHPCSUtils\Tests\Utils\Operators; |
12 | 12 |
|
| 13 | +use PHPCSUtils\BackCompat\Helper; |
13 | 14 | use PHPCSUtils\TestUtils\UtilityMethodTestCase; |
| 15 | +use PHPCSUtils\Utils\Numbers; |
14 | 16 | use PHPCSUtils\Utils\Operators; |
15 | 17 |
|
16 | 18 | /** |
@@ -53,11 +55,30 @@ public function testNotPlusMinusToken() |
53 | 55 | * |
54 | 56 | * @param string $testMarker The comment which prefaces the target token in the test file. |
55 | 57 | * @param bool $expected The expected boolean return value. |
| 58 | + * @param bool $maybeSkip Whether the "should this test be skipped" check should be executed. |
| 59 | + * Defaults to false. |
56 | 60 | * |
57 | 61 | * @return void |
58 | 62 | */ |
59 | | - public function testIsUnaryPlusMinus($testMarker, $expected) |
| 63 | + public function testIsUnaryPlusMinus($testMarker, $expected, $maybeSkip = false) |
60 | 64 | { |
| 65 | + if ($maybeSkip === true) { |
| 66 | + /* |
| 67 | + * Skip the test if this is PHP 7.4 or a PHPCS version which backfills the token sequence |
| 68 | + * to one token as in that case, the plus/minus token won't exist |
| 69 | + */ |
| 70 | + $skipMessage = 'Test irrelevant as the target token won\'t exist'; |
| 71 | + if (\version_compare(\PHP_VERSION_ID, '70399', '>') === true) { |
| 72 | + $this->markTestSkipped($skipMessage); |
| 73 | + } |
| 74 | + |
| 75 | + $phpcsVersion = Helper::getVersion(); |
| 76 | + $minVersionWithBackfill = \min(\array_keys(Numbers::$unsupportedPHPCSVersions)); |
| 77 | + if (\version_compare($phpcsVersion, $minVersionWithBackfill, '>=') === true) { |
| 78 | + $this->markTestSkipped($skipMessage); |
| 79 | + } |
| 80 | + } |
| 81 | + |
61 | 82 | $stackPtr = $this->getTargetToken($testMarker, [\T_PLUS, \T_MINUS]); |
62 | 83 | $result = Operators::isUnaryPlusMinus(self::$phpcsFile, $stackPtr); |
63 | 84 |
|
@@ -258,6 +279,33 @@ public function dataIsUnaryPlusMinus() |
258 | 279 | '/* testSequenceUnaryEnd */', |
259 | 280 | true, |
260 | 281 | ], |
| 282 | + 'php-7.4-underscore-float-containing-plus' => [ |
| 283 | + '/* testPHP74NumericLiteralFloatContainingPlus */', |
| 284 | + false, |
| 285 | + true, // Skip for PHP 7.4 & PHPCS 3.5.3+. |
| 286 | + ], |
| 287 | + 'php-7.4-underscore-float-containing-minus' => [ |
| 288 | + '/* testPHP74NumericLiteralFloatContainingMinus */', |
| 289 | + false, |
| 290 | + true, // Skip for PHP 7.4 & PHPCS 3.5.3+. |
| 291 | + ], |
| 292 | + 'php-7.4-underscore-int-calculation-1' => [ |
| 293 | + '/* testPHP74NumericLiteralIntCalc1 */', |
| 294 | + false, |
| 295 | + ], |
| 296 | + 'php-7.4-underscore-int-calculation-2' => [ |
| 297 | + '/* testPHP74NumericLiteralIntCalc2 */', |
| 298 | + false, |
| 299 | + ], |
| 300 | + 'php-7.4-underscore-float-calculation-1' => [ |
| 301 | + '/* testPHP74NumericLiteralFloatCalc1 */', |
| 302 | + false, |
| 303 | + ], |
| 304 | + 'php-7.4-underscore-float-calculation-2' => [ |
| 305 | + '/* testPHP74NumericLiteralFloatCalc2 */', |
| 306 | + false, |
| 307 | + ], |
| 308 | + |
261 | 309 | 'parse-error' => [ |
262 | 310 | '/* testParseError */', |
263 | 311 | false, |
|
0 commit comments