Annotation of embedaddon/php/ext/standard/tests/strings/strspn_variation2.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test strspn() function : usage variations - unexpected values for mask argument
3: --FILE--
4: <?php
5: /* Prototype : proto int strspn(string str, string mask [, int start [, int len]])
6: * Description: Finds length of initial segment consisting entirely of characters found in mask.
7: If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars)
8: * Source code: ext/standard/string.c
9: * Alias to functions: none
10: */
11:
12: error_reporting(E_ALL & ~E_NOTICE);
13:
14: /*
15: * Testing strspn() : with different unexpected values for mask argument
16: */
17:
1.1.1.2 ! misho 18: echo "*** Testing strspn() : with different unexpected values of mask argument ***\n";
1.1 misho 19:
20: $str = 'string_val';
21: $start = 1;
22: $len = 10;
23:
24:
25: //get an unset variable
26: $unset_var = 10;
27: unset ($unset_var);
28:
29: // declaring class
30: class sample {
31: public function __toString() {
32: return "object";
33: }
34: }
35:
36: // creating a file resource
37: $file_handle = fopen(__FILE__, 'r');
38:
39:
40: //array of values to iterate over
41: $values = array(
42:
43: // int data
44: 0,
45: 1,
46: 12345,
47: -2345,
48:
49: // float data
50: 10.5,
51: -10.5,
52: 10.1234567e10,
53: 10.7654321E-10,
54: .5,
55:
56: // array data
57: array(),
58: array(0),
59: array(1),
60: array(1, 2),
61: array('color' => 'red', 'item' => 'pen'),
62:
63: // null data
64: NULL,
65: null,
66:
67: // boolean data
68: true,
69: false,
70: TRUE,
71: FALSE,
72:
73: // empty data
74: "",
75: '',
76:
77: // object data
78: new sample(),
79:
80: // undefined data
81: $undefined_var,
82:
83: // unset data
84: $unset_var,
85:
86: // resource
87: $file_handle
88: );
89:
90: // loop through each element of the array for mask
91:
92: foreach($values as $value) {
93: echo "\n-- Iteration with mask value as \"$value\" --\n";
94: var_dump( strspn($str,$value) ); // with defalut args
95: var_dump( strspn($str,$value,$start) ); // with default len value
96: var_dump( strspn($str,$value,$start,$len) ); // with all args
97: };
98:
99: // close the resource
100: fclose($file_handle);
101:
102: echo "Done"
103: ?>
104: --EXPECTF--
1.1.1.2 ! misho 105: *** Testing strspn() : with different unexpected values of mask argument ***
1.1 misho 106:
107: -- Iteration with mask value as "0" --
108: int(0)
109: int(0)
110: int(0)
111:
112: -- Iteration with mask value as "1" --
113: int(0)
114: int(0)
115: int(0)
116:
117: -- Iteration with mask value as "12345" --
118: int(0)
119: int(0)
120: int(0)
121:
122: -- Iteration with mask value as "-2345" --
123: int(0)
124: int(0)
125: int(0)
126:
127: -- Iteration with mask value as "10.5" --
128: int(0)
129: int(0)
130: int(0)
131:
132: -- Iteration with mask value as "-10.5" --
133: int(0)
134: int(0)
135: int(0)
136:
137: -- Iteration with mask value as "101234567000" --
138: int(0)
139: int(0)
140: int(0)
141:
142: -- Iteration with mask value as "1.07654321E-9" --
143: int(0)
144: int(0)
145: int(0)
146:
147: -- Iteration with mask value as "0.5" --
148: int(0)
149: int(0)
150: int(0)
151:
152: -- Iteration with mask value as "Array" --
153:
154: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
155: NULL
156:
157: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
158: NULL
159:
160: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
161: NULL
162:
163: -- Iteration with mask value as "Array" --
164:
165: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
166: NULL
167:
168: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
169: NULL
170:
171: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
172: NULL
173:
174: -- Iteration with mask value as "Array" --
175:
176: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
177: NULL
178:
179: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
180: NULL
181:
182: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
183: NULL
184:
185: -- Iteration with mask value as "Array" --
186:
187: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
188: NULL
189:
190: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
191: NULL
192:
193: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
194: NULL
195:
196: -- Iteration with mask value as "Array" --
197:
198: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
199: NULL
200:
201: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
202: NULL
203:
204: Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
205: NULL
206:
207: -- Iteration with mask value as "" --
208: int(0)
209: int(0)
210: int(0)
211:
212: -- Iteration with mask value as "" --
213: int(0)
214: int(0)
215: int(0)
216:
217: -- Iteration with mask value as "1" --
218: int(0)
219: int(0)
220: int(0)
221:
222: -- Iteration with mask value as "" --
223: int(0)
224: int(0)
225: int(0)
226:
227: -- Iteration with mask value as "1" --
228: int(0)
229: int(0)
230: int(0)
231:
232: -- Iteration with mask value as "" --
233: int(0)
234: int(0)
235: int(0)
236:
237: -- Iteration with mask value as "" --
238: int(0)
239: int(0)
240: int(0)
241:
242: -- Iteration with mask value as "" --
243: int(0)
244: int(0)
245: int(0)
246:
247: -- Iteration with mask value as "object" --
248: int(0)
249: int(1)
250: int(1)
251:
252: -- Iteration with mask value as "" --
253: int(0)
254: int(0)
255: int(0)
256:
257: -- Iteration with mask value as "" --
258: int(0)
259: int(0)
260: int(0)
261:
262: -- Iteration with mask value as "Resource id #%d" --
263:
264: Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d
265: NULL
266:
267: Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d
268: NULL
269:
270: Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d
271: NULL
272: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>