From 71cd8daad157ef3e2cbf885d64e3c077545cc267 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 11 Jun 2026 19:05:55 +0800 Subject: [PATCH] =?UTF-8?q?test(stdlib):=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E6=A0=87=E5=87=86=E5=BA=93=E5=87=BD=E6=95=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 测试 gettype 函数对不同数据类型的返回值 - 验证 ucfirst 函数首字母大写功能 - 检查 floor 和 ceil 数学函数的正确性 - 测试 max 和 min 函数的数值比较功能 - 验证 uniqid 函数生成唯一标识符的能力 - 测试 reset 和 end 数组指针操作函数 - --- tests/std/core/012_new_functions.phpt | 148 ++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 tests/std/core/012_new_functions.phpt diff --git a/tests/std/core/012_new_functions.phpt b/tests/std/core/012_new_functions.phpt new file mode 100644 index 00000000..30b544dd --- /dev/null +++ b/tests/std/core/012_new_functions.phpt @@ -0,0 +1,148 @@ +--TEST-- +New stdlib functions - realpath, gettype, uniqid, ucfirst, reset, end, ksort, array_reverse, array_diff, max, min, floor, ceil +--FILE-- + 10); +$id2 = uniqid("pref_"); +var_dump(strncmp($id2, "pref_", 5) === 0); +$id3 = uniqid("", true); +var_dump(strlen($id3) > 20); + +echo "== reset() / end() ==\n"; +$arr = [1, 2, 3]; +var_dump(reset($arr)); +var_dump(end($arr)); +$arr2 = ['a' => 10, 'b' => 20, 'c' => 30]; +var_dump(reset($arr2)); +var_dump(end($arr2)); + +echo "== ksort() ==\n"; +$arr3 = ['c' => 3, 'a' => 1, 'b' => 2]; +ksort($arr3); +echo implode(',', array_keys($arr3)) . "\n"; +echo implode(',', array_values($arr3)) . "\n"; + +echo "== array_reverse() ==\n"; +print_r(array_reverse([1, 2, 3])); +print_r(array_reverse(['a' => 1, 'b' => 2, 'c' => 3])); +print_r(array_reverse(['a' => 1, 'b' => 2, 'c' => 3], true)); + +echo "== array_diff() ==\n"; +print_r(array_diff([1, 2, 3], [2, 4])); +print_r(array_diff(['a' => 1, 'b' => 2, 'c' => 3], [2])); +print_r(array_diff([1, 2, 3], [1, 2, 3])); + +echo "== realpath() ==\n"; +$path = realpath("/"); +var_dump($path !== false); + +?> +--EXPECT-- +== gettype() == +string(7) "integer" +string(6) "string" +string(6) "double" +string(7) "boolean" +string(5) "array" +string(4) "NULL" +== ucfirst() == +Hello +World + +A +123abc +== floor() / ceil() == +float(3) +float(4) +float(-4) +float(-3) +float(5) +float(5) +== max() / min() == +int(3) +int(1) +int(1) +int(-1) +string(1) "c" +string(1) "a" +== uniqid() == +bool(true) +bool(true) +bool(true) +== reset() / end() == +int(1) +int(3) +int(10) +int(30) +== ksort() == +a,b,c +1,2,3 +== array_reverse() == +Array +( + [0] => 3 + [1] => 2 + [2] => 1 +) +Array +( + [0] => 3 + [1] => 2 + [2] => 1 +) +Array +( + [c] => 3 + [b] => 2 + [a] => 1 +) +== array_diff() == +Array +( + [0] => 1 + [2] => 3 +) +Array +( + [a] => 1 + [c] => 3 +) +Array +( +) +== realpath() == +bool(true)