From 715d2222e855d6a1ceabba58342a612c69d30025 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sun, 21 Jun 2026 11:17:32 +0800 Subject: [PATCH] =?UTF-8?q?test(aot):=20=E6=B7=BB=E5=8A=A0=20std=20ordered?= =?UTF-8?q?=5Fmap=20=E5=8A=9F=E8=83=BD=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 - 测试基本的 ordered_map 操作,包括整数键浮点数值的存储和更新 - 测试字符串键的 ordered_map 功能及类型处理 - 测试复杂值类型的 ordered_map,包括字符串、数组、对象和变体类型 - 测试精确类值类型的容器功能,验证类型安全和继承关系 - 测试 unsafe_cast 功能及其类型转换行为 - 测试 unsafe_cast 类型不匹配的错误处理 - 测试 ordered_map 与 PHP 数组之间的赋值操作 - 测试相同类型的 ordered_map 之间复制操作 - 测试 unset 操作对 ordered_map 元素的删除功能 - 测试遍历过程中 unset 元素的行为表现 --- tests/aot/std-ordered-map/001.phpt | 19 +++++++++ tests/aot/std-ordered-map/002.phpt | 25 +++++++++++ tests/aot/std-ordered-map/003.phpt | 48 +++++++++++++++++++++ tests/aot/std-ordered-map/004.phpt | 67 ++++++++++++++++++++++++++++++ tests/aot/std-ordered-map/005.phpt | 30 +++++++++++++ tests/aot/std-ordered-map/006.phpt | 20 +++++++++ tests/aot/std-ordered-map/007.phpt | 21 ++++++++++ tests/aot/std-ordered-map/008.phpt | 25 +++++++++++ tests/aot/std-ordered-map/009.phpt | 24 +++++++++++ tests/aot/std-ordered-map/010.phpt | 32 ++++++++++++++ 10 files changed, 311 insertions(+) create mode 100644 tests/aot/std-ordered-map/001.phpt create mode 100644 tests/aot/std-ordered-map/002.phpt create mode 100644 tests/aot/std-ordered-map/003.phpt create mode 100644 tests/aot/std-ordered-map/004.phpt create mode 100644 tests/aot/std-ordered-map/005.phpt create mode 100644 tests/aot/std-ordered-map/006.phpt create mode 100644 tests/aot/std-ordered-map/007.phpt create mode 100644 tests/aot/std-ordered-map/008.phpt create mode 100644 tests/aot/std-ordered-map/009.phpt create mode 100644 tests/aot/std-ordered-map/010.phpt diff --git a/tests/aot/std-ordered-map/001.phpt b/tests/aot/std-ordered-map/001.phpt new file mode 100644 index 00000000..3e5bdd72 --- /dev/null +++ b/tests/aot/std-ordered-map/001.phpt @@ -0,0 +1,19 @@ +--TEST-- +std ordered_map: 001 +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +int(2) diff --git a/tests/aot/std-ordered-map/002.phpt b/tests/aot/std-ordered-map/002.phpt new file mode 100644 index 00000000..440a628c --- /dev/null +++ b/tests/aot/std-ordered-map/002.phpt @@ -0,0 +1,25 @@ +--TEST-- +std ordered_map: string key +--FILE-- + +--EXPECT-- +int(10) +int(42) +int(2) +bool(true) diff --git a/tests/aot/std-ordered-map/003.phpt b/tests/aot/std-ordered-map/003.phpt new file mode 100644 index 00000000..9c4cf8ee --- /dev/null +++ b/tests/aot/std-ordered-map/003.phpt @@ -0,0 +1,48 @@ +--TEST-- +std ordered_map: complex value types +--FILE-- +value; + } +} + +function main() { + $strings = std::ordered_map(native_types::type_int, complex_types::type_str); + $strings[1] = 456; + var_dump($strings[1]); + + $arrays = std::ordered_map(native_types::type_int, complex_types::type_array); + $arrays[2] = ["name" => "map", "value" => 84]; + $array = $arrays[2]; + var_dump($array["name"]); + var_dump($array["value"]); + + $objects = std::ordered_map(complex_types::type_string, complex_types::type_object); + $objects["item"] = new StdMapComplexValue(14); + var_dump($objects["item"] instanceof StdMapComplexValue); + $object = $objects["item"]->toObject(StdMapComplexValue::class); + var_dump($object->getValue()); + + $variants = std::ordered_map(native_types::type_int, complex_types::type_any); + $variants[3] = 12.5; + $variants[4] = "any"; + var_dump($variants[3]); + var_dump($variants[4]); +} +?> +--EXPECT-- +string(3) "456" +string(3) "map" +int(84) +bool(true) +int(14) +float(12.5) +string(3) "any" diff --git a/tests/aot/std-ordered-map/004.phpt b/tests/aot/std-ordered-map/004.phpt new file mode 100644 index 00000000..7b4a6f3c --- /dev/null +++ b/tests/aot/std-ordered-map/004.phpt @@ -0,0 +1,67 @@ +--TEST-- +std containers: exact class value type +--FILE-- +value; + } +} + +class StdContainerClassValueChild extends StdContainerClassValue +{ +} + +class StdContainerClassValueOther +{ +} + +function std_container_class_value_mixed(mixed $value): mixed +{ + return $value; +} + +function main() { + $map = std::ordered_map(complex_types::type_str, StdContainerClassValue::class); + $map["a"] = new StdContainerClassValue(1); + $item = $map["a"]; + var_dump($item->getValue()); + + $vector = std::vector(StdContainerClassValue::class); + $vector[] = new StdContainerClassValue(2); + var_dump($vector[0]->getValue()); + + $array = std::array(StdContainerClassValue::class, 2); + $array[0] = new StdContainerClassValue(3); + var_dump($array[0]->getValue()); + + $ordered = std::map(native_types::type_int, StdContainerClassValue::class); + $unordered[1] = std_container_class_value_mixed(new StdContainerClassValue(4)); + var_dump($unordered[1]->getValue()); + + try { + $unordered[2] = std_container_class_value_mixed(new StdContainerClassValueChild(5)); + } catch (Throwable $e) { + echo $e->getMessage(), "\n"; + } + + try { + $unordered[3] = std_container_class_value_mixed(new StdContainerClassValueOther()); + } catch (Throwable $e) { + echo $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +int(1) +int(2) +int(3) +int(4) +The parameter `object` must be instance of class `StdContainerClassValue`, object of `StdContainerClassValueChild` given +The parameter `object` must be instance of class `StdContainerClassValue`, object of `StdContainerClassValueOther` given diff --git a/tests/aot/std-ordered-map/005.phpt b/tests/aot/std-ordered-map/005.phpt new file mode 100644 index 00000000..3f351594 --- /dev/null +++ b/tests/aot/std-ordered-map/005.phpt @@ -0,0 +1,30 @@ +--TEST-- +std ordered_map: unsafe_cast +--FILE-- +toStdMap(complex_types::type_str, native_types::type_int); + var_dump($map["b"]); + $map["c"] = 9; + + unset($source); + + $array = (array)$map; + var_dump(count($array)); +} + +function main() { + $map = std::ordered_map(complex_types::type_str, native_types::type_int); + $map["a"] = 1; + $map["b"] = 7; + $map["c"] = 3; + + std_map_unsafe_ptr_update($map); + var_dump($map["c"]); +} +?> +--EXPECT-- +int(7) +int(3) +int(9) diff --git a/tests/aot/std-ordered-map/006.phpt b/tests/aot/std-ordered-map/006.phpt new file mode 100644 index 00000000..cf407278 --- /dev/null +++ b/tests/aot/std-ordered-map/006.phpt @@ -0,0 +1,20 @@ +--TEST-- +std ordered_map: unsafe_cast type mismatch +--FILE-- +toStdMap(complex_types::type_str, native_types::type_float); +} + +function main() { + $map = std::ordered_map(complex_types::type_str, native_types::type_int); + try { + std_map_unsafe_ptr_type_mismatch($map); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +std container type mismatch diff --git a/tests/aot/std-ordered-map/007.phpt b/tests/aot/std-ordered-map/007.phpt new file mode 100644 index 00000000..55a42fac --- /dev/null +++ b/tests/aot/std-ordered-map/007.phpt @@ -0,0 +1,21 @@ +--TEST-- +std ordered_map: assign to PHP array +--FILE-- + +--EXPECT-- +bool(true) +int(2) +int(100) +int(200) diff --git a/tests/aot/std-ordered-map/008.phpt b/tests/aot/std-ordered-map/008.phpt new file mode 100644 index 00000000..300ca268 --- /dev/null +++ b/tests/aot/std-ordered-map/008.phpt @@ -0,0 +1,25 @@ +--TEST-- +std ordered_map: same type copy +--FILE-- + +--EXPECT-- +int(2) +int(100) +int(200) +int(100) diff --git a/tests/aot/std-ordered-map/009.phpt b/tests/aot/std-ordered-map/009.phpt new file mode 100644 index 00000000..4aada09d --- /dev/null +++ b/tests/aot/std-ordered-map/009.phpt @@ -0,0 +1,24 @@ +--TEST-- +std ordered_map: unset +--FILE-- + +--EXPECT-- +array(2) { + ["alpha"]=> + int(10) + ["beta"]=> + int(20) +} +array(1) { + ["beta"]=> + int(20) +} \ No newline at end of file diff --git a/tests/aot/std-ordered-map/010.phpt b/tests/aot/std-ordered-map/010.phpt new file mode 100644 index 00000000..34190551 --- /dev/null +++ b/tests/aot/std-ordered-map/010.phpt @@ -0,0 +1,32 @@ +--TEST-- +std ordered_map: unset +--FILE-- + $v) { + var_dump($k, $v); + } + unset($map["beta"]); + echo "unset-------------\n"; + foreach ($map as $k => $v) { + var_dump($k, $v); + } +} +?> +--EXPECT-- +string(5) "alpha" +int(10) +string(4) "beta" +int(20) +string(5) "gamma" +int(30) +unset------------- +string(5) "alpha" +int(10) +string(5) "gamma" +int(30) \ No newline at end of file