Skip to content

Commit 01238eb

Browse files
authored
Merge pull request #63 from PHPCSStandards/feature/operators-isunaryplusminus-add-tests-php74-numeric-literals
Operators::isUnaryPlusMinus(): add tests with PHP 7.4 numeric literals using underscores
2 parents d5ae800 + 184febe commit 01238eb

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

Tests/Utils/Operators/IsUnaryPlusMinusTest.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ $a =
146146
/* testSequenceUnaryEnd */
147147
+ /*comment*/ 10;
148148

149+
/* testPHP74NumericLiteralFloatContainingPlus */
150+
$a = 6.674_083e+11;
151+
152+
/* testPHP74NumericLiteralFloatContainingMinus */
153+
$a = 6.674_083e-1_1;
154+
155+
/* testPHP74NumericLiteralIntCalc1 */
156+
$a = 667_083 - 11;
157+
158+
/* testPHP74NumericLiteralIntCalc2 */
159+
$a = 74_083 + 1_1;
160+
161+
/* testPHP74NumericLiteralFloatCalc1 */
162+
$a = 6.674_08e3 - 1_1;
163+
164+
/* testPHP74NumericLiteralFloatCalc2 */
165+
$a = 6.674_08e3 + 11;
166+
149167
// Intentional parse error. This has to be the last test in the file.
150168
/* testParseError */
151169
$a = -

Tests/Utils/Operators/IsUnaryPlusMinusTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
namespace PHPCSUtils\Tests\Utils\Operators;
1212

13+
use PHPCSUtils\BackCompat\Helper;
1314
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
15+
use PHPCSUtils\Utils\Numbers;
1416
use PHPCSUtils\Utils\Operators;
1517

1618
/**
@@ -53,11 +55,30 @@ public function testNotPlusMinusToken()
5355
*
5456
* @param string $testMarker The comment which prefaces the target token in the test file.
5557
* @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.
5660
*
5761
* @return void
5862
*/
59-
public function testIsUnaryPlusMinus($testMarker, $expected)
63+
public function testIsUnaryPlusMinus($testMarker, $expected, $maybeSkip = false)
6064
{
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+
6182
$stackPtr = $this->getTargetToken($testMarker, [\T_PLUS, \T_MINUS]);
6283
$result = Operators::isUnaryPlusMinus(self::$phpcsFile, $stackPtr);
6384

@@ -258,6 +279,33 @@ public function dataIsUnaryPlusMinus()
258279
'/* testSequenceUnaryEnd */',
259280
true,
260281
],
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+
261309
'parse-error' => [
262310
'/* testParseError */',
263311
false,

0 commit comments

Comments
 (0)