1
0
mirror of https://github.com/php/php-src.git synced 2026-04-12 18:43:37 +02:00
Files
archived-php-src/ext/standard/tests/strings/vsprintf_variation8.phpt
Peter Kokot b746e69887 Sync leading and final newlines in *.phpt sections
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
2018-10-15 04:32:30 +02:00

104 lines
2.8 KiB
PHP

--TEST--
Test vsprintf() function : usage variations - string formats with non-string values
--FILE--
<?php
/* Prototype : string vsprintf(string format, array args)
* Description: Return a formatted string
* Source code: ext/standard/formatted_print.c
*/
/*
* Test vsprintf() when different string formats and non-string values are passed to
* the '$format' and '$args' arguments of the function
*/
error_reporting(E_ALL & ~E_NOTICE);
echo "*** Testing vsprintf() : string formats and non-string values ***\n";
// defining array of string formats
$formats =
'%s %+s %-s
%ls %4s %-4s
%10.4s %-10.4s %04s %04.4s
%\'#2s %\'2s %\'$2s %\'_2s
%3$s %4$s %1$s %2$s';
// Arrays of non string values for the format defined in $format.
// Each sub array contains non string values which correspond to each format in $format
$args_array = array(
// array of float values
array(2.2, .2, 10.2,
123456.234, -1234.6789, +1234.6789,
2.1234567e10, +2.7654321e10, -2.7654321e10, 2.1234567e10,
12345.780, 12.000000011111, -12.00000111111, -123456.234,
3.33, +4.44, 1.11,-2.22 ),
// array of int values
array(2, -2, +2,
123456, -12346789, +12346789,
123200, +20000, -40000, 22212,
12345780, 1211111, -12111111, -12345634,
3, +4, 1,-2 ),
// different arrays
array( array(0), array(1, 2), array(-1, -1),
array("123"), array('-123'), array("-123"),
array(true), array(false), array(TRUE), array(FALSE),
array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
array("3"), array("4"), array("1"), array("2") ),
// array of boolean data
array( true, TRUE, false,
TRUE, FALSE, 1,
true, false, TRUE, FALSE,
0, 1, 1, 0,
1, TRUE, 0, FALSE),
);
// looping to test vsprintf() with different string formats from the above $format array
// and with non-string values from the above $args_array array
$counter = 1;
foreach($args_array as $args) {
echo "\n-- Iteration $counter --\n";
var_dump( vsprintf($formats, $args) );
$counter++;
}
?>
===DONE===
--EXPECT--
*** Testing vsprintf() : string formats and non-string values ***
-- Iteration 1 --
string(174) "2.2 0.2 10.2
123456.234 -1234.6789 1234.6789
2123 2765 -27654321000 2123
12345.78 12.000000011111 -12.00000111111 -123456.234
10.2 123456.234 2.2 0.2"
-- Iteration 2 --
string(130) "2 -2 2
123456 -12346789 12346789
1232 2000 -40000 2221
12345780 1211111 -12111111 -12345634
2 123456 2 -2"
-- Iteration 3 --
string(129) "Array Array Array
Array Array Array
Arra Arra Array Arra
Array Array Array Array
Array Array Array Array"
-- Iteration 4 --
string(79) "1 1
1 1
1 0001 0000
#0 1 $1 _0
1 1 1"
===DONE===