-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
600 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* testNonUnaryPlus */ | ||
result = 1 + 2; | ||
|
||
/* testNonUnaryMinus */ | ||
result = 1-2; | ||
|
||
/* testUnaryMinusColon */ | ||
$.localScroll({offset: {top: -32}}); | ||
|
||
switch (result) { | ||
/* testUnaryMinusCase */ | ||
case -1: | ||
break; | ||
} | ||
|
||
/* testUnaryMinusTernaryThen */ | ||
result = x?-y:z; | ||
|
||
/* testUnaryPlusTernaryElse */ | ||
result = x ? y : +z; | ||
|
||
/* testUnaryMinusIfCondition */ | ||
if (true || -1 == b) {} |
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,74 @@ | ||
<?php | ||
/** | ||
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers. | ||
* | ||
* @package PHPCSUtils | ||
* @copyright 2019 PHPCSUtils Contributors | ||
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3 | ||
* @link https://github.com/PHPCSStandards/PHPCSUtils | ||
*/ | ||
|
||
namespace PHPCSUtils\Tests\Utils\Operators; | ||
|
||
use PHPCSUtils\Tests\Utils\Operators\IsUnaryPlusMinusTest; | ||
|
||
/** | ||
* Tests for the \PHPCSUtils\Utils\Operators::isUnaryPlusMinus() method. | ||
* | ||
* @covers \PHPCSUtils\Utils\Operators::isUnaryPlusMinus | ||
* | ||
* @group operators | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
class IsUnaryPlusMinusJSTest extends IsUnaryPlusMinusTest | ||
{ | ||
|
||
/** | ||
* The file extension of the test case file (without leading dot). | ||
* | ||
* @var string | ||
*/ | ||
protected static $fileExtension = 'js'; | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @see IsUnaryPlusMinusTest::testIsUnaryPlusMinus() For the array format. | ||
* | ||
* @return array | ||
*/ | ||
public function dataIsUnaryPlusMinus() | ||
{ | ||
return [ | ||
'non-unary-plus' => [ | ||
'/* testNonUnaryPlus */', | ||
false, | ||
], | ||
'non-unary-minus' => [ | ||
'/* testNonUnaryMinus */', | ||
false, | ||
], | ||
'unary-minus-colon' => [ | ||
'/* testUnaryMinusColon */', | ||
true, | ||
], | ||
'unary-minus-switch-case' => [ | ||
'/* testUnaryMinusCase */', | ||
true, | ||
], | ||
'unary-minus-ternary-then' => [ | ||
'/* testUnaryMinusTernaryThen */', | ||
true, | ||
], | ||
'unary-minus-ternary-else' => [ | ||
'/* testUnaryPlusTernaryElse */', | ||
true, | ||
], | ||
'unary-minus-if-condition' => [ | ||
'/* testUnaryMinusIfCondition */', | ||
true, | ||
], | ||
]; | ||
} | ||
} |
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,151 @@ | ||
<?php | ||
|
||
/* testNonUnaryPlus */ | ||
$a = 1 + 2; | ||
|
||
/* testNonUnaryMinus */ | ||
$a = 1-2; | ||
|
||
/* testNonUnaryPlusArrays */ | ||
$a = [1] + [2]; | ||
|
||
/* testUnaryMinusArithmetic */ | ||
$a = 1 / -2; | ||
|
||
/* testUnaryPlusArithmetic */ | ||
$a = 1 ** +2; | ||
|
||
/* testUnaryMinusConcatenation */ | ||
$a = 'ID' . -$var; | ||
|
||
/* testUnaryPlusIntAssignment */ | ||
$a = +1; | ||
|
||
/* testUnaryMinusVariableAssignment */ | ||
$a += -$b; | ||
|
||
/* testUnaryPlusFloatAssignment */ | ||
$a **= + 1.1; | ||
|
||
/* testUnaryMinusBoolAssignment */ | ||
$a /= -true; | ||
|
||
/* testUnaryPlusStringAssignmentWithComment */ | ||
$a &= + /* comment */ '1'; | ||
|
||
/* testUnaryMinusStringAssignment */ | ||
$a .= - <<<'EOD' | ||
123 | ||
EOD; | ||
|
||
/* testUnaryPlusNullAssignment */ | ||
$a = +null; | ||
|
||
/* testUnaryMinusVariableVariableAssignment */ | ||
$a .= -${$var}; | ||
|
||
/* testUnaryPlusIntComparison */ | ||
$a = ($b === + 1); | ||
|
||
/* testUnaryPlusIntComparisonYoda */ | ||
$a = (+1 <=> $b); | ||
|
||
/* testUnaryMinusFloatComparison */ | ||
$a = ($b !== - 1.1); | ||
|
||
/* testUnaryMinusStringComparisonYoda */ | ||
$a = (-'1' != $b); | ||
|
||
/* testUnaryPlusVariableBoolean */ | ||
$a = ($a && - $b); | ||
|
||
/* testUnaryMinusVariableBoolean */ | ||
$a = ($a || -$b); | ||
|
||
/* testUnaryPlusLogicalXor */ | ||
$a = ($a xor -$b); | ||
|
||
/* testUnaryMinusTernaryThen */ | ||
$a = $a ? -1 : | ||
/* testUnaryPlusTernaryElse */ | ||
+ 10; | ||
|
||
/* testUnaryMinusCoalesce */ | ||
$a = $a ?? -1 : | ||
|
||
/* testUnaryPlusIntReturn */ | ||
return +1; | ||
|
||
/* testUnaryMinusFloatReturn */ | ||
return -1.1; | ||
|
||
/* testUnaryPlusPrint */ | ||
print +$b; | ||
|
||
/* testUnaryMinusEcho */ | ||
echo -$a; | ||
|
||
/* testUnaryPlusYield */ | ||
yield +$a; | ||
|
||
/* testUnaryPlusArrayAccess */ | ||
$a = $array[ + 2 ]; | ||
|
||
/* testUnaryMinusStringArrayAccess */ | ||
if ($line{-1} === ':') {} | ||
|
||
$array = array( | ||
/* testUnaryPlusLongArrayAssignment */ | ||
+1, | ||
/* testUnaryMinusLongArrayAssignmentKey */ | ||
-1 => | ||
/* testUnaryPlusLongArrayAssignmentValue */ | ||
+20, | ||
); | ||
|
||
$array = [ | ||
/* testUnaryPlusShortArrayAssignment */ | ||
+1 => | ||
/* testNonUnaryMinusShortArrayAssignment */ | ||
5-20, | ||
]; | ||
|
||
/* testUnaryMinusCast */ | ||
$a = (bool) -2; | ||
|
||
functionCall( | ||
/* testUnaryPlusFunctionCallParam */ | ||
+2, | ||
/* testUnaryMinusFunctionCallParam */ | ||
- 123.456, | ||
); | ||
|
||
/* testUnaryPlusDeclare */ | ||
declare( ticks = +10 ); | ||
|
||
switch ($a) { | ||
/* testUnaryPlusCase */ | ||
case +20: | ||
// Something. | ||
break; | ||
|
||
/* testUnaryMinusCase */ | ||
case -1.23: | ||
// Something. | ||
break; | ||
} | ||
|
||
// Testing `$a = -+-+10`; | ||
$a = | ||
/* testSequenceNonUnary1 */ | ||
- | ||
/* testSequenceNonUnary2 */ | ||
+ | ||
/* testSequenceNonUnary3 */ | ||
- | ||
/* testSequenceUnaryEnd */ | ||
+ /*comment*/ 10; | ||
|
||
// Intentional parse error. This has to be the last test in the file. | ||
/* testParseError */ | ||
$a = - |
Oops, something went wrong.