Annotation of embedaddon/php/ext/standard/tests/strings/sprintf_variation6.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test sprintf() function : usage variations - int formats with arrays
3: --FILE--
4: <?php
5: /* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
6: * Description: Return a formatted string
7: * Source code: ext/standard/formatted_print.c
8: */
9:
10: echo "*** Testing sprintf() : integer formats with arrays ***\n";
11:
12: // different arrays used to test the function
13: $array_types = array (
14: array(),
15: array(0),
16: array(1),
17: array(-123),
18: array("123"),
19: array("-123"),
20: array(NULL),
21: array(null),
22: array("string"),
23: array(true),
24: array(TRUE),
25: array(false),
26: array(FALSE),
27: array(1,2,3,4),
28: array(1 => "One", "two" => 2)
29: );
30:
31: // various integer formats
32: $int_formats = array(
33: "%d", "%hd", "%ld",
34: "%Ld", " %d", "%d ",
35: "\t%d", "\n%d", "%4d",
36: "%30d", "%[0-9]", "%*d"
37: );
38:
39: $count = 1;
40: foreach($array_types as $arr) {
41: echo "\n-- Iteration $count --\n";
42:
43: foreach($int_formats as $format) {
44: var_dump( sprintf($format, $arr) );
45: }
46: $count++;
47: };
48:
49: echo "Done";
50: ?>
51: --EXPECTF--
52: *** Testing sprintf() : integer formats with arrays ***
53:
54: -- Iteration 1 --
55: string(1) "0"
56: string(1) "d"
57: string(1) "0"
58: string(1) "d"
59: string(2) " 0"
60: string(2) "0 "
61: string(2) " 0"
62: string(2) "
63: 0"
64: string(4) " 0"
65: string(30) " 0"
66: string(4) "0-9]"
67: string(1) "d"
68:
69: -- Iteration 2 --
70: string(1) "1"
71: string(1) "d"
72: string(1) "1"
73: string(1) "d"
74: string(2) " 1"
75: string(2) "1 "
76: string(2) " 1"
77: string(2) "
78: 1"
79: string(4) " 1"
80: string(30) " 1"
81: string(4) "0-9]"
82: string(1) "d"
83:
84: -- Iteration 3 --
85: string(1) "1"
86: string(1) "d"
87: string(1) "1"
88: string(1) "d"
89: string(2) " 1"
90: string(2) "1 "
91: string(2) " 1"
92: string(2) "
93: 1"
94: string(4) " 1"
95: string(30) " 1"
96: string(4) "0-9]"
97: string(1) "d"
98:
99: -- Iteration 4 --
100: string(1) "1"
101: string(1) "d"
102: string(1) "1"
103: string(1) "d"
104: string(2) " 1"
105: string(2) "1 "
106: string(2) " 1"
107: string(2) "
108: 1"
109: string(4) " 1"
110: string(30) " 1"
111: string(4) "0-9]"
112: string(1) "d"
113:
114: -- Iteration 5 --
115: string(1) "1"
116: string(1) "d"
117: string(1) "1"
118: string(1) "d"
119: string(2) " 1"
120: string(2) "1 "
121: string(2) " 1"
122: string(2) "
123: 1"
124: string(4) " 1"
125: string(30) " 1"
126: string(4) "0-9]"
127: string(1) "d"
128:
129: -- Iteration 6 --
130: string(1) "1"
131: string(1) "d"
132: string(1) "1"
133: string(1) "d"
134: string(2) " 1"
135: string(2) "1 "
136: string(2) " 1"
137: string(2) "
138: 1"
139: string(4) " 1"
140: string(30) " 1"
141: string(4) "0-9]"
142: string(1) "d"
143:
144: -- Iteration 7 --
145: string(1) "1"
146: string(1) "d"
147: string(1) "1"
148: string(1) "d"
149: string(2) " 1"
150: string(2) "1 "
151: string(2) " 1"
152: string(2) "
153: 1"
154: string(4) " 1"
155: string(30) " 1"
156: string(4) "0-9]"
157: string(1) "d"
158:
159: -- Iteration 8 --
160: string(1) "1"
161: string(1) "d"
162: string(1) "1"
163: string(1) "d"
164: string(2) " 1"
165: string(2) "1 "
166: string(2) " 1"
167: string(2) "
168: 1"
169: string(4) " 1"
170: string(30) " 1"
171: string(4) "0-9]"
172: string(1) "d"
173:
174: -- Iteration 9 --
175: string(1) "1"
176: string(1) "d"
177: string(1) "1"
178: string(1) "d"
179: string(2) " 1"
180: string(2) "1 "
181: string(2) " 1"
182: string(2) "
183: 1"
184: string(4) " 1"
185: string(30) " 1"
186: string(4) "0-9]"
187: string(1) "d"
188:
189: -- Iteration 10 --
190: string(1) "1"
191: string(1) "d"
192: string(1) "1"
193: string(1) "d"
194: string(2) " 1"
195: string(2) "1 "
196: string(2) " 1"
197: string(2) "
198: 1"
199: string(4) " 1"
200: string(30) " 1"
201: string(4) "0-9]"
202: string(1) "d"
203:
204: -- Iteration 11 --
205: string(1) "1"
206: string(1) "d"
207: string(1) "1"
208: string(1) "d"
209: string(2) " 1"
210: string(2) "1 "
211: string(2) " 1"
212: string(2) "
213: 1"
214: string(4) " 1"
215: string(30) " 1"
216: string(4) "0-9]"
217: string(1) "d"
218:
219: -- Iteration 12 --
220: string(1) "1"
221: string(1) "d"
222: string(1) "1"
223: string(1) "d"
224: string(2) " 1"
225: string(2) "1 "
226: string(2) " 1"
227: string(2) "
228: 1"
229: string(4) " 1"
230: string(30) " 1"
231: string(4) "0-9]"
232: string(1) "d"
233:
234: -- Iteration 13 --
235: string(1) "1"
236: string(1) "d"
237: string(1) "1"
238: string(1) "d"
239: string(2) " 1"
240: string(2) "1 "
241: string(2) " 1"
242: string(2) "
243: 1"
244: string(4) " 1"
245: string(30) " 1"
246: string(4) "0-9]"
247: string(1) "d"
248:
249: -- Iteration 14 --
250: string(1) "1"
251: string(1) "d"
252: string(1) "1"
253: string(1) "d"
254: string(2) " 1"
255: string(2) "1 "
256: string(2) " 1"
257: string(2) "
258: 1"
259: string(4) " 1"
260: string(30) " 1"
261: string(4) "0-9]"
262: string(1) "d"
263:
264: -- Iteration 15 --
265: string(1) "1"
266: string(1) "d"
267: string(1) "1"
268: string(1) "d"
269: string(2) " 1"
270: string(2) "1 "
271: string(2) " 1"
272: string(2) "
273: 1"
274: string(4) " 1"
275: string(30) " 1"
276: string(4) "0-9]"
277: string(1) "d"
278: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>