Skip to content

Commit

Permalink
Add tests for various other operators
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 24, 2024
1 parent 13ac792 commit 36eb6f1
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/test/php/lang/ast/unittest/emit/OperatorTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class OperatorTest extends EmittingTest {

#[Test, Values([['+=', 3], ['-=', -1], ['*=', 2], ['/=', 0.5]])]
#[Test, Values([['+=', 3], ['-=', -1], ['*=', 2], ['/=', 0.5], ['**=', 1]])]
public function assignment_and_math($op, $expected) {
$r= $this->run('class %T {
public function run() {
Expand All @@ -17,7 +17,7 @@ public function run() {
Assert::equals($expected, $r);
}

#[Test, Values([['|=', 0x0003], ['&=', 0x0002], ['^=', 0x0001]])]
#[Test, Values([['|=', 0x0003], ['&=', 0x0002], ['^=', 0x0001], ['>>=', 0x0000], ['<<=', 0x000C]])]
public function assignment_and_bitwise($op, $expected) {
$r= $this->run('class %T {
public function run() {
Expand All @@ -30,6 +30,46 @@ public function run() {
Assert::equals($expected, $r);
}

#[Test]
public function concatenation() {
$r= $this->run('class %T {
public function run() {
$a= "A..";
$a.= "B";
return $a;
}
}');

Assert::equals('A..B', $r);
}

#[Test, Values([['$a++', 2, 1], ['++$a', 2, 2], ['$a--', 0, 1], ['--$a', 0, 0]])]
public function inc_dec($op, $a, $b) {
$r= $this->run('class %T {
public function run() {
$a= 1;
$b= '.$op.';
return [$a, $b];
}
}');

Assert::equals([$a, $b], $r);
}

#[Test]
public function references() {
$r= $this->run('class %T {
public function run() {
$a= 3;
$ptr= &$a;
$a++;
return $ptr;
}
}');

Assert::equals(4, $r);
}

#[Test]
public function destructuring() {
$r= $this->run('class %T {
Expand Down

0 comments on commit 36eb6f1

Please sign in to comment.