diff --git a/tests/std/array/001.phpt b/tests/std/array/001.phpt new file mode 100644 index 00000000..7631525e --- /dev/null +++ b/tests/std/array/001.phpt @@ -0,0 +1,66 @@ +--TEST-- +array_diff: string-based comparison +--FILE-- + "hello", "b" => "world"]; + $h = ["hello"]; + $r = array_diff($g, $h); + var_dump($r); + + // Numeric strings match integers (both become same string) + $i = [100, 200, 300]; + $j = ["200"]; + $r = array_diff($i, $j); + var_dump($r); +} +?> +--EXPECT-- +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +array(1) { + ["b"]=> + string(5) "world" +} +array(2) { + [0]=> + int(100) + [2]=> + int(300) +} diff --git a/tests/std/array/002.phpt b/tests/std/array/002.phpt new file mode 100644 index 00000000..f25cfb7e --- /dev/null +++ b/tests/std/array/002.phpt @@ -0,0 +1,47 @@ +--TEST-- +array_intersect: string-based comparison +--FILE-- + "hello", "b" => "world"]; + $f = ["world", "extra"]; + $r = array_intersect($e, $f); + var_dump($r); + + // Empty result + $g = [1, 2, 3]; + $h = [4, 5, 6]; + $r = array_intersect($g, $h); + var_dump($r); +} +?> +--EXPECT-- +array(2) { + [0]=> + int(1) + [3]=> + string(1) "1" +} +array(1) { + [1]=> + int(200) +} +array(1) { + ["b"]=> + string(5) "world" +} +array(0) { +} diff --git a/tests/std/array/003.phpt b/tests/std/array/003.phpt new file mode 100644 index 00000000..b3ceaedb --- /dev/null +++ b/tests/std/array/003.phpt @@ -0,0 +1,53 @@ +--TEST-- +array_unique: sort flags +--FILE-- + 1, "b" => "1", "c" => 2, "d" => "2"]; + $r = array_unique($a, SORT_STRING); + var_dump($r); + + // SORT_REGULAR - uses zend_compare, 1 and "1" match + $b = ["a" => 1, "b" => "1", "c" => 2, "d" => "2"]; + $r = array_unique($b, SORT_REGULAR); + var_dump($r); + + // SORT_NUMERIC - numeric comparison + $c = ["a" => 1, "b" => "1.0", "c" => 2, "d" => "2.5"]; + $r = array_unique($c, SORT_NUMERIC); + var_dump($r); + + // Keys preserved (first occurrence kept) + $d = ["a" => "red", "b" => "green", "c" => "red"]; + $r = array_unique($d); + var_dump($r); +} +?> +--EXPECT-- +array(2) { + ["a"]=> + int(1) + ["c"]=> + int(2) +} +array(2) { + ["a"]=> + int(1) + ["c"]=> + int(2) +} +array(3) { + ["a"]=> + int(1) + ["c"]=> + int(2) + ["d"]=> + string(3) "2.5" +} +array(2) { + ["a"]=> + string(3) "red" + ["b"]=> + string(5) "green" +} diff --git a/tests/std/array/004.phpt b/tests/std/array/004.phpt new file mode 100644 index 00000000..d5d3b378 --- /dev/null +++ b/tests/std/array/004.phpt @@ -0,0 +1,44 @@ +--TEST-- +array_shift: non-packed re-indexing +--FILE-- + 1, "b" => 2, 0 => 3, 1 => 4]; + $v = array_shift($a); + var_dump($v); + var_dump($a); + + // Mixed keys with gaps + $b = [5 => "first", "key" => "second", 10 => "third"]; + $v = array_shift($b); + var_dump($v); + var_dump($b); + + // Single element + $c = ["only" => "one"]; + $v = array_shift($c); + var_dump($v); + var_dump($c); +} +?> +--EXPECT-- +int(1) +array(3) { + ["b"]=> + int(2) + [0]=> + int(3) + [1]=> + int(4) +} +string(5) "first" +array(2) { + ["key"]=> + string(6) "second" + [0]=> + string(5) "third" +} +string(3) "one" +array(0) { +} diff --git a/tests/std/array/005.phpt b/tests/std/array/005.phpt new file mode 100644 index 00000000..491c2b97 --- /dev/null +++ b/tests/std/array/005.phpt @@ -0,0 +1,48 @@ +--TEST-- +array_unshift: preserves string keys +--FILE-- + 1, "b" => 2]; + $c = array_unshift($a, "new1", "new2"); + var_dump($c); + var_dump($a); + + // Mixed integer and string keys + $b = [0 => "zero", "key" => "value"]; + array_unshift($b, "prepended"); + var_dump($b); + + // Return value is new count + $d = []; + $c = array_unshift($d, "x"); + var_dump($c); + var_dump($d); +} +?> +--EXPECT-- +int(4) +array(4) { + [0]=> + string(4) "new1" + [1]=> + string(4) "new2" + ["a"]=> + int(1) + ["b"]=> + int(2) +} +array(3) { + [0]=> + string(9) "prepended" + [1]=> + string(4) "zero" + ["key"]=> + string(5) "value" +} +int(1) +array(1) { + [0]=> + string(1) "x" +} diff --git a/tests/std/array/006.phpt b/tests/std/array/006.phpt new file mode 100644 index 00000000..58e14c4f --- /dev/null +++ b/tests/std/array/006.phpt @@ -0,0 +1,46 @@ +--TEST-- +ksort: flag handling +--FILE-- + 1, "a" => 2, "b" => 3]; + ksort($a); + var_dump($a); + + // SORT_NUMERIC — numeric key comparison + $b = ["10" => "ten", "2" => "two", "1" => "one"]; + ksort($b, SORT_NUMERIC); + var_dump($b); + + // Mixed int and string keys + $c = ["b" => 1, 0 => 2, "a" => 3]; + ksort($c); + var_dump($c); +} +?> +--EXPECT-- +array(3) { + ["a"]=> + int(2) + ["b"]=> + int(3) + ["c"]=> + int(1) +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [10]=> + string(3) "ten" +} +array(3) { + [0]=> + int(2) + ["a"]=> + int(3) + ["b"]=> + int(1) +} diff --git a/tests/std/array/007.phpt b/tests/std/array/007.phpt new file mode 100644 index 00000000..e27e8838 --- /dev/null +++ b/tests/std/array/007.phpt @@ -0,0 +1,37 @@ +--TEST-- +array_sum / array_product: type handling +--FILE-- + +--EXPECT-- +int(3) +int(0) +float(3.5) +float(5) +int(6) +int(6) +float(3.5) +float(5) +int(0) +int(1) diff --git a/tests/std/array/008.phpt b/tests/std/array/008.phpt new file mode 100644 index 00000000..fcfa859c --- /dev/null +++ b/tests/std/array/008.phpt @@ -0,0 +1,69 @@ +--TEST-- +array_combine: non-int/non-string key handling +--FILE-- + +--EXPECT-- +array(3) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) +} +array(3) { + [10]=> + string(1) "a" + [20]=> + string(1) "b" + [30]=> + string(1) "c" +} +array(2) { + ["1.5"]=> + string(5) "first" + ["2.5"]=> + string(6) "second" +} +array(1) { + [""]=> + string(8) "null_key" +} +array(2) { + [1]=> + string(8) "true_val" + [""]=> + string(9) "false_val" +}