diff --git a/run-tests.php b/run-tests.php index 8d082700..7592c7a9 100755 --- a/run-tests.php +++ b/run-tests.php @@ -2467,8 +2467,6 @@ COMMAND $cmd $stdin = $test->hasSection('STDIN') ? $test->getSection('STDIN') : null; $out = system_with_timeout($cmd, $env, $stdin, $captureStdIn, $captureStdOut, $captureStdErr); - unlink('./' . $bin_file); - $junit->stopTimer($shortname); $hrtime = hrtime(); $time = $hrtime[0] * 1000000000 + $hrtime[1] - $startTime; @@ -2628,6 +2626,7 @@ COMMAND $cmd $file = substr($test_file, 0, strlen($test_file) - 4); @unlink($file . '.cc'); @unlink($file . '.cc.o'); + @unlink('./' . $bin_file); } @unlink($tmp_post); diff --git a/src/Php/Translator.php b/src/Php/Translator.php index b0b238dd..f75f4581 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -356,6 +356,8 @@ class Translator extends \PhpAot\Core\Translator var_dump($expr); } switch ($type) { + case 'Expr_Isset': + return $this->parseIsset($expr); case 'Expr_Assign': return $this->parseAssign($expr); case 'Expr_Print': @@ -400,6 +402,8 @@ class Translator extends \PhpAot\Core\Translator return $this->parseAssignOpDiv($expr); case 'Expr_AssignOp_Mod': return $this->parseAssignOpMod($expr); + case 'Expr_AssignOp_Concat': + return $this->parseAssignOpConcat($expr); case 'Expr_AssignOp_ShiftRight': return $this->parseAssignOpShiftRight($expr); case 'Expr_BinaryOp_Mul': @@ -708,22 +712,44 @@ class Translator extends \PhpAot\Core\Translator if (count($items) === 0) { return self::TYPE_ARRAY .'{}'; } - $list = []; - $this->indentLevel++; + + // 检查一下数组的赋值方式,是否为索引数组或关联数组,若是混杂模式,需要改为多行插入 + $assocArray = (bool)$items[0]->key; + $mixed = false; foreach ($items as $item) { if ($item->key) { - $list[] = $this->getIndent() . '{ ' . $this->parseIdentifier($item->key) . ', ' . - self::TYPE_VAR . '(' . $this->parseIdentifier($item->value) . ') }'; + if (!$assocArray) { + $mixed = true; + break; + } } else { - $value = $this->parseIdentifier($item->value); - $list[] = $this->getIndent() . self::TYPE_VAR . '(' . $value . ')'; + if ($assocArray) { + $mixed = true; + break; + } } } - $this->indentLevel--; - return self::TYPE_ARRAY . '{' . PHP_EOL . - implode(', ' . PHP_EOL, $list) . PHP_EOL . - $this->getIndent() . - '}'; + + if ($mixed) { + abort($node); + } else { + $list = []; + $this->indentLevel++; + foreach ($items as $item) { + if ($item->key) { + $list[] = $this->getIndent() . '{ ' . $this->parseIdentifier($item->key) . ', ' . + self::TYPE_VAR . '(' . $this->parseIdentifier($item->value) . ') }'; + } else { + $value = $this->parseIdentifier($item->value); + $list[] = $this->getIndent() . self::TYPE_VAR . '(' . $value . ')'; + } + } + $this->indentLevel--; + return self::TYPE_ARRAY . '{' . PHP_EOL . + implode(', ' . PHP_EOL, $list) . PHP_EOL . + $this->getIndent() . + '}'; + } } private function parseType($type) @@ -809,6 +835,13 @@ class Translator extends \PhpAot\Core\Translator return 'php::concat(' . $left . ', ' . $right . ')'; } + private function parseAssignOpConcat(mixed $expr): string + { + $var = $this->parseIdentifier($expr->var); + $value = $this->parseIdentifier($expr->expr); + return $var . '.append(' . $value . ')'; + } + private function parseFor(mixed $v): string { $init = $v->init; @@ -1367,9 +1400,8 @@ class Translator extends \PhpAot\Core\Translator return '"' . $this->escapeString($this->file) . '"'; } - private function parseForeach(Node $node) + private function parseForeach(Node $node): string { - $expr = $this->parseIdentifier($node->expr); if ($node->keyVar) { $keyVar = $this->parseIdentifier($node->keyVar); } @@ -1380,6 +1412,14 @@ class Translator extends \PhpAot\Core\Translator $stmts = $node->stmts; $code = ''; + $this->regressionDetection = true; + $expr = $this->parseIdentifier($node->expr); + $this->regressionDetection = false; + if ($this->beforeStmtLines) { + foreach ($this->beforeStmtLines as $line) { + $code .= $line . PHP_EOL; + } + } $code .= self::TYPE_ARRAY . " $iteratorVar = " . $expr . ';' . PHP_EOL; $code .= 'for (auto iter = ' . $iteratorVar . '.begin(); iter != ' . $iteratorVar . '.end(); ++iter) {' . PHP_EOL; @@ -1528,12 +1568,27 @@ class Translator extends \PhpAot\Core\Translator private function parseScalarFloat(Node $expr): string { - if (is_nan($expr->value)) { + $value = $expr->value; + if (is_nan($value)) { return self::VALUE_NAN; - } elseif (is_infinite($expr->value)) { - return $expr->value > 0 ? self::VALUE_INF : '-' . self::VALUE_INF; + } elseif (is_infinite($value)) { + return $value > 0 ? self::VALUE_INF : '-' . self::VALUE_INF; + } else if (floor($value) == $value && abs($value) < 1e15) { + return number_format($value, 1, '.', ''); } else { - return number_format($expr->value, 1, '.', ''); + return $value; + } + } + + private function parseIsset(mixed $expr) + { + $vars = $expr->vars; + foreach($vars as $var) { + if ($var->getType() === 'Expr_Variable') { + return $this->hasVar($var->name) ? 'true' : 'false'; + } else { + abort($var); + } } } } diff --git a/tests/core/func/001.phpt b/tests/core/func/001.phpt new file mode 100644 index 00000000..a94c1198 --- /dev/null +++ b/tests/core/func/001.phpt @@ -0,0 +1,6 @@ +--TEST-- +Strlen() function test +--FILE-- + +--EXPECT-- +6 diff --git a/tests/core/func/002.phpt b/tests/core/func/002.phpt new file mode 100644 index 00000000..c7c32434 --- /dev/null +++ b/tests/core/func/002.phpt @@ -0,0 +1,24 @@ +--TEST-- +Static variables in functions +--FILE-- + +--EXPECT-- +hey=0, 0 +hey=1, -1 +hey=2, -2 diff --git a/tests/core/func/003.phpt b/tests/core/func/003.phpt new file mode 100644 index 00000000..df76103a --- /dev/null +++ b/tests/core/func/003.phpt @@ -0,0 +1,287 @@ +--TEST-- +General function test +--FILE-- +5) continue; + echo "$k\n"; + } +} + +function main() { + a(); + b("blah"); + a(); + b("blah"); + c(7,14); + + a(); + + for ($k=0; $k<10; $k++) { + for ($i=0; $i<=10; $i++) { + $n=factorial($i); + echo "factorial($i) = $n\n"; + } + } + + + echo "and now, from a function...\n"; + + for ($k=0; $k<10; $k++) { + call_fact(); + } + + echo "------\n"; + $result = factorial(factorial(3)); + echo "$result\n"; + + $result = factorial2(return4(),return7()); + echo "$result\n"; + + andi (3,10); +} +?> +--EXPECT-- +hey +blah +hey +blah +Counting from 7 to 14 +7 +8 +9 +10 +11 +12 +13 +14 +hey +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +and now, from a function... +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +------ +720 +840 +3 +4 +5 diff --git a/tests/core/func/004.phpt b/tests/core/func/004.phpt new file mode 100644 index 00000000..11eb2deb --- /dev/null +++ b/tests/core/func/004.phpt @@ -0,0 +1,62 @@ +--TEST-- +General function test +--FILE-- + +--EXPECT-- +Before function declaration... +After function declaration... +Calling function for the first time... +---- +In function, printing the string "This works!" 10 times +0) This works! +1) This works! +2) This works! +3) This works! +4) This works! +5) This works! +6) This works! +7) This works! +8) This works! +9) This works! +Done with function... +----- +Returned from function call... +Calling the function for the second time... +---- +In function, printing the string "This like, really works and stuff..." 3 times +0) This like, really works and stuff... +1) This like, really works and stuff... +2) This like, really works and stuff... +Done with function... +----- +Returned from function call... +This is some other function, to ensure more than just one function works fine... diff --git a/tests/core/func/005.phpt b/tests/core/func/005.phpt new file mode 100644 index 00000000..9d21817b --- /dev/null +++ b/tests/core/func/005.phpt @@ -0,0 +1,19 @@ +--TEST-- +Testing register_shutdown_function() +--SKIPIF-- + +--FILE-- + +--EXPECT-- +foo() will be called on shutdown... +foo diff --git a/tests/core/func/005a.phpt b/tests/core/func/005a.phpt new file mode 100644 index 00000000..b4a6144d --- /dev/null +++ b/tests/core/func/005a.phpt @@ -0,0 +1,35 @@ +--TEST-- +Testing register_shutdown_function() with timeout. (Bug: #21513) +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +Start + +Fatal error: Maximum execution time of 1 second exceeded in %s on line %d +Shutdown diff --git a/tests/core/func/006.phpt b/tests/core/func/006.phpt new file mode 100644 index 00000000..077b6f87 --- /dev/null +++ b/tests/core/func/006.phpt @@ -0,0 +1,26 @@ +--TEST-- +Output buffering tests +--INI-- +output_buffering=0 +output_handler= +zlib.output_compression=0 +zlib.output_handler= +--FILE-- + +--EXPECT-- +string(2) "2B" +string(2) "1A" diff --git a/tests/core/func/007.phpt b/tests/core/func/007.phpt new file mode 100644 index 00000000..6a18d444 --- /dev/null +++ b/tests/core/func/007.phpt @@ -0,0 +1,22 @@ +--TEST-- +INI functions test +--FILE-- + +--EXPECT-- +ini_set_works +ini_restore_works diff --git a/tests/core/func/008.phpt b/tests/core/func/008.phpt new file mode 100644 index 00000000..48098e13 --- /dev/null +++ b/tests/core/func/008.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test for buffering in core functions with implicit flush off +--INI-- +implicit_flush=0 +--FILE-- + +--EXPECT-- +'foo1' + +'foo2' diff --git a/tests/core/func/009.phpt b/tests/core/func/009.phpt new file mode 100644 index 00000000..05b40e8e --- /dev/null +++ b/tests/core/func/009.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test for buffering in core functions with implicit flush on +--INI-- +implicit_flush=1 +--FILE-- + +--EXPECT-- +'foo1' + +'foo2' diff --git a/tests/core/func/010.phpt b/tests/core/func/010.phpt new file mode 100644 index 00000000..bc8cb8a4 --- /dev/null +++ b/tests/core/func/010.phpt @@ -0,0 +1,78 @@ +--TEST-- +function with many parameters +--SKIPIF-- + + +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +Done diff --git a/tests/core/func/011.phpt b/tests/core/func/011.phpt new file mode 100644 index 00000000..368ed0b1 --- /dev/null +++ b/tests/core/func/011.phpt @@ -0,0 +1,9 @@ +--TEST-- +Test bitwise AND, OR, XOR, NOT and logical NOT in INI via error_reporting +--INI-- +error_reporting = E_ALL & E_NOTICE | E_PARSE ^ E_DEPRECATED & ~E_WARNING | !E_ERROR +--FILE-- + 0); +?> +--EXPECT-- diff --git a/tests/core/func/bug64523.phpt b/tests/core/func/bug64523.phpt new file mode 100644 index 00000000..173a0e6a --- /dev/null +++ b/tests/core/func/bug64523.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #64523: XOR not parsed in INI +--SKIPIF-- + +--INI-- +error_reporting = E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED +--FILE-- + +--EXPECT-- +22517 diff --git a/tests/core/func/ini_alter.phpt b/tests/core/func/ini_alter.phpt new file mode 100644 index 00000000..258e4d2d --- /dev/null +++ b/tests/core/func/ini_alter.phpt @@ -0,0 +1,18 @@ +--TEST-- +ini_alter() check +--CREDITS-- +Sebastian Schürmann +sebs@php.net +Testfest 2009 Munich +--FILE-- + +--EXPECT-- +string(1) "1" +string(1) "0" diff --git a/tests/core/strings/001.phpt b/tests/core/strings/001.phpt new file mode 100644 index 00000000..e1260001 --- /dev/null +++ b/tests/core/strings/001.phpt @@ -0,0 +1,223 @@ +--TEST-- +String functions +--FILE-- +?' + . '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_' + . '`abcdefghijklmnopqrstuvwxyz{|}~' + . ""; + +echo "Testing rawurlencode: "; +$encoded = rawurlencode($raw); +$correct = '%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F' + . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_' + . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~' + . ''; +if ($encoded == $correct) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing rawurldecode: "; +$decoded = rawurldecode($correct); +if ($decoded == $raw) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing urlencode: "; +$encoded = urlencode($raw); +$correct = '+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F' + . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_' + . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E' + . ''; +if ($encoded == $correct) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing urldecode: "; +$decoded = urldecode($correct); +if ($decoded == $raw) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing quotemeta: "; +$raw = "a.\\+*?" . chr(91) . "^" . chr(93) . "b\$c"; +$quoted = quotemeta($raw); +if ($quoted == "a\\.\\\\\\+\\*\\?\\[\\^\\]b\\\$c") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing ufirst: "; +$str = "fahrvergnuegen"; +$uc = ucfirst($str); +if ($uc == "Fahrvergnuegen") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing strtr: "; +$str = "test abcdefgh"; +$tr = strtr($str, "def", "456"); +if ($tr == "t5st abc456gh") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing addslashes: "; +$str = "\"\\'"; +$as = addslashes($str); +if ($as == "\\\"\\\\\\'") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing stripslashes: "; +$str = "\$\\'"; +$ss = stripslashes($str); +if ($ss == "\$'") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + + +echo "Testing uniqid(true): "; +$str = "prefix"; +$ui1 = uniqid($str, true); +$ui2 = uniqid($str, true); + +$len = 29; + +if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing uniqid(false): "; +$str = "prefix"; +$ui1 = uniqid($str); +usleep( 1 ); +$ui2 = uniqid($str); + +$len = strncasecmp(PHP_OS, 'CYGWIN', 6) ? 19 : 29; + +if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +?> +--EXPECT-- +Testing strtok: passed +Testing strstr: passed +Testing strrchr: passed +Testing strtoupper: passed +Testing strtolower: passed +Testing substr: passed +Testing rawurlencode: passed +Testing rawurldecode: passed +Testing urlencode: passed +Testing urldecode: passed +Testing quotemeta: passed +Testing ufirst: passed +Testing strtr: passed +Testing addslashes: passed +Testing stripslashes: passed +Testing uniqid(true): passed +Testing uniqid(false): passed diff --git a/tests/core/strings/002.phpt b/tests/core/strings/002.phpt new file mode 100644 index 00000000..ee970100 --- /dev/null +++ b/tests/core/strings/002.phpt @@ -0,0 +1,89 @@ +--TEST-- +Formatted print functions +--FILE-- +\n", "foo"); +printf("printf test 9:<%-20s>\n", "bar"); +printf("printf test 10: 123456789012345\n"); +printf("printf test 10:<%15s>\n", "hoyesterettsjustitiarius"); +printf("printf test 11: 123456789012345678901234567890\n"); +printf("printf test 11:<%30s>\n", "hoyesterettsjustitiarius"); +printf("printf test 12:%5.2f\n", -12.34); +printf("printf test 13:%5d\n", -12); +printf("printf test 14:%c\n", 64); +printf("printf test 15:%b\n", 170); +printf("printf test 16:%x\n", 170); +printf("printf test 17:%X\n", 170); +printf("printf test 18:%16b\n", 170); +printf("printf test 19:%16x\n", 170); +printf("printf test 20:%16X\n", 170); +printf("printf test 21:%016b\n", 170); +printf("printf test 22:%016x\n", 170); +printf("printf test 23:%016X\n", 170); +printf("printf test 24:%.5s\n", "abcdefghij"); +printf("printf test 25:%-2s\n", "gazonk"); +printf("printf test 26:%2\$d %1\$d\n", 1, 2); +printf("printf test 27:%3\$d %d %d\n", 1, 2, 3); +printf("printf test 28:%2\$02d %1\$2d\n", 1, 2); +printf("printf test 29:%2\$-2d %1\$2d\n", 1, 2); +//try { +// print("printf test 30:"); printf("%0\$s", 1); print("x\n"); +//} catch(\ValueError $e) { +// print('Error found: '.$e->getMessage()."\n"); +//} +printf("printf test 31:%.17g\n", INF); +printf("printf test 32:%.17g\n", -INF); +vprintf("vprintf test 1:%2\$-2d %1\$2d\n", array(1, 2)); + + +?> +--EXPECT-- +fprintf test 1:abcde +int(20) +printf test 1:simple string +printf test 2:42 +printf test 3:3.333333 +printf test 4:3.3333333333 +printf test 5:2.50 +printf test 6:2.50000000 +printf test 7:0000002.50 +printf test 8:< foo> +printf test 9: +printf test 10: 123456789012345 +printf test 10: +printf test 11: 123456789012345678901234567890 +printf test 11:< hoyesterettsjustitiarius> +printf test 12:-12.34 +printf test 13: -12 +printf test 14:@ +printf test 15:10101010 +printf test 16:aa +printf test 17:AA +printf test 18: 10101010 +printf test 19: aa +printf test 20: AA +printf test 21:0000000010101010 +printf test 22:00000000000000aa +printf test 23:00000000000000AA +printf test 24:abcde +printf test 25:gazonk +printf test 26:2 1 +printf test 27:3 1 2 +printf test 28:02 1 +printf test 29:2 1 +printf test 31:INF +printf test 32:-INF +vprintf test 1:2 1 diff --git a/tests/core/strings/004.phpt b/tests/core/strings/004.phpt new file mode 100644 index 00000000..45827883 --- /dev/null +++ b/tests/core/strings/004.phpt @@ -0,0 +1,17 @@ +--TEST-- +highlight_string() buffering +--INI-- +highlight.string=#DD0000 +highlight.comment=#FF9900 +highlight.keyword=#007700 +highlight.default=#0000BB +highlight.html=#000000 +--FILE-- +
"); +$var = highlight_string("

", TRUE); +echo "\n[$var]\n"; +?> +--EXPECT-- +
<br /><?php echo "foo"; ?><br />
+[
<br /><?php echo "bar"; ?><br />
] diff --git a/tests/core/strings/offsets_chaining_1.phpt b/tests/core/strings/offsets_chaining_1.phpt new file mode 100644 index 00000000..18b6fa2f --- /dev/null +++ b/tests/core/strings/offsets_chaining_1.phpt @@ -0,0 +1,9 @@ +--TEST-- +testing the behavior of string offset chaining +--FILE-- + +--EXPECT-- +string(1) "f" diff --git a/tests/zend/add_001.phpt b/tests/zend/add_001.phpt new file mode 100644 index 00000000..be3cbe43 --- /dev/null +++ b/tests/zend/add_001.phpt @@ -0,0 +1,80 @@ +--TEST-- +adding arrays +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + ["a"]=> + string(3) "aaa" + [0]=> + int(2) + [1]=> + int(3) +} +array(3) { + ["a"]=> + string(3) "aaa" + [0]=> + int(2) + [1]=> + int(3) +} +array(3) { + ["a"]=> + string(3) "aaa" + [0]=> + int(2) + [1]=> + int(3) +} +Done diff --git a/tests/zend/array_unpack/basic.phpt b/tests/zend/array_unpack/basic.phpt new file mode 100644 index 00000000..7ef62a82 --- /dev/null +++ b/tests/zend/array_unpack/basic.phpt @@ -0,0 +1,122 @@ +--TEST-- +Basic array unpacking +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(0) { +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(11) + [1]=> + int(12) + [2]=> + int(13) + [3]=> + int(14) +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(15) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + [11]=> + int(11) + [12]=> + int(12) + [13]=> + int(13) + [14]=> + int(14) +} +array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) + [7]=> + string(3) "end" +} diff --git a/tests/zend/concat/concat_002.phpt b/tests/zend/concat/concat_002.phpt new file mode 100644 index 00000000..c9f74951 --- /dev/null +++ b/tests/zend/concat/concat_002.phpt @@ -0,0 +1,23 @@ +--TEST-- +Stress test $x .= $x +--FILE-- + +--EXPECT-- +int(33554432) +Done diff --git a/tests/zend/concat/concat_003.phpt b/tests/zend/concat/concat_003.phpt new file mode 100644 index 00000000..ed4026af --- /dev/null +++ b/tests/zend/concat/concat_003.phpt @@ -0,0 +1,40 @@ +--TEST-- +Concatenating many small strings should not slowdown allocations +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) ++++DONE+++ diff --git a/tests/zend/foreach/foreach_002.phpt b/tests/zend/foreach/foreach_002.phpt new file mode 100644 index 00000000..325a3ffa --- /dev/null +++ b/tests/zend/foreach/foreach_002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Creating recursive array on foreach using same variable +--INI-- +zend.enable_gc=1 +--SKIPIF-- + +--FILE-- + array('a' => &$a))) as $a) { + var_dump($a); +} + +?> +--EXPECT-- +array(1) { + ["a"]=> + *RECURSION* +} diff --git a/tests/zend/foreach/foreach_003.phpt b/tests/zend/foreach/foreach_003.phpt new file mode 100644 index 00000000..d30802f2 --- /dev/null +++ b/tests/zend/foreach/foreach_003.phpt @@ -0,0 +1,73 @@ +--TEST-- +Iterator exceptions in foreach by value +--SKIPIF-- + +--FILE-- +count = $count; + $this->trap = $trap; + } + + function trap($trap) { + if ($trap === $this->trap) { + throw new Exception($trap); + } + } + + function rewind(): void {$this->trap(__FUNCTION__); $this->n = 0;} + function valid(): bool {$this->trap(__FUNCTION__); return $this->n < $this->count;} + function key(): mixed {$this->trap(__FUNCTION__); return $this->n;} + function current(): mixed {$this->trap(__FUNCTION__); return $this->n;} + function next(): void {$this->trap(__FUNCTION__); $this->n++;} +} + +foreach(['rewind', 'valid', 'key', 'current', 'next'] as $trap) { + $obj = new IT(3, $trap); + try { + // IS_CV + foreach ($obj as $key => $val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + unset($obj); + + try { + // IS_VAR + foreach (new IT(3, $trap) as $key => $val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + + try { + // IS_TMP_VAR + foreach ((object)new IT(2, $trap) as $key => $val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +rewind +rewind +rewind +valid +valid +valid +key +key +key +current +current +current +0 +next +0 +next +0 +next diff --git a/tests/zend/foreach/foreach_005.phpt b/tests/zend/foreach/foreach_005.phpt new file mode 100644 index 00000000..097d74d4 --- /dev/null +++ b/tests/zend/foreach/foreach_005.phpt @@ -0,0 +1,22 @@ +--TEST-- +Nested foreach by reference on the same array +--FILE-- + +--EXPECT-- +1-1 +2-2 +2-3 +3-2 +3-3 +4-4 +5-3 +5-4 +5-5 diff --git a/tests/zend/foreach/foreach_006.phpt b/tests/zend/foreach/foreach_006.phpt new file mode 100644 index 00000000..8e81a686 --- /dev/null +++ b/tests/zend/foreach/foreach_006.phpt @@ -0,0 +1,20 @@ +--TEST-- +Foreach by reference on constant +--FILE-- + +--EXPECT-- +1 +2 +3 +1 +2 +3 +1 +2 +3 diff --git a/tests/zend/foreach/foreach_007.phpt b/tests/zend/foreach/foreach_007.phpt new file mode 100644 index 00000000..09cf6024 --- /dev/null +++ b/tests/zend/foreach/foreach_007.phpt @@ -0,0 +1,13 @@ +--TEST-- +Foreach by reference and inserting new element when we are already at the end +--FILE-- + +--EXPECT-- +1 +2