tests: add calc tests
authorMichael Wallner <mike@php.net>
Wed, 8 Feb 2017 12:40:15 +0000 (13:40 +0100)
committerMichael Wallner <mike@php.net>
Wed, 8 Feb 2017 12:40:15 +0000 (13:40 +0100)
tests/calc/calc.psi [new file with mode: 0644]
tests/calc/calc001.phpt [new file with mode: 0644]

diff --git a/tests/calc/calc.psi b/tests/calc/calc.psi
new file mode 100644 (file)
index 0000000..915807a
--- /dev/null
@@ -0,0 +1,62 @@
+function test\calc1() : array {
+       let numerator = 3 * 5 + 2;
+       let denominator = 17;
+       return to_array(div,
+               to_int(quot),
+               to_int(rem)
+       );
+}
+
+function test\calc2() : array {
+       let numerator = 4 + 5 * 2;
+       let denominator = 14;
+       return to_array(div,
+               to_int(quot),
+               to_int(rem)
+       );
+}
+
+function test\calc3() : array {
+       let numerator = -1 + 2 - 3 * 2;
+       let denominator = -5;
+       return to_array(div,
+               to_int(quot),
+               to_int(rem)
+       );
+}
+
+function test\calc4() : array {
+       let numerator = 1 * 5 / 5 * -1 / -1 * 10 / 5 + 4 * 2;
+       let denominator = 10;
+       return to_array(div,
+               to_int(quot),
+               to_int(rem)
+       );
+}
+
+function test\calc5() : array {
+       let numerator = 5 % 3;
+       let denominator = 2;
+       return to_array(div,
+               to_int(quot),
+               to_int(rem)
+       );
+}
+
+function test\calc6() : array {
+       let numerator = 5 % 3 + 1;
+       let denominator = 3;
+       return to_array(div,
+               to_int(quot),
+               to_int(rem)
+       );
+}
+
+function test\calc7() : array {
+       let numerator = 5 % (3 + 1);
+       let denominator = 1;
+       return to_array(div,
+               to_int(quot),
+               to_int(rem)
+       );
+}
\ No newline at end of file
diff --git a/tests/calc/calc001.phpt b/tests/calc/calc001.phpt
new file mode 100644 (file)
index 0000000..2b6cbb6
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+calc
+--INI--
+psi.directory={PWD}/../../psi.d:{PWD}
+--SKIPIF--
+<?php
+extension_loaded("psi") or die("skip need ext/psi");
+?>
+--FILE--
+===TEST===
+<?php
+for ($i = 0; $i < 10; ++$i) {
+       $func = "test\\calc$i";
+       if (function_exists($func)) {
+               $res = $func();
+               if ($res === ["quot"=>1, "rem"=>0]) {
+                       echo "yay-";
+               } else {
+                       var_dump($res);
+               }
+       }
+}
+?>
+
+===DONE===
+--EXPECTREGEX--
+===TEST===
+(yay-)+
+===DONE===