mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
New testcases for array_diff_uassoc() function
This commit is contained in:
parent
f2ad965863
commit
55039a95fd
62
ext/standard/tests/array/array_diff_uassoc_error.phpt
Normal file
62
ext/standard/tests/array/array_diff_uassoc_error.phpt
Normal file
@ -0,0 +1,62 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : error conditions ***\n";
|
||||
|
||||
//Initialize array
|
||||
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
$array2 = array("a" => "green", "yellow", "red");
|
||||
$array3 = array("a" => "green", "red");
|
||||
$array4 = array();
|
||||
$extra_arg = array(1, 2, 3, 4);
|
||||
|
||||
function key_compare_func($a, $b)
|
||||
{
|
||||
if ($a === $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a > $b)? 1:-1;
|
||||
}
|
||||
|
||||
//Test array_diff_uassoc with one more than the expected number of arguments
|
||||
echo "\n-- Testing array_diff_uassoc() function with more than expected no. of arguments --\n";
|
||||
var_dump( array_diff_uassoc($array1, $array2, "key_compare_func", $extra_arg) );
|
||||
var_dump( array_diff_uassoc($array1, $array2, $array3, $array4, "key_compare_func", $extra_arg) );
|
||||
|
||||
// Testing array_diff_uassoc with one less than the expected number of arguments
|
||||
echo "\n-- Testing array_diff_uassoc() function with less than expected no. of arguments --\n";
|
||||
var_dump( array_diff_uassoc($array1, $array2) );
|
||||
|
||||
// Testing array_diff_uassoc with no arguments
|
||||
echo "\n-- Testing array_diff_uassoc() function with no arguments --\n";
|
||||
var_dump( array_diff_uassoc() );
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : error conditions ***
|
||||
|
||||
-- Testing array_diff_uassoc() function with more than expected no. of arguments --
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 6 to be a valid callback, array must have exactly two members in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Testing array_diff_uassoc() function with less than expected no. of arguments --
|
||||
|
||||
Warning: array_diff_uassoc(): at least 3 parameters are required, 2 given in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Testing array_diff_uassoc() function with no arguments --
|
||||
|
||||
Warning: array_diff_uassoc(): at least 3 parameters are required, 0 given in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
244
ext/standard/tests/array/array_diff_uassoc_variation1.phpt
Normal file
244
ext/standard/tests/array/array_diff_uassoc_variation1.phpt
Normal file
@ -0,0 +1,244 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Passing unexpected values to first argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$array2 = array("a" => "green", "yellow", "red");
|
||||
|
||||
function key_compare_func($a, $b)
|
||||
{
|
||||
if ($a === $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a > $b)? 1:-1;
|
||||
}
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
//resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// define some classes
|
||||
class classWithToString
|
||||
{
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
class classWithoutToString
|
||||
{
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// add arrays
|
||||
$index_array = array (1, 2, 3);
|
||||
$assoc_array = array ('one' => 1, 'two' => 2);
|
||||
|
||||
//array of values to iterate over
|
||||
$inputs = array(
|
||||
|
||||
// int data
|
||||
'int 0' => 0,
|
||||
'int 1' => 1,
|
||||
'int 12345' => 12345,
|
||||
'int -12345' => -2345,
|
||||
|
||||
// float data
|
||||
'float 10.5' => 10.5,
|
||||
'float -10.5' => -10.5,
|
||||
'float 12.3456789000e10' => 12.3456789000e10,
|
||||
'float -12.3456789000e10' => -12.3456789000e10,
|
||||
'float .5' => .5,
|
||||
|
||||
// null data
|
||||
'uppercase NULL' => NULL,
|
||||
'lowercase null' => null,
|
||||
|
||||
// boolean data
|
||||
'lowercase true' => true,
|
||||
'lowercase false' =>false,
|
||||
'uppercase TRUE' =>TRUE,
|
||||
'uppercase FALSE' =>FALSE,
|
||||
|
||||
// empty data
|
||||
'empty string DQ' => "",
|
||||
'empty string SQ' => '',
|
||||
|
||||
// string data
|
||||
'string DQ' => "string",
|
||||
'string SQ' => 'string',
|
||||
'mixed case string' => "sTrInG",
|
||||
'heredoc' => $heredoc,
|
||||
|
||||
// object data
|
||||
'instance of classWithToString' => new classWithToString(),
|
||||
'instance of classWithoutToString' => new classWithoutToString(),
|
||||
|
||||
// undefined data
|
||||
'undefined var' => @$undefined_var,
|
||||
|
||||
// unset data
|
||||
'unset var' => @$unset_var,
|
||||
|
||||
// resource data
|
||||
'resource' => $fp,
|
||||
);
|
||||
|
||||
// loop through each element of the array for arr1
|
||||
|
||||
foreach($inputs as $key =>$value) {
|
||||
echo "\n--$key--\n";
|
||||
var_dump( array_diff_uassoc($value, $array2, "key_compare_func") );
|
||||
};
|
||||
|
||||
fclose($fp);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
--int 0--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 1--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 12345--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int -12345--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 10.5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -10.5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float .5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase NULL--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase null--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase true--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase false--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase TRUE--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase FALSE--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string DQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string SQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string DQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string SQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--mixed case string--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--heredoc--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithToString--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithoutToString--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--undefined var--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--unset var--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--resource--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
47
ext/standard/tests/array/array_diff_uassoc_variation10.phpt
Normal file
47
ext/standard/tests/array/array_diff_uassoc_variation10.phpt
Normal file
@ -0,0 +1,47 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Passing float indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
// Initialise function arguments not being substituted (if any)
|
||||
$input_array = array(0 => '0', 10 => '10', -10 => '-10', 20 =>'20', -20 => '-20');
|
||||
$float_indx_array = array(0.0 => '0.0', 10.5 => '10.5', -10.5 => '-10.5', 0.5 => '0.5');
|
||||
|
||||
echo "\n-- Testing array_diff_key() function with float indexed array --\n";
|
||||
var_dump( array_diff_uassoc($input_array, $float_indx_array, "strcasecmp") );
|
||||
var_dump( array_diff_uassoc($float_indx_array, $input_array, "strcasecmp") );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
-- Testing array_diff_key() function with float indexed array --
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(1) "0"
|
||||
[10]=>
|
||||
string(2) "10"
|
||||
[-10]=>
|
||||
string(3) "-10"
|
||||
[20]=>
|
||||
string(2) "20"
|
||||
[-20]=>
|
||||
string(3) "-20"
|
||||
}
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(3) "0.5"
|
||||
[10]=>
|
||||
string(4) "10.5"
|
||||
[-10]=>
|
||||
string(5) "-10.5"
|
||||
}
|
||||
===DONE===
|
45
ext/standard/tests/array/array_diff_uassoc_variation11.phpt
Normal file
45
ext/standard/tests/array/array_diff_uassoc_variation11.phpt
Normal file
@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Passing boolean indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
// Initialise function arguments not being substituted (if any)
|
||||
$input_array = array(0 => '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0);
|
||||
$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF');
|
||||
|
||||
echo "\n-- Testing array_diff_key() function with float indexed array --\n";
|
||||
var_dump( array_diff_uassoc($input_array, $boolean_indx_array, "strcasecmp") );
|
||||
var_dump( array_diff_uassoc($boolean_indx_array, $input_array, "strcasecmp") );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
-- Testing array_diff_key() function with float indexed array --
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(1) "0"
|
||||
[1]=>
|
||||
string(1) "1"
|
||||
[-10]=>
|
||||
string(3) "-10"
|
||||
["true"]=>
|
||||
int(1)
|
||||
["false"]=>
|
||||
int(0)
|
||||
}
|
||||
array(2) {
|
||||
[1]=>
|
||||
string(5) "boolT"
|
||||
[0]=>
|
||||
string(5) "boolF"
|
||||
}
|
||||
===DONE===
|
60
ext/standard/tests/array/array_diff_uassoc_variation12.phpt
Normal file
60
ext/standard/tests/array/array_diff_uassoc_variation12.phpt
Normal file
@ -0,0 +1,60 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Passing null,unset and undefined variable indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
// Initialise function arguments not being substituted (if any)
|
||||
$input_array = array(10 => '10', "" => '');
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
$input_arrays = array(
|
||||
'null indexed' => array(NULL => NULL, null => null),
|
||||
'undefined indexed' => array(@$undefined_var => @$undefined_var),
|
||||
'unset indexed' => array(@$unset_var => @$unset_var),
|
||||
);
|
||||
|
||||
foreach($input_arrays as $key =>$value) {
|
||||
echo "\n--$key--\n";
|
||||
var_dump( array_diff_uassoc($input_array, $value, "strcasecmp") );
|
||||
var_dump( array_diff_uassoc($value, $input_array, "strcasecmp") );
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
--null indexed--
|
||||
array(1) {
|
||||
[10]=>
|
||||
string(2) "10"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
|
||||
--undefined indexed--
|
||||
array(1) {
|
||||
[10]=>
|
||||
string(2) "10"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
|
||||
--unset indexed--
|
||||
array(1) {
|
||||
[10]=>
|
||||
string(2) "10"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
===DONE===
|
68
ext/standard/tests/array/array_diff_uassoc_variation13.phpt
Normal file
68
ext/standard/tests/array/array_diff_uassoc_variation13.phpt
Normal file
@ -0,0 +1,68 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variations - arrays containing referenced variables
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$ref_var = 'a';
|
||||
$array1 = array('a', $ref_var);
|
||||
$array2 = array('a' => 1, &$ref_var);
|
||||
|
||||
echo "\n-- Testing array_diff_uassoc() function with referenced variable \$ref_var has value '$ref_var' --\n";
|
||||
var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") );
|
||||
var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") );
|
||||
|
||||
// re-assign reference variable to different value
|
||||
$ref_var = 10.00;
|
||||
echo "\n-- Testing array_diff_uassoc() function with referenced variable \$ref_var value changed to $ref_var --\n";
|
||||
var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") );
|
||||
var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") );
|
||||
|
||||
//When array are refenced
|
||||
$array2 = &$array1;
|
||||
echo "\n-- Testing array_diff_uassoc() function when \$array2 is referenced to \$array1 --\n";
|
||||
var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") );
|
||||
var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
-- Testing array_diff_uassoc() function with referenced variable $ref_var has value 'a' --
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(1) "a"
|
||||
}
|
||||
array(1) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
-- Testing array_diff_uassoc() function with referenced variable $ref_var value changed to 10 --
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "a"
|
||||
}
|
||||
array(2) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
&float(10)
|
||||
}
|
||||
|
||||
-- Testing array_diff_uassoc() function when $array2 is referenced to $array1 --
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
===DONE===
|
244
ext/standard/tests/array/array_diff_uassoc_variation2.phpt
Normal file
244
ext/standard/tests/array/array_diff_uassoc_variation2.phpt
Normal file
@ -0,0 +1,244 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation -Passing unexpected values to second argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
|
||||
function key_compare_func($a, $b)
|
||||
{
|
||||
if ($a === $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a > $b)? 1:-1;
|
||||
}
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
//resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// define some classes
|
||||
class classWithToString
|
||||
{
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
class classWithoutToString
|
||||
{
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// add arrays
|
||||
$index_array = array (1, 2, 3);
|
||||
$assoc_array = array ('one' => 1, 'two' => 2);
|
||||
|
||||
//array of values to iterate over
|
||||
$inputs = array(
|
||||
|
||||
// int data
|
||||
'int 0' => 0,
|
||||
'int 1' => 1,
|
||||
'int 12345' => 12345,
|
||||
'int -12345' => -2345,
|
||||
|
||||
// float data
|
||||
'float 10.5' => 10.5,
|
||||
'float -10.5' => -10.5,
|
||||
'float 12.3456789000e10' => 12.3456789000e10,
|
||||
'float -12.3456789000e10' => -12.3456789000e10,
|
||||
'float .5' => .5,
|
||||
|
||||
// null data
|
||||
'uppercase NULL' => NULL,
|
||||
'lowercase null' => null,
|
||||
|
||||
// boolean data
|
||||
'lowercase true' => true,
|
||||
'lowercase false' =>false,
|
||||
'uppercase TRUE' =>TRUE,
|
||||
'uppercase FALSE' =>FALSE,
|
||||
|
||||
// empty data
|
||||
'empty string DQ' => "",
|
||||
'empty string SQ' => '',
|
||||
|
||||
// string data
|
||||
'string DQ' => "string",
|
||||
'string SQ' => 'string',
|
||||
'mixed case string' => "sTrInG",
|
||||
'heredoc' => $heredoc,
|
||||
|
||||
// object data
|
||||
'instance of classWithToString' => new classWithToString(),
|
||||
'instance of classWithoutToString' => new classWithoutToString(),
|
||||
|
||||
// undefined data
|
||||
'undefined var' => @$undefined_var,
|
||||
|
||||
// unset data
|
||||
'unset var' => @$unset_var,
|
||||
|
||||
// resource data
|
||||
'resource' => $fp,
|
||||
);
|
||||
|
||||
// loop through each element of the array for arr2
|
||||
|
||||
foreach($inputs as $key =>$value) {
|
||||
echo "\n--$key--\n";
|
||||
var_dump( array_diff_uassoc($array1, $value, "key_compare_func") );
|
||||
};
|
||||
|
||||
fclose($fp);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
--int 0--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 1--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 12345--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int -12345--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 10.5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -10.5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float .5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase NULL--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase null--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase true--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase false--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase TRUE--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase FALSE--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string DQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string SQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string DQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string SQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--mixed case string--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--heredoc--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithToString--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithoutToString--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--undefined var--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--unset var--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--resource--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
263
ext/standard/tests/array/array_diff_uassoc_variation3.phpt
Normal file
263
ext/standard/tests/array/array_diff_uassoc_variation3.phpt
Normal file
@ -0,0 +1,263 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation -Passing unexpected values to callback argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize array
|
||||
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
$array2 = array("a" => "green", "yellow", "red");
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
//resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// define some classes
|
||||
class classWithToString
|
||||
{
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
class classWithoutToString
|
||||
{
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// add arrays
|
||||
$index_array = array (1, 2, 3);
|
||||
$assoc_array = array ('one' => 1, 'two' => 2);
|
||||
|
||||
//array of values to iterate over
|
||||
$inputs = array(
|
||||
|
||||
// int data
|
||||
'int 0' => 0,
|
||||
'int 1' => 1,
|
||||
'int 12345' => 12345,
|
||||
'int -12345' => -12345,
|
||||
|
||||
// float data
|
||||
'float 10.5' => 10.5,
|
||||
'float -10.5' => -10.5,
|
||||
'float 12.3456789000e10' => 12.3456789000e10,
|
||||
'float -12.3456789000e10' => -12.3456789000e10,
|
||||
'float .5' => .5,
|
||||
|
||||
// array data
|
||||
'empty array' => array(),
|
||||
'int indexed array' => $index_array,
|
||||
'associative array' => $assoc_array,
|
||||
'nested arrays' => array('foo', $index_array, $assoc_array),
|
||||
|
||||
// null data
|
||||
'uppercase NULL' => NULL,
|
||||
'lowercase null' => null,
|
||||
|
||||
// boolean data
|
||||
'lowercase true' => true,
|
||||
'lowercase false' =>false,
|
||||
'uppercase TRUE' =>TRUE,
|
||||
'uppercase FALSE' =>FALSE,
|
||||
|
||||
// empty data
|
||||
'empty string DQ' => "",
|
||||
'empty string SQ' => '',
|
||||
|
||||
// string data
|
||||
'string DQ' => "string",
|
||||
'string SQ' => 'string',
|
||||
'mixed case string' => "sTrInG",
|
||||
'heredoc' => $heredoc,
|
||||
|
||||
// object data
|
||||
'instance of classWithToString' => new classWithToString(),
|
||||
'instance of classWithoutToString' => new classWithoutToString(),
|
||||
|
||||
// undefined data
|
||||
'undefined var' => @$undefined_var,
|
||||
|
||||
// unset data
|
||||
'unset var' => @$unset_var,
|
||||
|
||||
// resource data
|
||||
'resource' => $fp,
|
||||
);
|
||||
|
||||
// loop through each element of the array for key_comp_func
|
||||
|
||||
foreach($inputs as $key =>$value) {
|
||||
echo "\n--$key--\n";
|
||||
var_dump( array_diff_uassoc($array1, $array2, $value) );
|
||||
};
|
||||
|
||||
fclose($fp);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
--int 0--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 1--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 12345--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--int -12345--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 10.5--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -10.5--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--float .5--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty array--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d
|
||||
NULL
|
||||
|
||||
--int indexed array--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d
|
||||
NULL
|
||||
|
||||
--associative array--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %s on line %d
|
||||
NULL
|
||||
|
||||
--nested arrays--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase NULL--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase null--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase true--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase false--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase TRUE--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase FALSE--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string DQ--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string SQ--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %s on line %d
|
||||
NULL
|
||||
|
||||
--string DQ--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %s on line %d
|
||||
NULL
|
||||
|
||||
--string SQ--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %s on line %d
|
||||
NULL
|
||||
|
||||
--mixed case string--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %s on line %d
|
||||
NULL
|
||||
|
||||
--heredoc--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithToString--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithoutToString--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--undefined var--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--unset var--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
|
||||
--resource--
|
||||
|
||||
Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
246
ext/standard/tests/array/array_diff_uassoc_variation4.phpt
Normal file
246
ext/standard/tests/array/array_diff_uassoc_variation4.phpt
Normal file
@ -0,0 +1,246 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation -Passing unexpected values as third optional argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
$array2 = array("a" => "green", "yellow", "red");
|
||||
|
||||
|
||||
function key_compare_func($a, $b)
|
||||
{
|
||||
if ($a === $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a > $b)? 1:-1;
|
||||
}
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
//resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// define some classes
|
||||
class classWithToString
|
||||
{
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
class classWithoutToString
|
||||
{
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// add arrays
|
||||
$index_array = array (1, 2, 3);
|
||||
$assoc_array = array ('one' => 1, 'two' => 2);
|
||||
|
||||
//array of values to iterate over
|
||||
$inputs = array(
|
||||
|
||||
// int data
|
||||
'int 0' => 0,
|
||||
'int 1' => 1,
|
||||
'int 12345' => 12345,
|
||||
'int -12345' => -12345,
|
||||
|
||||
// float data
|
||||
'float 10.5' => 10.5,
|
||||
'float -10.5' => -10.5,
|
||||
'float 12.3456789000e10' => 12.3456789000e10,
|
||||
'float -12.3456789000e10' => -12.3456789000e10,
|
||||
'float .5' => .5,
|
||||
|
||||
// null data
|
||||
'uppercase NULL' => NULL,
|
||||
'lowercase null' => null,
|
||||
|
||||
// boolean data
|
||||
'lowercase true' => true,
|
||||
'lowercase false' =>false,
|
||||
'uppercase TRUE' =>TRUE,
|
||||
'uppercase FALSE' =>FALSE,
|
||||
|
||||
// empty data
|
||||
'empty string DQ' => "",
|
||||
'empty string SQ' => '',
|
||||
|
||||
// string data
|
||||
'string DQ' => "string",
|
||||
'string SQ' => 'string',
|
||||
'mixed case string' => "sTrInG",
|
||||
'heredoc' => $heredoc,
|
||||
|
||||
// object data
|
||||
'instance of classWithToString' => new classWithToString(),
|
||||
'instance of classWithoutToString' => new classWithoutToString(),
|
||||
|
||||
// undefined data
|
||||
'undefined var' => @$undefined_var,
|
||||
|
||||
// unset data
|
||||
'unset var' => @$unset_var,
|
||||
|
||||
// resource data
|
||||
'resource' => $fp,
|
||||
);
|
||||
|
||||
// loop through each element of the array for arr2
|
||||
|
||||
foreach($inputs as $key =>$value) {
|
||||
echo "\n--$key--\n";
|
||||
var_dump( array_diff_uassoc($array1, $array2, $value, "key_compare_func") );
|
||||
};
|
||||
|
||||
fclose($fp);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
--int 0--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 1--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 12345--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int -12345--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 10.5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -10.5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -12.3456789000e10--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float .5--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase NULL--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase null--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase true--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase false--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase TRUE--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase FALSE--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string DQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string SQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string DQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string SQ--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--mixed case string--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--heredoc--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithToString--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithoutToString--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--undefined var--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--unset var--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--resource--
|
||||
|
||||
Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
40
ext/standard/tests/array/array_diff_uassoc_variation5.phpt
Normal file
40
ext/standard/tests/array/array_diff_uassoc_variation5.phpt
Normal file
@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Comparing integers and floating point numbers
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$arr_default_int = array(1, 2, 3, 4);
|
||||
$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00, 3.00 => 4.00);
|
||||
|
||||
|
||||
function key_compare_func($key1, $key2)
|
||||
{
|
||||
if ($key1 === $key2) {
|
||||
return 0;
|
||||
}
|
||||
return ($key1 > $key2)? 1:-1;
|
||||
}
|
||||
|
||||
echo "\n-- Result of comparing integers and floating point numbers --\n";
|
||||
var_dump( array_diff_uassoc($arr_default_int, $arr_float, "key_compare_func") );
|
||||
var_dump( array_diff_uassoc($arr_float, $arr_default_int, "key_compare_func") );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
-- Result of comparing integers and floating point numbers --
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
===DONE===
|
58
ext/standard/tests/array/array_diff_uassoc_variation6.phpt
Normal file
58
ext/standard/tests/array/array_diff_uassoc_variation6.phpt
Normal file
@ -0,0 +1,58 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Comparing floating points with strings having integers and float
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$arr_float = array(0 => 1.00, 1.00 => 2.00);
|
||||
$arr_string_int = array('1', '2');
|
||||
$arr_string_float = array('0' => '1.00', '1.00' => '2.00');
|
||||
|
||||
function key_compare_func($key1, $key2)
|
||||
{
|
||||
if ($key1 === $key2) {
|
||||
return 0;
|
||||
}
|
||||
return ($key1 > $key2)? 1:-1;
|
||||
}
|
||||
|
||||
echo "\n-- Result of comparing floating points and strings containing integers --\n";
|
||||
var_dump( array_diff_uassoc($arr_float, $arr_string_int, "key_compare_func") );
|
||||
var_dump( array_diff_uassoc($arr_string_int, $arr_float, "key_compare_func") );
|
||||
|
||||
echo "\n-- Result of comparing floating points and strings containing floating point --\n";
|
||||
var_dump( array_diff_uassoc($arr_float, $arr_string_float, "key_compare_func") );
|
||||
var_dump( array_diff_uassoc($arr_string_float, $arr_float, "key_compare_func") );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
-- Result of comparing floating points and strings containing integers --
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
|
||||
-- Result of comparing floating points and strings containing floating point --
|
||||
array(2) {
|
||||
[0]=>
|
||||
float(1)
|
||||
[1]=>
|
||||
float(2)
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(4) "1.00"
|
||||
["1.00"]=>
|
||||
string(4) "2.00"
|
||||
}
|
||||
===DONE===
|
47
ext/standard/tests/array/array_diff_uassoc_variation7.phpt
Normal file
47
ext/standard/tests/array/array_diff_uassoc_variation7.phpt
Normal file
@ -0,0 +1,47 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Comparing strings containing integers and float
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$arr_string_int = array('1', '2');
|
||||
$arr_string_float = array('0' => '1.00', '1.00' => '2.00');
|
||||
|
||||
function key_compare_func($key1, $key2)
|
||||
{
|
||||
if ($key1 === $key2) {
|
||||
return 0;
|
||||
}
|
||||
return ($key1 > $key2)? 1:-1;
|
||||
}
|
||||
|
||||
echo "\n-- Result of comparing strings containing integers and strings containing floating points --\n";
|
||||
var_dump( array_diff_uassoc($arr_string_int, $arr_string_float, "key_compare_func") );
|
||||
var_dump( array_diff_uassoc($arr_string_float, $arr_string_int, "key_compare_func") );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
-- Result of comparing strings containing integers and strings containing floating points --
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "1"
|
||||
[1]=>
|
||||
string(1) "2"
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(4) "1.00"
|
||||
["1.00"]=>
|
||||
string(4) "2.00"
|
||||
}
|
||||
===DONE===
|
62
ext/standard/tests/array/array_diff_uassoc_variation8.phpt
Normal file
62
ext/standard/tests/array/array_diff_uassoc_variation8.phpt
Normal file
@ -0,0 +1,62 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Comparing integers with strings containing integers and float
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
//Initialize variables
|
||||
$arr_default_int = array(1, 2, 3);
|
||||
$arr_string_int = array('1', '2');
|
||||
$arr_string_float = array('0' => '1.00', '1.00' => '2.00');
|
||||
|
||||
function key_compare_func($key1, $key2)
|
||||
{
|
||||
if ($key1 === $key2) {
|
||||
return 0;
|
||||
}
|
||||
return ($key1 > $key2)? 1:-1;
|
||||
}
|
||||
|
||||
echo "\n-- Result of comparing integers and strings containing an integers --\n";
|
||||
var_dump( array_diff_uassoc($arr_default_int, $arr_string_int, "key_compare_func") );
|
||||
var_dump( array_diff_uassoc($arr_string_int, $arr_default_int, "key_compare_func") );
|
||||
|
||||
echo "\n-- Result of comparing integers and strings containing floating points --\n";
|
||||
var_dump( array_diff_uassoc($arr_default_int, $arr_string_float, "key_compare_func") );
|
||||
var_dump( array_diff_uassoc($arr_string_float, $arr_default_int, "key_compare_func") );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
-- Result of comparing integers and strings containing an integers --
|
||||
array(1) {
|
||||
[2]=>
|
||||
int(3)
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
|
||||
-- Result of comparing integers and strings containing floating points --
|
||||
array(3) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(3)
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(4) "1.00"
|
||||
["1.00"]=>
|
||||
string(4) "2.00"
|
||||
}
|
||||
===DONE===
|
62
ext/standard/tests/array/array_diff_uassoc_variation9.phpt
Normal file
62
ext/standard/tests/array/array_diff_uassoc_variation9.phpt
Normal file
@ -0,0 +1,62 @@
|
||||
--TEST--
|
||||
Test array_diff_uassoc() function : usage variation - Passing integer indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
|
||||
* Description: Computes the difference of arrays with additional index check which is performed by a
|
||||
* user supplied callback function
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
|
||||
|
||||
// Initialise function arguments not being substituted (if any)
|
||||
$input_array = array(10 => 10, 12 => 12);
|
||||
|
||||
$input_arrays = array(
|
||||
'decimal indexed' => array(10 => 10, -17 => -17),
|
||||
'octal indexed' => array( 012 => 10, -011 => -011,),
|
||||
'hexa indexed' => array(0xA => 10, -0x7 => -0x7 ),
|
||||
);
|
||||
|
||||
foreach($input_arrays as $key =>$value) {
|
||||
echo "\n--$key--\n";
|
||||
var_dump( array_diff_uassoc($input_array, $value, "strcasecmp") );
|
||||
var_dump( array_diff_uassoc($value, $input_array, "strcasecmp") );
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_uassoc() : usage variation ***
|
||||
|
||||
--decimal indexed--
|
||||
array(1) {
|
||||
[12]=>
|
||||
int(12)
|
||||
}
|
||||
array(1) {
|
||||
[-17]=>
|
||||
int(-17)
|
||||
}
|
||||
|
||||
--octal indexed--
|
||||
array(1) {
|
||||
[12]=>
|
||||
int(12)
|
||||
}
|
||||
array(1) {
|
||||
[-9]=>
|
||||
int(-9)
|
||||
}
|
||||
|
||||
--hexa indexed--
|
||||
array(1) {
|
||||
[12]=>
|
||||
int(12)
|
||||
}
|
||||
array(1) {
|
||||
[-7]=>
|
||||
int(-7)
|
||||
}
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user