mirror of
https://github.com/php/php-src.git
synced 2025-01-08 20:17:28 +08:00
366 lines
5.7 KiB
PHP
366 lines
5.7 KiB
PHP
--TEST--
|
|
Test sprintf() function : usage variations - unsigned formats with string values
|
|
--SKIPIF--
|
|
<?php
|
|
if (PHP_INT_SIZE != 4) {
|
|
die("skip this test is for 32bit platform only");
|
|
}
|
|
?>
|
|
--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() : unsigned formats with string values ***\n";
|
|
|
|
// array of string values
|
|
$string_values = array(
|
|
"",
|
|
'',
|
|
"0",
|
|
'0',
|
|
"1",
|
|
'1',
|
|
"-123",
|
|
"+123",
|
|
"\x01",
|
|
'\x01',
|
|
"\01",
|
|
'\01',
|
|
'string',
|
|
"string",
|
|
"true",
|
|
"FALSE",
|
|
'false',
|
|
'TRUE',
|
|
"NULL",
|
|
'null'
|
|
);
|
|
|
|
// array of unsigned formats
|
|
$unsigned_formats = array(
|
|
"%u", "%hu", "%lu",
|
|
"%Lu", " %u", "%u ",
|
|
"\t%u", "\n%u", "%4u",
|
|
"%30u", "%[0-9]", "%*u"
|
|
);
|
|
|
|
|
|
$count = 1;
|
|
foreach($string_values as $string_value) {
|
|
echo "\n-- Iteration $count --\n";
|
|
|
|
foreach($unsigned_formats as $format) {
|
|
var_dump( sprintf($format, $string_value) );
|
|
}
|
|
$count++;
|
|
};
|
|
|
|
echo "Done";
|
|
?>
|
|
--EXPECTF--
|
|
*** Testing sprintf() : unsigned formats with string values ***
|
|
|
|
-- Iteration 1 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 2 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 3 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 4 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 5 --
|
|
string(1) "1"
|
|
string(1) "u"
|
|
string(1) "1"
|
|
string(1) "u"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 6 --
|
|
string(1) "1"
|
|
string(1) "u"
|
|
string(1) "1"
|
|
string(1) "u"
|
|
string(2) " 1"
|
|
string(2) "1 "
|
|
string(2) " 1"
|
|
string(2) "
|
|
1"
|
|
string(4) " 1"
|
|
string(30) " 1"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 7 --
|
|
string(10) "4294967173"
|
|
string(1) "u"
|
|
string(10) "4294967173"
|
|
string(1) "u"
|
|
string(11) " 4294967173"
|
|
string(11) "4294967173 "
|
|
string(11) " 4294967173"
|
|
string(11) "
|
|
4294967173"
|
|
string(10) "4294967173"
|
|
string(30) " 4294967173"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 8 --
|
|
string(3) "123"
|
|
string(1) "u"
|
|
string(3) "123"
|
|
string(1) "u"
|
|
string(4) " 123"
|
|
string(4) "123 "
|
|
string(4) " 123"
|
|
string(4) "
|
|
123"
|
|
string(4) " 123"
|
|
string(30) " 123"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 9 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 10 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 11 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 12 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 13 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 14 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 15 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 16 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 17 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 18 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 19 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
|
|
-- Iteration 20 --
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(1) "0"
|
|
string(1) "u"
|
|
string(2) " 0"
|
|
string(2) "0 "
|
|
string(2) " 0"
|
|
string(2) "
|
|
0"
|
|
string(4) " 0"
|
|
string(30) " 0"
|
|
string(4) "0-9]"
|
|
string(1) "u"
|
|
Done
|