Annotation of embedaddon/php/ext/standard/tests/strings/sprintf_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test sprintf() function : usage variations - int formats with int values
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 integer values ***\n";
11:
12: // different valid integer vlaues
13: $valid_ints = array(
14: 0,
15: 1,
16: -1,
17: -2147483648, // max negative integer value
18: -2147483647,
19: 2147483647, // max positive integer value
20: 2147483640,
21: 0x123B, // integer as hexadecimal
22: 0x12ab,
23: 0Xfff,
24: 0XFA,
25: -0x80000000, // max negative integer as hexadecimal
26: 0x7fffffff, // max postive integer as hexadecimal
27: 0x7FFFFFFF, // max postive integer as hexadecimal
28: 0123, // integer as octal
29: 01912, // should be quivalent to octal 1
30: -020000000000, // max negative integer as octal
31: 017777777777 // max positive integer as octal
32: );
33: // various integer formats
34: $int_formats = array(
35: "%d", "%hd", "%ld",
36: "%Ld", " %d", "%d ",
37: "\t%d", "\n%d", "%4d",
38: "%30d", "%[0-9]", "%*d"
39: );
40:
41: $count = 1;
42: foreach($valid_ints as $int_value) {
43: echo "\n-- Iteration $count --\n";
44:
45: foreach($int_formats as $format) {
46: var_dump( sprintf($format, $int_value) );
47: }
48: $count++;
49: };
50:
51: echo "Done";
52: ?>
53: --EXPECTF--
54: *** Testing sprintf() : integer formats with integer values ***
55:
56: -- Iteration 1 --
57: string(1) "0"
58: string(1) "d"
59: string(1) "0"
60: string(1) "d"
61: string(2) " 0"
62: string(2) "0 "
63: string(2) " 0"
64: string(2) "
65: 0"
66: string(4) " 0"
67: string(30) " 0"
68: string(4) "0-9]"
69: string(1) "d"
70:
71: -- Iteration 2 --
72: string(1) "1"
73: string(1) "d"
74: string(1) "1"
75: string(1) "d"
76: string(2) " 1"
77: string(2) "1 "
78: string(2) " 1"
79: string(2) "
80: 1"
81: string(4) " 1"
82: string(30) " 1"
83: string(4) "0-9]"
84: string(1) "d"
85:
86: -- Iteration 3 --
87: string(2) "-1"
88: string(1) "d"
89: string(2) "-1"
90: string(1) "d"
91: string(3) " -1"
92: string(3) "-1 "
93: string(3) " -1"
94: string(3) "
95: -1"
96: string(4) " -1"
97: string(30) " -1"
98: string(4) "0-9]"
99: string(1) "d"
100:
101: -- Iteration 4 --
102: string(11) "-2147483648"
103: string(1) "d"
104: string(11) "-2147483648"
105: string(1) "d"
106: string(12) " -2147483648"
107: string(12) "-2147483648 "
108: string(12) " -2147483648"
109: string(12) "
110: -2147483648"
111: string(11) "-2147483648"
112: string(30) " -2147483648"
113: string(4) "0-9]"
114: string(1) "d"
115:
116: -- Iteration 5 --
117: string(11) "-2147483647"
118: string(1) "d"
119: string(11) "-2147483647"
120: string(1) "d"
121: string(12) " -2147483647"
122: string(12) "-2147483647 "
123: string(12) " -2147483647"
124: string(12) "
125: -2147483647"
126: string(11) "-2147483647"
127: string(30) " -2147483647"
128: string(4) "0-9]"
129: string(1) "d"
130:
131: -- Iteration 6 --
132: string(10) "2147483647"
133: string(1) "d"
134: string(10) "2147483647"
135: string(1) "d"
136: string(11) " 2147483647"
137: string(11) "2147483647 "
138: string(11) " 2147483647"
139: string(11) "
140: 2147483647"
141: string(10) "2147483647"
142: string(30) " 2147483647"
143: string(4) "0-9]"
144: string(1) "d"
145:
146: -- Iteration 7 --
147: string(10) "2147483640"
148: string(1) "d"
149: string(10) "2147483640"
150: string(1) "d"
151: string(11) " 2147483640"
152: string(11) "2147483640 "
153: string(11) " 2147483640"
154: string(11) "
155: 2147483640"
156: string(10) "2147483640"
157: string(30) " 2147483640"
158: string(4) "0-9]"
159: string(1) "d"
160:
161: -- Iteration 8 --
162: string(4) "4667"
163: string(1) "d"
164: string(4) "4667"
165: string(1) "d"
166: string(5) " 4667"
167: string(5) "4667 "
168: string(5) " 4667"
169: string(5) "
170: 4667"
171: string(4) "4667"
172: string(30) " 4667"
173: string(4) "0-9]"
174: string(1) "d"
175:
176: -- Iteration 9 --
177: string(4) "4779"
178: string(1) "d"
179: string(4) "4779"
180: string(1) "d"
181: string(5) " 4779"
182: string(5) "4779 "
183: string(5) " 4779"
184: string(5) "
185: 4779"
186: string(4) "4779"
187: string(30) " 4779"
188: string(4) "0-9]"
189: string(1) "d"
190:
191: -- Iteration 10 --
192: string(4) "4095"
193: string(1) "d"
194: string(4) "4095"
195: string(1) "d"
196: string(5) " 4095"
197: string(5) "4095 "
198: string(5) " 4095"
199: string(5) "
200: 4095"
201: string(4) "4095"
202: string(30) " 4095"
203: string(4) "0-9]"
204: string(1) "d"
205:
206: -- Iteration 11 --
207: string(3) "250"
208: string(1) "d"
209: string(3) "250"
210: string(1) "d"
211: string(4) " 250"
212: string(4) "250 "
213: string(4) " 250"
214: string(4) "
215: 250"
216: string(4) " 250"
217: string(30) " 250"
218: string(4) "0-9]"
219: string(1) "d"
220:
221: -- Iteration 12 --
222: string(11) "-2147483648"
223: string(1) "d"
224: string(11) "-2147483648"
225: string(1) "d"
226: string(12) " -2147483648"
227: string(12) "-2147483648 "
228: string(12) " -2147483648"
229: string(12) "
230: -2147483648"
231: string(11) "-2147483648"
232: string(30) " -2147483648"
233: string(4) "0-9]"
234: string(1) "d"
235:
236: -- Iteration 13 --
237: string(10) "2147483647"
238: string(1) "d"
239: string(10) "2147483647"
240: string(1) "d"
241: string(11) " 2147483647"
242: string(11) "2147483647 "
243: string(11) " 2147483647"
244: string(11) "
245: 2147483647"
246: string(10) "2147483647"
247: string(30) " 2147483647"
248: string(4) "0-9]"
249: string(1) "d"
250:
251: -- Iteration 14 --
252: string(10) "2147483647"
253: string(1) "d"
254: string(10) "2147483647"
255: string(1) "d"
256: string(11) " 2147483647"
257: string(11) "2147483647 "
258: string(11) " 2147483647"
259: string(11) "
260: 2147483647"
261: string(10) "2147483647"
262: string(30) " 2147483647"
263: string(4) "0-9]"
264: string(1) "d"
265:
266: -- Iteration 15 --
267: string(2) "83"
268: string(1) "d"
269: string(2) "83"
270: string(1) "d"
271: string(3) " 83"
272: string(3) "83 "
273: string(3) " 83"
274: string(3) "
275: 83"
276: string(4) " 83"
277: string(30) " 83"
278: string(4) "0-9]"
279: string(1) "d"
280:
281: -- Iteration 16 --
282: string(1) "1"
283: string(1) "d"
284: string(1) "1"
285: string(1) "d"
286: string(2) " 1"
287: string(2) "1 "
288: string(2) " 1"
289: string(2) "
290: 1"
291: string(4) " 1"
292: string(30) " 1"
293: string(4) "0-9]"
294: string(1) "d"
295:
296: -- Iteration 17 --
297: string(11) "-2147483648"
298: string(1) "d"
299: string(11) "-2147483648"
300: string(1) "d"
301: string(12) " -2147483648"
302: string(12) "-2147483648 "
303: string(12) " -2147483648"
304: string(12) "
305: -2147483648"
306: string(11) "-2147483648"
307: string(30) " -2147483648"
308: string(4) "0-9]"
309: string(1) "d"
310:
311: -- Iteration 18 --
312: string(10) "2147483647"
313: string(1) "d"
314: string(10) "2147483647"
315: string(1) "d"
316: string(11) " 2147483647"
317: string(11) "2147483647 "
318: string(11) " 2147483647"
319: string(11) "
320: 2147483647"
321: string(10) "2147483647"
322: string(30) " 2147483647"
323: string(4) "0-9]"
324: string(1) "d"
325: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>