mirror of
https://github.com/php/php-src.git
synced 2025-01-08 20:17:28 +08:00
278 lines
4.4 KiB
PHP
278 lines
4.4 KiB
PHP
--TEST--
|
|
Test sprintf() function : usage variations - int formats with arrays
|
|
--FILE--
|
|
<?php
|
|
/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
|
|
* Description: Return a formatted string
|
|
* Source code: ext/standard/formatted_print.c
|
|
*/
|
|
|
|
echo "*** Testing sprintf() : integer formats with arrays ***\n";
|
|
|
|
// different arrays used to test the function
|
|
$array_types = array (
|
|
array(),
|
|
array(0),
|
|
array(1),
|
|
array(-123),
|
|
array("123"),
|
|
array("-123"),
|
|
array(NULL),
|
|
array(null),
|
|
array("string"),
|
|
array(true),
|
|
array(TRUE),
|
|
array(false),
|
|
array(FALSE),
|
|
array(1,2,3,4),
|
|
array(1 => "One", "two" => 2)
|
|
);
|
|
|
|
// various integer formats
|
|
$int_formats = array(
|
|
"%d", "%hd", "%ld",
|
|
"%Ld", " %d", "%d ",
|
|
"\t%d", "\n%d", "%4d",
|
|
"%30d", "%[0-9]", "%*d"
|
|
);
|
|
|
|
$count = 1;
|
|
foreach($array_types as $arr) {
|
|
echo "\n-- Iteration $count --\n";
|
|
|
|
foreach($int_formats as $format) {
|
|
var_dump( sprintf($format, $arr) );
|
|
}
|
|
$count++;
|
|
};
|
|
|
|
echo "Done";
|
|
?>
|
|
--EXPECTF--
|
|
*** Testing sprintf() : integer formats with arrays ***
|
|
|
|
-- Iteration 1 --
|
|
string(1) "0"
|
|
string(1) "d"
|
|
string(1) "0"
|
|
string(1) "d"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 2 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 3 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 4 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 5 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 6 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 7 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 8 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 9 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 10 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 11 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 12 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 13 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 14 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
|
|
-- Iteration 15 --
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(1) "1"
|
|
string(1) "d"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "d"
|
|
Done
|