From 8a423d225ef0d3e59b23045799e93ee056fcd4db Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 23 May 2026 14:13:59 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=E6=8A=BD=E8=B1=A1?= =?UTF-8?q?=E7=B1=BB=E3=80=81=E6=8E=A5=E5=8F=A3=E3=80=81final=E7=B1=BB?= =?UTF-8?q?=E3=80=81=E5=8F=8D=E5=BC=95=E5=8F=B7=E5=92=8Ceval=E7=9A=84AOT?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/aot/abstract-class.phpt | 57 ++++++++++++++++++++++++++++++ tests/aot/backtick.phpt | 21 +++++++++++ tests/aot/eval-test.phpt | 30 ++++++++++++++++ tests/aot/final-class.phpt | 50 +++++++++++++++++++++++++++ tests/aot/interface.phpt | 65 +++++++++++++++++++++++++++++++++++ 5 files changed, 223 insertions(+) create mode 100644 tests/aot/abstract-class.phpt create mode 100644 tests/aot/backtick.phpt create mode 100644 tests/aot/eval-test.phpt create mode 100644 tests/aot/final-class.phpt create mode 100644 tests/aot/interface.phpt diff --git a/tests/aot/abstract-class.phpt b/tests/aot/abstract-class.phpt new file mode 100644 index 00000000..65b14682 --- /dev/null +++ b/tests/aot/abstract-class.phpt @@ -0,0 +1,57 @@ +--TEST-- +abstract class and abstract method +--FILE-- +name = $name; + } + + abstract public function speak(): string; + + public function getName(): string { + return $this->name; + } + + public function describe(): string { + return $this->getName() . " says " . $this->speak(); + } +} + +class Dog extends Animal { + public function speak(): string { + return "woof"; + } +} + +class Cat extends Animal { + public function speak(): string { + return "meow"; + } +} + +function main() { + $dog = new Dog("Buddy"); + $cat = new Cat("Kitty"); + + var_dump($dog->getName()); + var_dump($dog->speak()); + var_dump($dog->describe()); + + var_dump($cat->getName()); + var_dump($cat->speak()); + + echo "done\n"; +} + +?> +--EXPECT-- +string(5) "Buddy" +string(4) "woof" +string(15) "Buddy says woof" +string(5) "Kitty" +string(4) "meow" +done diff --git a/tests/aot/backtick.phpt b/tests/aot/backtick.phpt new file mode 100644 index 00000000..905fe1a4 --- /dev/null +++ b/tests/aot/backtick.phpt @@ -0,0 +1,21 @@ +--TEST-- +shell_exec / backtick operator +--FILE-- + +--EXPECT-- +string(5) "hello" +string(5) "world" +done diff --git a/tests/aot/eval-test.phpt b/tests/aot/eval-test.phpt new file mode 100644 index 00000000..89632f7e --- /dev/null +++ b/tests/aot/eval-test.phpt @@ -0,0 +1,30 @@ +--TEST-- +eval() language construct +--FILE-- + +--EXPECT-- +int(15) +string(11) "hello world" +int(6) +done diff --git a/tests/aot/final-class.phpt b/tests/aot/final-class.phpt new file mode 100644 index 00000000..f5dcec27 --- /dev/null +++ b/tests/aot/final-class.phpt @@ -0,0 +1,50 @@ +--TEST-- +final class and final method +--FILE-- +overridable()); + var_dump($base->locked()); + + $derived = new Derived(); + var_dump($derived->overridable()); + var_dump($derived->locked()); + + $sealed = new Sealed(); + var_dump($sealed->value()); + + echo "done\n"; +} + +?> +--EXPECT-- +string(4) "base" +string(15) "cannot override" +string(7) "derived" +string(15) "cannot override" +int(42) +done diff --git a/tests/aot/interface.phpt b/tests/aot/interface.phpt new file mode 100644 index 00000000..8ad403b8 --- /dev/null +++ b/tests/aot/interface.phpt @@ -0,0 +1,65 @@ +--TEST-- +interface implementation +--FILE-- +entries[] = $message; + } + + public function format(string $message): string { + return '{"msg":"' . $message . '"}'; + } + + public function getEntries(): array { + return $this->entries; + } +} + +function main() { + $console = new ConsoleLogger(); + $console->log("test message"); + + $json = new JsonLogger(); + $json->log("hello"); + $json->log("world"); + var_dump($json->getEntries()); + var_dump($json->format("hi")); + + $logger = $json; + var_dump($logger instanceof Logger); + var_dump($logger instanceof Formatter); + + echo "done\n"; +} + +?> +--EXPECT-- +LOG: test message +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +string(12) "{"msg":"hi"}" +bool(true) +bool(true) +done