- 为std::vector添加复杂值类型测试用例 - 为std::map添加复杂值类型测试用例 - 为std::unordered_map添加复杂值类型测试用例 - 为std::array添加复杂值类型测试用例 - 测试字符串、数组、对象、变体等复杂类型的存储和访问 - 验证精确类值类型的容器行为 - 包含错误处理和异常情况的测试场景pull/1/head
parent
73bf28667d
commit
9f2db2f6c0
5 changed files with 259 additions and 0 deletions
@ -0,0 +1,48 @@ |
|||||||
|
--TEST-- |
||||||
|
std array: complex value types |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class StdArrayComplexValue |
||||||
|
{ |
||||||
|
public function __construct(public int $value) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public function getValue(): int |
||||||
|
{ |
||||||
|
return $this->value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$strings = std::array(complex_types::type_string, 2); |
||||||
|
$strings[0] = 321; |
||||||
|
var_dump($strings[0]); |
||||||
|
|
||||||
|
$arrays = std::array(complex_types::type_array, 2); |
||||||
|
$arrays[0] = ["name" => "array", "value" => 64]; |
||||||
|
$array = $arrays[0]; |
||||||
|
var_dump($array["name"]); |
||||||
|
var_dump($array["value"]); |
||||||
|
|
||||||
|
$objects = std::array(complex_types::type_object, 2); |
||||||
|
$objects[0] = new StdArrayComplexValue(28); |
||||||
|
var_dump($objects[0] instanceof StdArrayComplexValue); |
||||||
|
$object = objval($objects[0], StdArrayComplexValue::class); |
||||||
|
var_dump($object->getValue()); |
||||||
|
|
||||||
|
$variants = std::array(complex_types::type_any, 2); |
||||||
|
$variants[0] = 123; |
||||||
|
$variants[1] = "variant"; |
||||||
|
var_dump($variants[0]); |
||||||
|
var_dump($variants[1]); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(3) "321" |
||||||
|
string(5) "array" |
||||||
|
int(64) |
||||||
|
bool(true) |
||||||
|
int(28) |
||||||
|
int(123) |
||||||
|
string(7) "variant" |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
--TEST-- |
||||||
|
std map: complex value types |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class StdMapComplexValue |
||||||
|
{ |
||||||
|
public function __construct(public int $value) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public function getValue(): int |
||||||
|
{ |
||||||
|
return $this->value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$strings = std::map(native_types::type_int, complex_types::type_str); |
||||||
|
$strings[1] = 456; |
||||||
|
var_dump($strings[1]); |
||||||
|
|
||||||
|
$arrays = std::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::map(complex_types::type_string, complex_types::type_object); |
||||||
|
$objects["item"] = new StdMapComplexValue(14); |
||||||
|
var_dump($objects["item"] instanceof StdMapComplexValue); |
||||||
|
$object = objval($objects["item"], StdMapComplexValue::class); |
||||||
|
var_dump($object->getValue()); |
||||||
|
|
||||||
|
$variants = std::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" |
||||||
@ -0,0 +1,67 @@ |
|||||||
|
--TEST-- |
||||||
|
std containers: exact class value type |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class StdContainerClassValue |
||||||
|
{ |
||||||
|
public function __construct(public int $value) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public function getValue(): int |
||||||
|
{ |
||||||
|
return $this->value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class StdContainerClassValueChild extends StdContainerClassValue |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
class StdContainerClassValueOther |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
function std_container_class_value_mixed(mixed $value): mixed |
||||||
|
{ |
||||||
|
return $value; |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$map = std::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()); |
||||||
|
|
||||||
|
$unordered = std::unordered_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) |
||||||
|
std container value expects exact object of class `StdContainerClassValue` |
||||||
|
std container value expects exact object of class `StdContainerClassValue` |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
--TEST-- |
||||||
|
std unordered map: complex value types |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class StdUnorderedMapComplexValue |
||||||
|
{ |
||||||
|
public function __construct(public int $value) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public function getValue(): int |
||||||
|
{ |
||||||
|
return $this->value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$strings = std::unordered_map(native_types::type_int, complex_types::type_string); |
||||||
|
$strings[1] = 789; |
||||||
|
var_dump($strings[1]); |
||||||
|
|
||||||
|
$arrays = std::unordered_map(complex_types::type_string, complex_types::type_array); |
||||||
|
$arrays["item"] = ["name" => "unordered", "value" => 168]; |
||||||
|
$array = $arrays["item"]; |
||||||
|
var_dump($array["name"]); |
||||||
|
var_dump($array["value"]); |
||||||
|
|
||||||
|
$objects = std::unordered_map(native_types::type_int, complex_types::type_object); |
||||||
|
$objects[2] = new StdUnorderedMapComplexValue(21); |
||||||
|
var_dump($objects[2] instanceof StdUnorderedMapComplexValue); |
||||||
|
$object = objval($objects[2], StdUnorderedMapComplexValue::class); |
||||||
|
var_dump($object->getValue()); |
||||||
|
|
||||||
|
$variants = std::unordered_map(native_types::type_int, complex_types::type_var); |
||||||
|
$variants[3] = false; |
||||||
|
$variants[4] = "variant"; |
||||||
|
var_dump($variants[3]); |
||||||
|
var_dump($variants[4]); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(3) "789" |
||||||
|
string(9) "unordered" |
||||||
|
int(168) |
||||||
|
bool(true) |
||||||
|
int(21) |
||||||
|
bool(false) |
||||||
|
string(7) "variant" |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
--TEST-- |
||||||
|
std vector: complex value types |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class StdVectorComplexValue |
||||||
|
{ |
||||||
|
public function __construct(public int $value) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public function getValue(): int |
||||||
|
{ |
||||||
|
return $this->value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$strings = std::vector(complex_types::type_string); |
||||||
|
$strings[] = 123; |
||||||
|
var_dump($strings[0]); |
||||||
|
|
||||||
|
$arrays = std::vector(complex_types::type_array); |
||||||
|
$arrays[] = ["name" => "vector", "value" => 42]; |
||||||
|
$array = $arrays[0]; |
||||||
|
var_dump($array["name"]); |
||||||
|
var_dump($array["value"]); |
||||||
|
|
||||||
|
$objects = std::vector(complex_types::type_object); |
||||||
|
$objects[] = new StdVectorComplexValue(7); |
||||||
|
var_dump($objects[0] instanceof StdVectorComplexValue); |
||||||
|
$object = objval($objects[0], StdVectorComplexValue::class); |
||||||
|
var_dump($object->getValue()); |
||||||
|
|
||||||
|
$variants = std::vector(complex_types::type_variant); |
||||||
|
$variants[] = 99; |
||||||
|
$variants[] = "mixed"; |
||||||
|
var_dump($variants[0]); |
||||||
|
var_dump($variants[1]); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(3) "123" |
||||||
|
string(6) "vector" |
||||||
|
int(42) |
||||||
|
bool(true) |
||||||
|
int(7) |
||||||
|
int(99) |
||||||
|
string(5) "mixed" |
||||||
Loading…
Reference in new issue