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