1--TEST--
2Test strcspn() function : usage variations - with heredoc strings, varying start and default len args
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/*
13* Testing strcspn() : with heredoc string, varying start and default len arguments
14*/
15
16echo "*** Testing strcspn() : with different start values ***\n";
17
18// initialing required variables
19// defining different heredoc strings
20$empty_heredoc = <<<EOT
21EOT;
22
23$heredoc_with_newline = <<<EOT
24\n
25
26EOT;
27
28$heredoc_with_characters = <<<EOT
29first line of heredoc string
30second line of heredoc string
31third line of heredocstring
32EOT;
33
34$heredoc_with_newline_and_tabs = <<<EOT
35hello\tworld\nhello\nworld\n
36EOT;
37
38$heredoc_with_alphanumerics = <<<EOT
39hello123world456
401234hello\t1234
41EOT;
42
43$heredoc_with_embedded_nulls = <<<EOT
44hello\0world\0hello
45\0hello\0
46EOT;
47
48$heredoc_with_hexa_octal = <<<EOT
49hello\0\100\xaaworld\0hello
50\0hello\0
51EOT;
52
53$heredoc_strings = array(
54                   $empty_heredoc,
55                   $heredoc_with_newline,
56                   $heredoc_with_characters,
57                   $heredoc_with_newline_and_tabs,
58                   $heredoc_with_alphanumerics,
59                   $heredoc_with_embedded_nulls,
60   		   $heredoc_with_hexa_octal
61 		   );
62
63
64// defining array of mask strings
65
66$mask_array = array(
67		    "",
68		    '',
69		    "\n\trsti \l",
70		    '\n\trsti \l',
71		    "\t",
72		    "t\ ",
73		    '\t',
74		    "\t\ ",
75		    " \t",
76                    "\t\i\100\xaa"
77                   );
78
79// definig array of start values
80$start_array = array(
81		    0,
82		    1,
83		    2,
84		    -1,
85		    -2,
86		    2147483647,  // max positive integer
87		    -2147483648,  // min negative integer
88                   );
89
90
91// loop through each element of the arrays for str, mask and start arguments
92
93$count = 1;
94foreach($heredoc_strings as $str) {
95  echo "\n-- Iteration $count --\n";
96  foreach($mask_array as $mask) {
97    foreach($start_array as $start) {
98      var_dump( strcspn($str,$mask,$start) );  // with default len value
99    }
100  }
101  $count++;
102}
103
104echo "Done"
105?>
106--EXPECTF--
107*** Testing strcspn() : with different start values ***
108
109-- Iteration 1 --
110int(0)
111bool(false)
112bool(false)
113int(0)
114int(0)
115bool(false)
116int(0)
117int(0)
118bool(false)
119bool(false)
120int(0)
121int(0)
122bool(false)
123int(0)
124int(0)
125bool(false)
126bool(false)
127int(0)
128int(0)
129bool(false)
130int(0)
131int(0)
132bool(false)
133bool(false)
134int(0)
135int(0)
136bool(false)
137int(0)
138int(0)
139bool(false)
140bool(false)
141int(0)
142int(0)
143bool(false)
144int(0)
145int(0)
146bool(false)
147bool(false)
148int(0)
149int(0)
150bool(false)
151int(0)
152int(0)
153bool(false)
154bool(false)
155int(0)
156int(0)
157bool(false)
158int(0)
159int(0)
160bool(false)
161bool(false)
162int(0)
163int(0)
164bool(false)
165int(0)
166int(0)
167bool(false)
168bool(false)
169int(0)
170int(0)
171bool(false)
172int(0)
173int(0)
174bool(false)
175bool(false)
176int(0)
177int(0)
178bool(false)
179int(0)
180
181-- Iteration 2 --
182int(2)
183int(1)
184int(0)
185int(1)
186int(2)
187bool(false)
188int(2)
189int(2)
190int(1)
191int(0)
192int(1)
193int(2)
194bool(false)
195int(2)
196int(0)
197int(0)
198int(0)
199int(0)
200int(0)
201bool(false)
202int(0)
203int(2)
204int(1)
205int(0)
206int(1)
207int(2)
208bool(false)
209int(2)
210int(2)
211int(1)
212int(0)
213int(1)
214int(2)
215bool(false)
216int(2)
217int(2)
218int(1)
219int(0)
220int(1)
221int(2)
222bool(false)
223int(2)
224int(2)
225int(1)
226int(0)
227int(1)
228int(2)
229bool(false)
230int(2)
231int(2)
232int(1)
233int(0)
234int(1)
235int(2)
236bool(false)
237int(2)
238int(2)
239int(1)
240int(0)
241int(1)
242int(2)
243bool(false)
244int(2)
245int(2)
246int(1)
247int(0)
248int(1)
249int(2)
250bool(false)
251int(2)
252
253-- Iteration 3 --
254int(86)
255int(85)
256int(84)
257int(1)
258int(2)
259bool(false)
260int(86)
261int(86)
262int(85)
263int(84)
264int(1)
265int(2)
266bool(false)
267int(86)
268int(1)
269int(0)
270int(0)
271int(1)
272int(2)
273bool(false)
274int(1)
275int(1)
276int(0)
277int(0)
278int(1)
279int(0)
280bool(false)
281int(1)
282int(86)
283int(85)
284int(84)
285int(1)
286int(2)
287bool(false)
288int(86)
289int(4)
290int(3)
291int(2)
292int(1)
293int(2)
294bool(false)
295int(4)
296int(4)
297int(3)
298int(2)
299int(1)
300int(2)
301bool(false)
302int(4)
303int(5)
304int(4)
305int(3)
306int(1)
307int(2)
308bool(false)
309int(5)
310int(5)
311int(4)
312int(3)
313int(1)
314int(2)
315bool(false)
316int(5)
317int(1)
318int(0)
319int(5)
320int(1)
321int(2)
322bool(false)
323int(1)
324
325-- Iteration 4 --
326int(24)
327int(23)
328int(22)
329int(1)
330int(2)
331bool(false)
332int(24)
333int(24)
334int(23)
335int(22)
336int(1)
337int(2)
338bool(false)
339int(24)
340int(2)
341int(1)
342int(0)
343int(0)
344int(1)
345bool(false)
346int(2)
347int(2)
348int(1)
349int(0)
350int(1)
351int(2)
352bool(false)
353int(2)
354int(5)
355int(4)
356int(3)
357int(1)
358int(2)
359bool(false)
360int(5)
361int(24)
362int(23)
363int(22)
364int(1)
365int(2)
366bool(false)
367int(24)
368int(24)
369int(23)
370int(22)
371int(1)
372int(2)
373bool(false)
374int(24)
375int(5)
376int(4)
377int(3)
378int(1)
379int(2)
380bool(false)
381int(5)
382int(5)
383int(4)
384int(3)
385int(1)
386int(2)
387bool(false)
388int(5)
389int(5)
390int(4)
391int(3)
392int(1)
393int(2)
394bool(false)
395int(5)
396
397-- Iteration 5 --
398int(31)
399int(30)
400int(29)
401int(1)
402int(2)
403bool(false)
404int(31)
405int(31)
406int(30)
407int(29)
408int(1)
409int(2)
410bool(false)
411int(31)
412int(2)
413int(1)
414int(0)
415int(1)
416int(2)
417bool(false)
418int(2)
419int(2)
420int(1)
421int(0)
422int(1)
423int(2)
424bool(false)
425int(2)
426int(26)
427int(25)
428int(24)
429int(1)
430int(2)
431bool(false)
432int(26)
433int(31)
434int(30)
435int(29)
436int(1)
437int(2)
438bool(false)
439int(31)
440int(31)
441int(30)
442int(29)
443int(1)
444int(2)
445bool(false)
446int(31)
447int(26)
448int(25)
449int(24)
450int(1)
451int(2)
452bool(false)
453int(26)
454int(26)
455int(25)
456int(24)
457int(1)
458int(2)
459bool(false)
460int(26)
461int(26)
462int(25)
463int(24)
464int(1)
465int(2)
466bool(false)
467int(26)
468
469-- Iteration 6 --
470int(5)
471int(4)
472int(3)
473int(0)
474int(1)
475bool(false)
476int(5)
477int(5)
478int(4)
479int(3)
480int(0)
481int(1)
482bool(false)
483int(5)
484int(2)
485int(1)
486int(0)
487int(1)
488int(2)
489bool(false)
490int(2)
491int(2)
492int(1)
493int(0)
494int(1)
495int(2)
496bool(false)
497int(2)
498int(25)
499int(24)
500int(23)
501int(1)
502int(2)
503bool(false)
504int(25)
505int(25)
506int(24)
507int(23)
508int(1)
509int(2)
510bool(false)
511int(25)
512int(25)
513int(24)
514int(23)
515int(1)
516int(2)
517bool(false)
518int(25)
519int(25)
520int(24)
521int(23)
522int(1)
523int(2)
524bool(false)
525int(25)
526int(25)
527int(24)
528int(23)
529int(1)
530int(2)
531bool(false)
532int(25)
533int(25)
534int(24)
535int(23)
536int(1)
537int(2)
538bool(false)
539int(25)
540
541-- Iteration 7 --
542int(5)
543int(4)
544int(3)
545int(0)
546int(1)
547bool(false)
548int(5)
549int(5)
550int(4)
551int(3)
552int(0)
553int(1)
554bool(false)
555int(5)
556int(2)
557int(1)
558int(0)
559int(1)
560int(2)
561bool(false)
562int(2)
563int(2)
564int(1)
565int(0)
566int(1)
567int(2)
568bool(false)
569int(2)
570int(27)
571int(26)
572int(25)
573int(1)
574int(2)
575bool(false)
576int(27)
577int(27)
578int(26)
579int(25)
580int(1)
581int(2)
582bool(false)
583int(27)
584int(27)
585int(26)
586int(25)
587int(1)
588int(2)
589bool(false)
590int(27)
591int(27)
592int(26)
593int(25)
594int(1)
595int(2)
596bool(false)
597int(27)
598int(27)
599int(26)
600int(25)
601int(1)
602int(2)
603bool(false)
604int(27)
605int(6)
606int(5)
607int(4)
608int(1)
609int(2)
610bool(false)
611int(6)
612Done
613