1--TEST--
2Test strcspn() function : usage variations - with 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 varying start and default len arguments
14*/
15
16echo "*** Testing strcspn() : with different start and default len values ***\n";
17
18// initialing required variables
19// initialing required variables
20$strings = array(
21                   "",
22                   '',
23                   "\n",
24                   '\n',
25                   "hello\tworld\nhello\nworld\n",
26                   'hello\tworld\nhello\nworld\n',
27                   "1234hello45world\t123",
28                   '1234hello45world\t123',
29                   "hello\0world\012",
30                   'hello\0world\012',
31                   chr(0).chr(0),
32                   chr(0)."hello\0world".chr(0),
33                   chr(0).'hello\0world'.chr(0),
34                   "hello".chr(0)."world",
35                   'hello'.chr(0).'world',
36                   "hello\0\100\xaaaworld",
37                   'hello\0\100\xaaaworld'
38                   );
39
40// defining array of mask strings
41$mask_array = array(
42                    "",
43                    '',
44                    "\n\trsti \l",
45                    '\n\trsti \l',
46                    "\t",
47                    "t\ ",
48                    '\t',
49                    "\t\ ",
50                    " \t",
51                    "\t\i\100\xa"
52                   );
53
54//defining array of start values
55$start_array = array(
56                     0,
57                     1,
58                     2,
59                     -1,
60                     -2,
61                     2147483647,  // max positive integer
62                     -2147483648,  // min negative integer
63                    );
64
65
66// loop through each element of the arrays for str,mask and start arguments
67$count = 1;
68foreach($strings as $str) {
69  echo "\n-- Iteration $count --\n";
70  foreach($mask_array as $mask) {
71    foreach($start_array as $start) {
72      var_dump( strcspn($str,$mask,$start) );
73    }
74  }
75  $count++;
76}
77
78echo "Done"
79?>
80--EXPECTF--
81*** Testing strcspn() : with different start and default len values ***
82
83-- Iteration 1 --
84int(0)
85bool(false)
86bool(false)
87int(0)
88int(0)
89bool(false)
90int(0)
91int(0)
92bool(false)
93bool(false)
94int(0)
95int(0)
96bool(false)
97int(0)
98int(0)
99bool(false)
100bool(false)
101int(0)
102int(0)
103bool(false)
104int(0)
105int(0)
106bool(false)
107bool(false)
108int(0)
109int(0)
110bool(false)
111int(0)
112int(0)
113bool(false)
114bool(false)
115int(0)
116int(0)
117bool(false)
118int(0)
119int(0)
120bool(false)
121bool(false)
122int(0)
123int(0)
124bool(false)
125int(0)
126int(0)
127bool(false)
128bool(false)
129int(0)
130int(0)
131bool(false)
132int(0)
133int(0)
134bool(false)
135bool(false)
136int(0)
137int(0)
138bool(false)
139int(0)
140int(0)
141bool(false)
142bool(false)
143int(0)
144int(0)
145bool(false)
146int(0)
147int(0)
148bool(false)
149bool(false)
150int(0)
151int(0)
152bool(false)
153int(0)
154
155-- Iteration 2 --
156int(0)
157bool(false)
158bool(false)
159int(0)
160int(0)
161bool(false)
162int(0)
163int(0)
164bool(false)
165bool(false)
166int(0)
167int(0)
168bool(false)
169int(0)
170int(0)
171bool(false)
172bool(false)
173int(0)
174int(0)
175bool(false)
176int(0)
177int(0)
178bool(false)
179bool(false)
180int(0)
181int(0)
182bool(false)
183int(0)
184int(0)
185bool(false)
186bool(false)
187int(0)
188int(0)
189bool(false)
190int(0)
191int(0)
192bool(false)
193bool(false)
194int(0)
195int(0)
196bool(false)
197int(0)
198int(0)
199bool(false)
200bool(false)
201int(0)
202int(0)
203bool(false)
204int(0)
205int(0)
206bool(false)
207bool(false)
208int(0)
209int(0)
210bool(false)
211int(0)
212int(0)
213bool(false)
214bool(false)
215int(0)
216int(0)
217bool(false)
218int(0)
219int(0)
220bool(false)
221bool(false)
222int(0)
223int(0)
224bool(false)
225int(0)
226
227-- Iteration 3 --
228int(1)
229int(0)
230bool(false)
231int(1)
232int(1)
233bool(false)
234int(1)
235int(1)
236int(0)
237bool(false)
238int(1)
239int(1)
240bool(false)
241int(1)
242int(0)
243int(0)
244bool(false)
245int(0)
246int(0)
247bool(false)
248int(0)
249int(1)
250int(0)
251bool(false)
252int(1)
253int(1)
254bool(false)
255int(1)
256int(1)
257int(0)
258bool(false)
259int(1)
260int(1)
261bool(false)
262int(1)
263int(1)
264int(0)
265bool(false)
266int(1)
267int(1)
268bool(false)
269int(1)
270int(1)
271int(0)
272bool(false)
273int(1)
274int(1)
275bool(false)
276int(1)
277int(1)
278int(0)
279bool(false)
280int(1)
281int(1)
282bool(false)
283int(1)
284int(1)
285int(0)
286bool(false)
287int(1)
288int(1)
289bool(false)
290int(1)
291int(0)
292int(0)
293bool(false)
294int(0)
295int(0)
296bool(false)
297int(0)
298
299-- Iteration 4 --
300int(2)
301int(1)
302int(0)
303int(1)
304int(2)
305bool(false)
306int(2)
307int(2)
308int(1)
309int(0)
310int(1)
311int(2)
312bool(false)
313int(2)
314int(0)
315int(1)
316int(0)
317int(1)
318int(0)
319bool(false)
320int(0)
321int(0)
322int(0)
323int(0)
324int(0)
325int(0)
326bool(false)
327int(0)
328int(2)
329int(1)
330int(0)
331int(1)
332int(2)
333bool(false)
334int(2)
335int(0)
336int(1)
337int(0)
338int(1)
339int(0)
340bool(false)
341int(0)
342int(0)
343int(1)
344int(0)
345int(1)
346int(0)
347bool(false)
348int(0)
349int(0)
350int(1)
351int(0)
352int(1)
353int(0)
354bool(false)
355int(0)
356int(2)
357int(1)
358int(0)
359int(1)
360int(2)
361bool(false)
362int(2)
363int(0)
364int(1)
365int(0)
366int(1)
367int(0)
368bool(false)
369int(0)
370
371-- Iteration 5 --
372int(24)
373int(23)
374int(22)
375int(1)
376int(2)
377bool(false)
378int(24)
379int(24)
380int(23)
381int(22)
382int(1)
383int(2)
384bool(false)
385int(24)
386int(2)
387int(1)
388int(0)
389int(0)
390int(1)
391bool(false)
392int(2)
393int(2)
394int(1)
395int(0)
396int(1)
397int(2)
398bool(false)
399int(2)
400int(5)
401int(4)
402int(3)
403int(1)
404int(2)
405bool(false)
406int(5)
407int(24)
408int(23)
409int(22)
410int(1)
411int(2)
412bool(false)
413int(24)
414int(24)
415int(23)
416int(22)
417int(1)
418int(2)
419bool(false)
420int(24)
421int(5)
422int(4)
423int(3)
424int(1)
425int(2)
426bool(false)
427int(5)
428int(5)
429int(4)
430int(3)
431int(1)
432int(2)
433bool(false)
434int(5)
435int(5)
436int(4)
437int(3)
438int(0)
439int(1)
440bool(false)
441int(5)
442
443-- Iteration 6 --
444int(28)
445int(27)
446int(26)
447int(1)
448int(2)
449bool(false)
450int(28)
451int(28)
452int(27)
453int(26)
454int(1)
455int(2)
456bool(false)
457int(28)
458int(2)
459int(1)
460int(0)
461int(1)
462int(0)
463bool(false)
464int(2)
465int(2)
466int(1)
467int(0)
468int(0)
469int(0)
470bool(false)
471int(2)
472int(28)
473int(27)
474int(26)
475int(1)
476int(2)
477bool(false)
478int(28)
479int(5)
480int(4)
481int(3)
482int(1)
483int(0)
484bool(false)
485int(5)
486int(5)
487int(4)
488int(3)
489int(1)
490int(0)
491bool(false)
492int(5)
493int(5)
494int(4)
495int(3)
496int(1)
497int(0)
498bool(false)
499int(5)
500int(28)
501int(27)
502int(26)
503int(1)
504int(2)
505bool(false)
506int(28)
507int(5)
508int(4)
509int(3)
510int(1)
511int(0)
512bool(false)
513int(5)
514
515-- Iteration 7 --
516int(20)
517int(19)
518int(18)
519int(1)
520int(2)
521bool(false)
522int(20)
523int(20)
524int(19)
525int(18)
526int(1)
527int(2)
528bool(false)
529int(20)
530int(6)
531int(5)
532int(4)
533int(1)
534int(2)
535bool(false)
536int(6)
537int(6)
538int(5)
539int(4)
540int(1)
541int(2)
542bool(false)
543int(6)
544int(16)
545int(15)
546int(14)
547int(1)
548int(2)
549bool(false)
550int(16)
551int(20)
552int(19)
553int(18)
554int(1)
555int(2)
556bool(false)
557int(20)
558int(20)
559int(19)
560int(18)
561int(1)
562int(2)
563bool(false)
564int(20)
565int(16)
566int(15)
567int(14)
568int(1)
569int(2)
570bool(false)
571int(16)
572int(16)
573int(15)
574int(14)
575int(1)
576int(2)
577bool(false)
578int(16)
579int(16)
580int(15)
581int(14)
582int(1)
583int(2)
584bool(false)
585int(16)
586
587-- Iteration 8 --
588int(21)
589int(20)
590int(19)
591int(1)
592int(2)
593bool(false)
594int(21)
595int(21)
596int(20)
597int(19)
598int(1)
599int(2)
600bool(false)
601int(21)
602int(6)
603int(5)
604int(4)
605int(1)
606int(2)
607bool(false)
608int(6)
609int(6)
610int(5)
611int(4)
612int(1)
613int(2)
614bool(false)
615int(6)
616int(21)
617int(20)
618int(19)
619int(1)
620int(2)
621bool(false)
622int(21)
623int(16)
624int(15)
625int(14)
626int(1)
627int(2)
628bool(false)
629int(16)
630int(16)
631int(15)
632int(14)
633int(1)
634int(2)
635bool(false)
636int(16)
637int(16)
638int(15)
639int(14)
640int(1)
641int(2)
642bool(false)
643int(16)
644int(21)
645int(20)
646int(19)
647int(1)
648int(2)
649bool(false)
650int(21)
651int(16)
652int(15)
653int(14)
654int(1)
655int(2)
656bool(false)
657int(16)
658
659-- Iteration 9 --
660int(5)
661int(4)
662int(3)
663int(1)
664int(2)
665bool(false)
666int(5)
667int(5)
668int(4)
669int(3)
670int(1)
671int(2)
672bool(false)
673int(5)
674int(2)
675int(1)
676int(0)
677int(0)
678int(1)
679bool(false)
680int(2)
681int(2)
682int(1)
683int(0)
684int(1)
685int(2)
686bool(false)
687int(2)
688int(12)
689int(11)
690int(10)
691int(1)
692int(2)
693bool(false)
694int(12)
695int(12)
696int(11)
697int(10)
698int(1)
699int(2)
700bool(false)
701int(12)
702int(12)
703int(11)
704int(10)
705int(1)
706int(2)
707bool(false)
708int(12)
709int(12)
710int(11)
711int(10)
712int(1)
713int(2)
714bool(false)
715int(12)
716int(12)
717int(11)
718int(10)
719int(1)
720int(2)
721bool(false)
722int(12)
723int(11)
724int(10)
725int(9)
726int(0)
727int(1)
728bool(false)
729int(11)
730
731-- Iteration 10 --
732int(16)
733int(15)
734int(14)
735int(1)
736int(2)
737bool(false)
738int(16)
739int(16)
740int(15)
741int(14)
742int(1)
743int(2)
744bool(false)
745int(16)
746int(2)
747int(1)
748int(0)
749int(1)
750int(2)
751bool(false)
752int(2)
753int(2)
754int(1)
755int(0)
756int(1)
757int(2)
758bool(false)
759int(2)
760int(16)
761int(15)
762int(14)
763int(1)
764int(2)
765bool(false)
766int(16)
767int(5)
768int(4)
769int(3)
770int(1)
771int(2)
772bool(false)
773int(5)
774int(5)
775int(4)
776int(3)
777int(1)
778int(2)
779bool(false)
780int(5)
781int(5)
782int(4)
783int(3)
784int(1)
785int(2)
786bool(false)
787int(5)
788int(16)
789int(15)
790int(14)
791int(1)
792int(2)
793bool(false)
794int(16)
795int(5)
796int(4)
797int(3)
798int(1)
799int(2)
800bool(false)
801int(5)
802
803-- Iteration 11 --
804int(0)
805int(0)
806int(0)
807int(0)
808int(0)
809bool(false)
810int(0)
811int(0)
812int(0)
813int(0)
814int(0)
815int(0)
816bool(false)
817int(0)
818int(2)
819int(1)
820int(0)
821int(1)
822int(2)
823bool(false)
824int(2)
825int(2)
826int(1)
827int(0)
828int(1)
829int(2)
830bool(false)
831int(2)
832int(2)
833int(1)
834int(0)
835int(1)
836int(2)
837bool(false)
838int(2)
839int(2)
840int(1)
841int(0)
842int(1)
843int(2)
844bool(false)
845int(2)
846int(2)
847int(1)
848int(0)
849int(1)
850int(2)
851bool(false)
852int(2)
853int(2)
854int(1)
855int(0)
856int(1)
857int(2)
858bool(false)
859int(2)
860int(2)
861int(1)
862int(0)
863int(1)
864int(2)
865bool(false)
866int(2)
867int(2)
868int(1)
869int(0)
870int(1)
871int(2)
872bool(false)
873int(2)
874
875-- Iteration 12 --
876int(0)
877int(5)
878int(4)
879int(0)
880int(1)
881bool(false)
882int(0)
883int(0)
884int(5)
885int(4)
886int(0)
887int(1)
888bool(false)
889int(0)
890int(3)
891int(2)
892int(1)
893int(1)
894int(2)
895bool(false)
896int(3)
897int(3)
898int(2)
899int(1)
900int(1)
901int(2)
902bool(false)
903int(3)
904int(13)
905int(12)
906int(11)
907int(1)
908int(2)
909bool(false)
910int(13)
911int(13)
912int(12)
913int(11)
914int(1)
915int(2)
916bool(false)
917int(13)
918int(13)
919int(12)
920int(11)
921int(1)
922int(2)
923bool(false)
924int(13)
925int(13)
926int(12)
927int(11)
928int(1)
929int(2)
930bool(false)
931int(13)
932int(13)
933int(12)
934int(11)
935int(1)
936int(2)
937bool(false)
938int(13)
939int(13)
940int(12)
941int(11)
942int(1)
943int(2)
944bool(false)
945int(13)
946
947-- Iteration 13 --
948int(0)
949int(12)
950int(11)
951int(0)
952int(1)
953bool(false)
954int(0)
955int(0)
956int(12)
957int(11)
958int(0)
959int(1)
960bool(false)
961int(0)
962int(3)
963int(2)
964int(1)
965int(1)
966int(2)
967bool(false)
968int(3)
969int(3)
970int(2)
971int(1)
972int(1)
973int(2)
974bool(false)
975int(3)
976int(14)
977int(13)
978int(12)
979int(1)
980int(2)
981bool(false)
982int(14)
983int(6)
984int(5)
985int(4)
986int(1)
987int(2)
988bool(false)
989int(6)
990int(6)
991int(5)
992int(4)
993int(1)
994int(2)
995bool(false)
996int(6)
997int(6)
998int(5)
999int(4)
1000int(1)
1001int(2)
1002bool(false)
1003int(6)
1004int(14)
1005int(13)
1006int(12)
1007int(1)
1008int(2)
1009bool(false)
1010int(14)
1011int(6)
1012int(5)
1013int(4)
1014int(1)
1015int(2)
1016bool(false)
1017int(6)
1018
1019-- Iteration 14 --
1020int(5)
1021int(4)
1022int(3)
1023int(1)
1024int(2)
1025bool(false)
1026int(5)
1027int(5)
1028int(4)
1029int(3)
1030int(1)
1031int(2)
1032bool(false)
1033int(5)
1034int(2)
1035int(1)
1036int(0)
1037int(1)
1038int(0)
1039bool(false)
1040int(2)
1041int(2)
1042int(1)
1043int(0)
1044int(1)
1045int(0)
1046bool(false)
1047int(2)
1048int(11)
1049int(10)
1050int(9)
1051int(1)
1052int(2)
1053bool(false)
1054int(11)
1055int(11)
1056int(10)
1057int(9)
1058int(1)
1059int(2)
1060bool(false)
1061int(11)
1062int(11)
1063int(10)
1064int(9)
1065int(1)
1066int(2)
1067bool(false)
1068int(11)
1069int(11)
1070int(10)
1071int(9)
1072int(1)
1073int(2)
1074bool(false)
1075int(11)
1076int(11)
1077int(10)
1078int(9)
1079int(1)
1080int(2)
1081bool(false)
1082int(11)
1083int(11)
1084int(10)
1085int(9)
1086int(1)
1087int(2)
1088bool(false)
1089int(11)
1090
1091-- Iteration 15 --
1092int(5)
1093int(4)
1094int(3)
1095int(1)
1096int(2)
1097bool(false)
1098int(5)
1099int(5)
1100int(4)
1101int(3)
1102int(1)
1103int(2)
1104bool(false)
1105int(5)
1106int(2)
1107int(1)
1108int(0)
1109int(1)
1110int(0)
1111bool(false)
1112int(2)
1113int(2)
1114int(1)
1115int(0)
1116int(1)
1117int(0)
1118bool(false)
1119int(2)
1120int(11)
1121int(10)
1122int(9)
1123int(1)
1124int(2)
1125bool(false)
1126int(11)
1127int(11)
1128int(10)
1129int(9)
1130int(1)
1131int(2)
1132bool(false)
1133int(11)
1134int(11)
1135int(10)
1136int(9)
1137int(1)
1138int(2)
1139bool(false)
1140int(11)
1141int(11)
1142int(10)
1143int(9)
1144int(1)
1145int(2)
1146bool(false)
1147int(11)
1148int(11)
1149int(10)
1150int(9)
1151int(1)
1152int(2)
1153bool(false)
1154int(11)
1155int(11)
1156int(10)
1157int(9)
1158int(1)
1159int(2)
1160bool(false)
1161int(11)
1162
1163-- Iteration 16 --
1164int(5)
1165int(4)
1166int(3)
1167int(1)
1168int(2)
1169bool(false)
1170int(5)
1171int(5)
1172int(4)
1173int(3)
1174int(1)
1175int(2)
1176bool(false)
1177int(5)
1178int(2)
1179int(1)
1180int(0)
1181int(1)
1182int(0)
1183bool(false)
1184int(2)
1185int(2)
1186int(1)
1187int(0)
1188int(1)
1189int(0)
1190bool(false)
1191int(2)
1192int(14)
1193int(13)
1194int(12)
1195int(1)
1196int(2)
1197bool(false)
1198int(14)
1199int(14)
1200int(13)
1201int(12)
1202int(1)
1203int(2)
1204bool(false)
1205int(14)
1206int(14)
1207int(13)
1208int(12)
1209int(1)
1210int(2)
1211bool(false)
1212int(14)
1213int(14)
1214int(13)
1215int(12)
1216int(1)
1217int(2)
1218bool(false)
1219int(14)
1220int(14)
1221int(13)
1222int(12)
1223int(1)
1224int(2)
1225bool(false)
1226int(14)
1227int(6)
1228int(5)
1229int(4)
1230int(1)
1231int(2)
1232bool(false)
1233int(6)
1234
1235-- Iteration 17 --
1236int(21)
1237int(20)
1238int(19)
1239int(1)
1240int(2)
1241bool(false)
1242int(21)
1243int(21)
1244int(20)
1245int(19)
1246int(1)
1247int(2)
1248bool(false)
1249int(21)
1250int(2)
1251int(1)
1252int(0)
1253int(1)
1254int(0)
1255bool(false)
1256int(2)
1257int(2)
1258int(1)
1259int(0)
1260int(1)
1261int(0)
1262bool(false)
1263int(2)
1264int(21)
1265int(20)
1266int(19)
1267int(1)
1268int(2)
1269bool(false)
1270int(21)
1271int(5)
1272int(4)
1273int(3)
1274int(1)
1275int(2)
1276bool(false)
1277int(5)
1278int(5)
1279int(4)
1280int(3)
1281int(1)
1282int(2)
1283bool(false)
1284int(5)
1285int(5)
1286int(4)
1287int(3)
1288int(1)
1289int(2)
1290bool(false)
1291int(5)
1292int(21)
1293int(20)
1294int(19)
1295int(1)
1296int(2)
1297bool(false)
1298int(21)
1299int(5)
1300int(4)
1301int(3)
1302int(1)
1303int(2)
1304bool(false)
1305int(5)
1306Done