mirror of
https://github.com/php/php-src.git
synced 2026-03-30 20:22:36 +02:00
This patch adds missing newlines, trims multiple redundant final newlines into a single one, and trims redundant leading newlines in all *.phpt sections. According to POSIX, a line is a sequence of zero or more non-' <newline>' characters plus a terminating '<newline>' character. [1] Files should normally have at least one final newline character. C89 [2] and later standards [3] mention a final newline: "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character." Although it is not mandatory for all files to have a final newline fixed, a more consistent and homogeneous approach brings less of commit differences issues and a better development experience in certain text editors and IDEs. [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 [2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2 [3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
428 lines
7.2 KiB
PHP
428 lines
7.2 KiB
PHP
--TEST--
|
||
Test sprintf() function : usage variations - string formats with string values
|
||
--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() : string formats with string values ***\n";
|
||
|
||
// defining different heredoc strings
|
||
/* string created using Heredoc (<<<) */
|
||
$heredoc_string = <<<EOT
|
||
This is string defined
|
||
using heredoc.
|
||
EOT;
|
||
|
||
/* heredoc string with only numerics */
|
||
$heredoc_numeric_string = <<<EOT
|
||
123456 3993
|
||
4849 string
|
||
EOT;
|
||
|
||
/* null heardoc string */
|
||
$heredoc_empty_string = <<<EOT
|
||
EOT;
|
||
$heredoc_null_string = <<<EOT
|
||
NULL
|
||
EOT;
|
||
|
||
// array of strings used to test the function
|
||
$string_values = array(
|
||
"",
|
||
" ",
|
||
'',
|
||
' ',
|
||
"string",
|
||
'string',
|
||
"NULL",
|
||
'null',
|
||
"FALSE",
|
||
'true',
|
||
"\x0b",
|
||
"\0",
|
||
'\0',
|
||
'\060',
|
||
"\070",
|
||
"0x55F",
|
||
"055",
|
||
"@#$#$%%$^^$%^%^$^&",
|
||
$heredoc_string,
|
||
$heredoc_numeric_string,
|
||
$heredoc_empty_string,
|
||
$heredoc_null_string
|
||
);
|
||
|
||
// array of string formats
|
||
$string_formats = array(
|
||
"%s", "%hs", "%ls",
|
||
"%Ls"," %s", "%s ",
|
||
"\t%s", "\n%s", "%4s",
|
||
"%30s", "%[a-zA-Z0-9]", "%*s"
|
||
);
|
||
|
||
$count = 1;
|
||
foreach($string_values as $string_value) {
|
||
echo "\n-- Iteration $count --\n";
|
||
|
||
foreach($string_formats as $format) {
|
||
var_dump( sprintf($format, $string_value) );
|
||
}
|
||
$count++;
|
||
};
|
||
|
||
echo "Done";
|
||
?>
|
||
--EXPECT--
|
||
*** Testing sprintf() : string formats with string values ***
|
||
|
||
-- Iteration 1 --
|
||
string(0) ""
|
||
string(1) "s"
|
||
string(0) ""
|
||
string(1) "s"
|
||
string(1) " "
|
||
string(1) " "
|
||
string(1) " "
|
||
string(1) "
|
||
"
|
||
string(4) " "
|
||
string(30) " "
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 2 --
|
||
string(1) " "
|
||
string(1) "s"
|
||
string(1) " "
|
||
string(1) "s"
|
||
string(2) " "
|
||
string(2) " "
|
||
string(2) " "
|
||
string(2) "
|
||
"
|
||
string(4) " "
|
||
string(30) " "
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 3 --
|
||
string(0) ""
|
||
string(1) "s"
|
||
string(0) ""
|
||
string(1) "s"
|
||
string(1) " "
|
||
string(1) " "
|
||
string(1) " "
|
||
string(1) "
|
||
"
|
||
string(4) " "
|
||
string(30) " "
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 4 --
|
||
string(1) " "
|
||
string(1) "s"
|
||
string(1) " "
|
||
string(1) "s"
|
||
string(2) " "
|
||
string(2) " "
|
||
string(2) " "
|
||
string(2) "
|
||
"
|
||
string(4) " "
|
||
string(30) " "
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 5 --
|
||
string(6) "string"
|
||
string(1) "s"
|
||
string(6) "string"
|
||
string(1) "s"
|
||
string(7) " string"
|
||
string(7) "string "
|
||
string(7) " string"
|
||
string(7) "
|
||
string"
|
||
string(6) "string"
|
||
string(30) " string"
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 6 --
|
||
string(6) "string"
|
||
string(1) "s"
|
||
string(6) "string"
|
||
string(1) "s"
|
||
string(7) " string"
|
||
string(7) "string "
|
||
string(7) " string"
|
||
string(7) "
|
||
string"
|
||
string(6) "string"
|
||
string(30) " string"
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 7 --
|
||
string(4) "NULL"
|
||
string(1) "s"
|
||
string(4) "NULL"
|
||
string(1) "s"
|
||
string(5) " NULL"
|
||
string(5) "NULL "
|
||
string(5) " NULL"
|
||
string(5) "
|
||
NULL"
|
||
string(4) "NULL"
|
||
string(30) " NULL"
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 8 --
|
||
string(4) "null"
|
||
string(1) "s"
|
||
string(4) "null"
|
||
string(1) "s"
|
||
string(5) " null"
|
||
string(5) "null "
|
||
string(5) " null"
|
||
string(5) "
|
||
null"
|
||
string(4) "null"
|
||
string(30) " null"
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 9 --
|
||
string(5) "FALSE"
|
||
string(1) "s"
|
||
string(5) "FALSE"
|
||
string(1) "s"
|
||
string(6) " FALSE"
|
||
string(6) "FALSE "
|
||
string(6) " FALSE"
|
||
string(6) "
|
||
FALSE"
|
||
string(5) "FALSE"
|
||
string(30) " FALSE"
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 10 --
|
||
string(4) "true"
|
||
string(1) "s"
|
||
string(4) "true"
|
||
string(1) "s"
|
||
string(5) " true"
|
||
string(5) "true "
|
||
string(5) " true"
|
||
string(5) "
|
||
true"
|
||
string(4) "true"
|
||
string(30) " true"
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 11 --
|
||
string(1) ""
|
||
string(1) "s"
|
||
string(1) ""
|
||
string(1) "s"
|
||
string(2) " "
|
||
string(2) " "
|
||
string(2) " "
|
||
string(2) "
|
||
"
|
||
string(4) " "
|
||
string(30) " "
|
||
string(10) "a-zA-Z0-9]"
|
||
string(1) "s"
|
||
|
||
-- Iteration 12 --
|
||
string(1) " |