From e5e94b034c779b1d4ad72dc09c2b1449bb6b7abc Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 5 Jun 2026 19:56:09 +0800 Subject: [PATCH] =?UTF-8?q?test(aot):=20=E6=B7=BB=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E7=A7=8DAOT=E7=BC=96=E8=AF=91=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加浮点数边界情况测试,包括NAN、INF、-INF的处理 - 添加带接口的枚举功能测试,验证枚举实现接口和使用trait的场景 - 添加try/finally无catch块的异常处理测试 - 添加魔术方法__invoke和__toString的表达式调用测试 - 添加parent::method()父类方法调用测试 - 添加严格类型声明strict_types=1的功能测试 --- .../aot/enum/enum-backed-with-interface.phpt | 52 ++++++++++++++++++ .../aot/exception/finally-without-catch.phpt | 35 ++++++++++++ tests/aot/float_edge/edge-cases.phpt | 40 ++++++++++++++ .../magic_methods/invoke-and-tostring.phpt | 54 +++++++++++++++++++ tests/aot/parent_call/parent-method-call.phpt | 49 +++++++++++++++++ tests/aot/strict_types/strict_types.phpt | 24 +++++++++ 6 files changed, 254 insertions(+) create mode 100644 tests/aot/enum/enum-backed-with-interface.phpt create mode 100644 tests/aot/exception/finally-without-catch.phpt create mode 100644 tests/aot/float_edge/edge-cases.phpt create mode 100644 tests/aot/magic_methods/invoke-and-tostring.phpt create mode 100644 tests/aot/parent_call/parent-method-call.phpt create mode 100644 tests/aot/strict_types/strict_types.phpt diff --git a/tests/aot/enum/enum-backed-with-interface.phpt b/tests/aot/enum/enum-backed-with-interface.phpt new file mode 100644 index 00000000..f080c8a2 --- /dev/null +++ b/tests/aot/enum/enum-backed-with-interface.phpt @@ -0,0 +1,52 @@ +--TEST-- +Backed enum with interface and trait +--FILE-- +value . " - " . $this->label(); + } +} + +enum Status: int implements Labeled { + use Description; + + case Active = 1; + case Inactive = 0; + case Pending = 2; + + public function label(): string { + return match ($this) { + self::Active => 'Active', + self::Inactive => 'Inactive', + self::Pending => 'Pending', + }; + } + + public function isActive(): bool { + return $this === self::Active; + } +} + +function main(): void { + var_dump(Status::Active->value); + var_dump(Status::Active->label()); + var_dump(Status::Active->describe()); + var_dump(Status::Active->isActive()); + var_dump(Status::Inactive->isActive()); + var_dump(Status::from(2)); + var_dump(Status::tryFrom(99)); +} +?> +--EXPECT-- +int(1) +string(6) "Active" +string(18) "Status: 1 - Active" +bool(true) +bool(false) +enum(Status::Pending) +NULL diff --git a/tests/aot/exception/finally-without-catch.phpt b/tests/aot/exception/finally-without-catch.phpt new file mode 100644 index 00000000..937bf08f --- /dev/null +++ b/tests/aot/exception/finally-without-catch.phpt @@ -0,0 +1,35 @@ +--TEST-- +try/finally without catch +--FILE-- += 10) { + throw new Exception("too large"); + } + $result .= " normal"; + } finally { + $result .= " finally"; + } + return $result; +} + +function main(): void { + echo testFinally(5) . "\n"; + echo testFinally(0) . "\n"; + try { + echo testFinally(20) . "\n"; + } catch (Exception $e) { + echo "Caught: " . $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +try-5 normal finally +try-0 early-return +Caught: too large diff --git a/tests/aot/float_edge/edge-cases.phpt b/tests/aot/float_edge/edge-cases.phpt new file mode 100644 index 00000000..1afab394 --- /dev/null +++ b/tests/aot/float_edge/edge-cases.phpt @@ -0,0 +1,40 @@ +--TEST-- +Float edge cases: NAN, INF, -INF +--FILE-- + +--EXPECT-- +float(NAN) +float(INF) +float(-INF) +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(false) +bool(true) +NAN +INF +-INF +float(INF) +float(NAN) +float(NAN) diff --git a/tests/aot/magic_methods/invoke-and-tostring.phpt b/tests/aot/magic_methods/invoke-and-tostring.phpt new file mode 100644 index 00000000..3e163631 --- /dev/null +++ b/tests/aot/magic_methods/invoke-and-tostring.phpt @@ -0,0 +1,54 @@ +--TEST-- +__invoke closure-style call and __toString in expressions +--FILE-- +multiplier = $m; + } + + public function __invoke(int $x): int { + return $x * $this->multiplier; + } + + public function __toString(): string { + return "CallableClass(multiplier={$this->multiplier})"; + } +} + +class Greeter { + public function __invoke(string $name): string { + return "Hello, {$name}!"; + } + + public function __toString(): string { + return "Greeter"; + } +} + +function main(): void { + $double = new CallableClass(2); + $triple = new CallableClass(3); + + echo $double(5) . "\n"; + echo $triple(5) . "\n"; + echo $double . "\n"; + echo $triple . "\n"; + + $greet = new Greeter(); + echo $greet("World") . "\n"; + echo $greet . "\n"; + + echo strlen($double) . "\n"; +} +?> +--EXPECT-- +10 +15 +CallableClass(multiplier=2) +CallableClass(multiplier=3) +Hello, World! +Greeter +27 diff --git a/tests/aot/parent_call/parent-method-call.phpt b/tests/aot/parent_call/parent-method-call.phpt new file mode 100644 index 00000000..99ff0592 --- /dev/null +++ b/tests/aot/parent_call/parent-method-call.phpt @@ -0,0 +1,49 @@ +--TEST-- +parent::method() call +--FILE-- +greet() . "\n"; + echo $child->value() . "\n"; + echo $child->getParentGreet() . "\n"; + echo Child::staticValue() . "\n"; +} +?> +--EXPECT-- +Hello from Base and Child +15 +Hello from Base +150 diff --git a/tests/aot/strict_types/strict_types.phpt b/tests/aot/strict_types/strict_types.phpt new file mode 100644 index 00000000..ade63d3b --- /dev/null +++ b/tests/aot/strict_types/strict_types.phpt @@ -0,0 +1,24 @@ +--TEST-- +strict_types=1 with typed functions +--FILE-- + +--EXPECT-- +int(30) +int(10) +string(12) "Hello, World"