Annotation of embedaddon/php/ext/standard/tests/strings/vsprintf_variation10.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test vsprintf() function : usage variations - char formats with non-char values
3: --FILE--
4: <?php
5: /* Prototype : string vsprintf(string format, array args)
6: * Description: Return a formatted string
7: * Source code: ext/standard/formatted_print.c
8: */
9:
10: /*
11: * Test vsprintf() when different char formats and non-char values are passed to
12: * the '$format' and '$args' arguments of the function
13: */
14:
15: echo "*** Testing vsprintf() : char formats and non-char values ***\n";
16:
17: // defining an array of various char formats
18: $formats =
19: '%c %+c %-c
20: %lc %Lc %4c %-4c
21: %10.4c %-10.4c %04c %04.4c
22: %\'10c %\'10c %\'$10c %\'_10c
23: %3$c %4$c %1$c %2$c';
24:
25: // Arrays of non char values for the format defined in $format.
26: // Each sub array contains non char values which correspond to each format in $format
27: $args_array = array(
28:
29: // array of float values
30: array(65.8, -65.8, +66.8,
31: 93.2, -93.2, 126.8, -126.49,
32: 35.44, -35.68, 32.99, -32.00,
33: -61.51, 61.51, 50.49, -54.50,
34: 83.33, +84.44, 81.11, 82.22),
35:
36: // array of int values
37: array(65, -65, +66,
38: 169, -169, 126, -126,
39: 35, -35, 32, -32,
40: -61, 61, 50, -54,
41: 83, +84, 81, 82),
42:
43: // array of strings
44: array(" ", ' ', 'hello',
45: '123hello', "123hello", '-123hello', '+123hello',
46: "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
47: "1234hello", "hello\0world", "NULL", "true",
48: "3", "4", '1', '2'),
49:
50: // different arrays
51: array( array(0), array(1, 2), array(-1, -1),
52: array("123"), array('123'), array('-123'), array("-123"),
53: array(true), array(false), array(TRUE), array(FALSE),
54: array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
55: array("3"), array("4"), array("1"), array("2") ),
56:
57: // array of boolean data
58: array( true, TRUE, false,
59: TRUE, 0, FALSE, 1,
60: true, false, TRUE, FALSE,
61: 0, 1, 1, 0,
62: 1, TRUE, 0, FALSE),
63:
64: );
65:
66: // looping to test vsprintf() with different char formats from the above $format array
67: // and with non-char values from the above $args_array array
68: $counter = 1;
69: foreach($args_array as $args) {
70: echo "\n-- Iteration $counter --\n";
71: var_dump( vsprintf($formats, $args) );
72: $counter++;
73: }
74:
75: echo "Done";
76: ?>
77: --EXPECTF--
78: *** Testing vsprintf() : char formats and non-char values ***
79:
80: -- Iteration 1 --
81: string(50) "A ¿ B
82: ] c ~ ‚
83: # Ý à
84: Ã = 2 Ê
85: B ] A ¿"
86:
87: -- Iteration 2 --
88: string(50) "A ¿ B
89: © c ~ ‚
90: # Ý à
91: Ã = 2 Ê
92: B © A ¿"
93:
94: -- Iteration 3 --
95: string(50) "