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