From 184090ec84700298bf7fa0e057c6498274427eba Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 22 May 2026 20:58:42 +0800 Subject: [PATCH] =?UTF-8?q?test(aot):=20=E6=B7=BB=E5=8A=A0AOT=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加对象克隆功能测试,验证clone关键字的正确性 - 添加复合赋值运算符测试,覆盖数组、对象属性等场景 - 添加exit/die语言结构测试,验证程序退出行为 - 添加嵌套闭包功能测试,验证闭包作用域和链式调用 --- tests/aot/clone.phpt | 35 +++++++++++++++++++ tests/aot/compound-assign.phpt | 62 ++++++++++++++++++++++++++++++++++ tests/aot/exit-test.phpt | 35 +++++++++++++++++++ tests/aot/nested-closures.phpt | 56 ++++++++++++++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 tests/aot/clone.phpt create mode 100644 tests/aot/compound-assign.phpt create mode 100644 tests/aot/exit-test.phpt create mode 100644 tests/aot/nested-closures.phpt diff --git a/tests/aot/clone.phpt b/tests/aot/clone.phpt new file mode 100644 index 00000000..cbfef4c7 --- /dev/null +++ b/tests/aot/clone.phpt @@ -0,0 +1,35 @@ +--TEST-- +Clone keyword for object cloning +--FILE-- +value = $v; + } + + public function increment(): void { + $this->value++; + } +} + +function main() { + $original = new Counter(10); + $original->increment(); + + $cloned = clone $original; + $cloned->increment(); + $cloned->increment(); + + var_dump($original->value); + var_dump($cloned->value); + var_dump($original->value !== $cloned->value); +} + +?> +--EXPECT-- +int(11) +int(13) +bool(true) diff --git a/tests/aot/compound-assign.phpt b/tests/aot/compound-assign.phpt new file mode 100644 index 00000000..a500e8f8 --- /dev/null +++ b/tests/aot/compound-assign.phpt @@ -0,0 +1,62 @@ +--TEST-- +Compound assignment in expressions +--FILE-- +val += 5; + $obj->val *= 2; + $obj->val -= 3; + $obj->val %= 4; + var_dump($obj->val); + + // Chained assignments + $a = $b = $c = 10; + var_dump($a); + var_dump($b); + var_dump($c); + + // Reference assignment + $y = 2; + $z = &$y; + $y = 5; + var_dump($z); + + // Global variable with assignment + global $config; + $config = ["debug" => true]; + var_dump($config["debug"]); + + echo "done\n"; +} + +?> +--EXPECT-- +array(3) { + [0]=> + int(11) + [1]=> + int(6) + [2]=> + int(2) +} +int(3) +int(10) +int(10) +int(10) +int(5) +bool(true) +done diff --git a/tests/aot/exit-test.phpt b/tests/aot/exit-test.phpt new file mode 100644 index 00000000..7da48a43 --- /dev/null +++ b/tests/aot/exit-test.phpt @@ -0,0 +1,35 @@ +--TEST-- +exit/die language constructs +--FILE-- + 0) { + echo "should not reach here\n"; + } + echo "code is zero\n"; +} + +function processValue(mixed $val): string { + if (!is_string($val)) { + die("not a string"); + } + return "string: " . $val; +} + +function main() { + testExit(0); + + $result = processValue("hello"); + var_dump($result); + + $status = 42; + $x = $status == 0 ? 'zero' : 'non-zero'; + var_dump($x); +} + +?> +--EXPECT-- +code is zero +string(13) "string: hello" +string(8) "non-zero" diff --git a/tests/aot/nested-closures.phpt b/tests/aot/nested-closures.phpt new file mode 100644 index 00000000..beef46d1 --- /dev/null +++ b/tests/aot/nested-closures.phpt @@ -0,0 +1,56 @@ +--TEST-- +Nested closures and closure scope +--FILE-- + +--EXPECT-- +int(20) +int(15) +int(11) +string(11) "User: Alice" +int(6)