Annotation of embedaddon/php/ext/standard/tests/strings/str_repeat.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test str_repeat() function
3: --INI--
4: precision=14
5: --FILE--
6: <?php
7: /* Prototype: string str_repeat ( string $input, int $multiplier );
8: Description: Returns input repeated multiplier times. multiplier has to be
9: greater than or equal to 0. If the multiplier is set to 0, the function
10: will return an empty string.
11: */
12:
13: echo "*** Testing str_repeat() with possible strings ***";
14: $variations = array(
15: 'a',
16: 'foo',
17: 'barbazbax',
18: "\x00",
19: '\0',
20: NULL,
21: TRUE,
22: 4,
23: 1.23,
24: "",
25: " "
26: );
27:
28: /* variations in string and multiplier as an integer */
29: foreach($variations as $input) {
30: echo "\n--- str_repeat() of '$input' ---\n" ;
31: for($n=0; $n<4; $n++) {
32: echo "-- after repeating $n times is => ";
33: echo str_repeat($input, $n)."\n";
34: }
35: }
36:
37: /* variations in multiplier as well as string to be repeated. Same varient
38: values are used as string to be repeated as well as multiplier */
39: echo "\n\n*** Testing str_repeat() with various strings & multiplier value ***";
40: foreach ( $variations as $input ) {
41: echo "\n--- str_repeat() of '$input' ---\n" ;
42: foreach ( $variations as $multiplier ) {
43: echo "-- after repeating '$multiplier' times is => ";
44: var_dump( str_repeat($input, $multiplier) );
45: }
46: }
47:
48:
49: echo "\n*** Testing str_repeat() with complex strings containing
50: other than 7-bit chars ***\n";
51: $str = chr(0).chr(128).chr(129).chr(234).chr(235).chr(254).chr(255);
52: var_dump(str_repeat($str, chr(51))); // ASCII value of '3' given
53: var_dump(str_repeat($str, 3));
54:
55:
56: echo "\n\n*** Testing error conditions ***";
57: var_dump( str_repeat() ); // Zero args
58: var_dump( str_repeat($input[0]) ); // args < expected
59: var_dump( str_repeat($input[0], 3, 4) ); // args > expected
60: var_dump( str_repeat($input[0], -1) ); // Invalid arg for multiplier
61:
62: echo "Done\n";
63: ?>
64: --EXPECTF--
65: *** Testing str_repeat() with possible strings ***
66: --- str_repeat() of 'a' ---
67: -- after repeating 0 times is =>
68: -- after repeating 1 times is => a
69: -- after repeating 2 times is => aa
70: -- after repeating 3 times is => aaa
71:
72: --- str_repeat() of 'foo' ---
73: -- after repeating 0 times is =>
74: -- after repeating 1 times is => foo
75: -- after repeating 2 times is => foofoo
76: -- after repeating 3 times is => foofoofoo
77:
78: --- str_repeat() of 'barbazbax' ---
79: -- after repeating 0 times is =>
80: -- after repeating 1 times is => barbazbax
81: -- after repeating 2 times is => barbazbaxbarbazbax
82: -- after repeating 3 times is => barbazbaxbarbazbaxbarbazbax
83:
84: --- str_repeat() of ' ' ---
85: -- after repeating 0 times is =>
86: -- after repeating 1 times is =>
87: -- after repeating 2 times is =>
88: -- after repeating 3 times is =>
89:
90: --- str_repeat() of '\0' ---
91: -- after repeating 0 times is =>
92: -- after repeating 1 times is => \0
93: -- after repeating 2 times is => \0\0
94: -- after repeating 3 times is => \0\0\0
95:
96: --- str_repeat() of '' ---
97: -- after repeating 0 times is =>
98: -- after repeating 1 times is =>
99: -- after repeating 2 times is =>
100: -- after repeating 3 times is =>
101:
102: --- str_repeat() of '1' ---
103: -- after repeating 0 times is =>
104: -- after repeating 1 times is => 1
105: -- after repeating 2 times is => 11
106: -- after repeating 3 times is => 111
107:
108: --- str_repeat() of '4' ---
109: -- after repeating 0 times is =>
110: -- after repeating 1 times is => 4
111: -- after repeating 2 times is => 44
112: -- after repeating 3 times is => 444
113:
114: --- str_repeat() of '1.23' ---
115: -- after repeating 0 times is =>
116: -- after repeating 1 times is => 1.23
117: -- after repeating 2 times is => 1.231.23
118: -- after repeating 3 times is => 1.231.231.23
119:
120: --- str_repeat() of '' ---
121: -- after repeating 0 times is =>
122: -- after repeating 1 times is =>
123: -- after repeating 2 times is =>
124: -- after repeating 3 times is =>
125:
126: --- str_repeat() of ' ' ---
127: -- after repeating 0 times is =>
128: -- after repeating 1 times is =>
129: -- after repeating 2 times is =>
130: -- after repeating 3 times is =>
131:
132:
133: *** Testing str_repeat() with various strings & multiplier value ***
134: --- str_repeat() of 'a' ---
135: -- after repeating 'a' times is =>
136: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
137: NULL
138: -- after repeating 'foo' times is =>
139: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
140: NULL
141: -- after repeating 'barbazbax' times is =>
142: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
143: NULL
144: -- after repeating ' ' times is =>
145: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
146: NULL
147: -- after repeating '\0' times is =>
148: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
149: NULL
150: -- after repeating '' times is => string(0) ""
151: -- after repeating '1' times is => string(1) "a"
152: -- after repeating '4' times is => string(4) "aaaa"
153: -- after repeating '1.23' times is => string(1) "a"
154: -- after repeating '' times is =>
155: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
156: NULL
157: -- after repeating ' ' times is =>
158: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
159: NULL
160:
161: --- str_repeat() of 'foo' ---
162: -- after repeating 'a' times is =>
163: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
164: NULL
165: -- after repeating 'foo' times is =>
166: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
167: NULL
168: -- after repeating 'barbazbax' times is =>
169: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
170: NULL
171: -- after repeating ' ' times is =>
172: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
173: NULL
174: -- after repeating '\0' times is =>
175: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
176: NULL
177: -- after repeating '' times is => string(0) ""
178: -- after repeating '1' times is => string(3) "foo"
179: -- after repeating '4' times is => string(12) "foofoofoofoo"
180: -- after repeating '1.23' times is => string(3) "foo"
181: -- after repeating '' times is =>
182: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
183: NULL
184: -- after repeating ' ' times is =>
185: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
186: NULL
187:
188: --- str_repeat() of 'barbazbax' ---
189: -- after repeating 'a' times is =>
190: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
191: NULL
192: -- after repeating 'foo' times is =>
193: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
194: NULL
195: -- after repeating 'barbazbax' times is =>
196: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
197: NULL
198: -- after repeating ' ' times is =>
199: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
200: NULL
201: -- after repeating '\0' times is =>
202: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
203: NULL
204: -- after repeating '' times is => string(0) ""
205: -- after repeating '1' times is => string(9) "barbazbax"
206: -- after repeating '4' times is => string(36) "barbazbaxbarbazbaxbarbazbaxbarbazbax"
207: -- after repeating '1.23' times is => string(9) "barbazbax"
208: -- after repeating '' times is =>
209: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
210: NULL
211: -- after repeating ' ' times is =>
212: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
213: NULL
214:
215: --- str_repeat() of ' ' ---
216: -- after repeating 'a' times is =>
217: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
218: NULL
219: -- after repeating 'foo' times is =>
220: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
221: NULL
222: -- after repeating 'barbazbax' times is =>
223: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
224: NULL
225: -- after repeating ' ' times is =>
226: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
227: NULL
228: -- after repeating '\0' times is =>
229: Warning: str_repeat() expects parameter 2 to be long, string given in %s on line %d
230: NULL
231: -- after repeating '' times is => string(0) ""
232: -- after repeating '1' times is => string(1) "