Skip to content

Commit 04e962f

Browse files
committed
Tests for bitwise operators
1 parent 9d1a3b1 commit 04e962f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/operators/bitwise.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Tests bitwise operators
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$code =<<<ZEP
9+
function bitwise() {
10+
let a = 0x01 << 1;
11+
let a = 0xF0 >> 1;
12+
let a = 0x01 | 0x02;
13+
let a = 0x03 & 0x01;
14+
let a = 0x03 ^ 0x02;
15+
let a = ~ 0x01;
16+
}
17+
ZEP;
18+
19+
$ir = zephir_parse_file($code, '(eval code)');
20+
21+
echo count($ir[0]["statements"]) . "\n";
22+
23+
foreach ($ir[0]["statements"] as $statement) {
24+
$expr = $statement["assignments"][0]["expr"];
25+
$parts = [
26+
$expr["left"]["type"],
27+
$expr["left"]["value"],
28+
$expr["type"]
29+
];
30+
31+
if (isset($expr["right"])) {
32+
$parts[] = $expr["right"]["type"];
33+
$parts[] = $expr["right"]["value"];
34+
}
35+
36+
echo implode(" ", $parts) . "\n";
37+
}
38+
?>
39+
--EXPECT--
40+
6
41+
int 0x01 bitwise_shiftleft int 1
42+
int 0xF0 bitwise_shiftright int 1
43+
int 0x01 bitwise_or int 0x02
44+
int 0x03 bitwise_and int 0x01
45+
int 0x03 bitwise_xor int 0x02
46+
int 0x01 bitwise_not

0 commit comments

Comments
 (0)