Annotation of embedaddon/php/ext/standard/tests/file/fnmatch_variation.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test fnmatch() function: Variations
3: --SKIPIF--
4: <?php
5: if (!function_exists('fnmatch'))
6: die("skip fnmatch() function is not available");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype: bool fnmatch ( string $pattern, string $string [, int $flags] )
11: Description: fnmatch() checks if the passed string would match
12: the given shell wildcard pattern.
13: */
14:
15: echo "*** Testing fnmatch() with file and various patterns ***\n";
16: $file_name = dirname(__FILE__)."/match.tmp";
17:
18: /* avoid using \, it breaks the pattern */
19: if (substr(PHP_OS, 0, 3) == 'WIN') {
20: $file_name = str_replace('\\','/', $file_name);
21: }
22:
23: fopen($file_name, "w");
24:
25: $pattern_arr = array(
26: 0 => "*.tmp",
27: 1 => "match*",
28: 2 => "mat*",
29: 3 => "mat*tmp",
30: 4 => "m*t",
31: 5 => "ma[pt]ch*",
32: 6 => "*.t*",
33: 7 => "***.tmp",
34: 8 => "match**",
35: 9 => "*.t*p",
36: 10 => "",
37: 11 => "match",
38: 12 => ".tmp",
39: 13 => "?match",
40: 14 => "match?tmp",
41: 15 => "?tmp",
42: 16 => "match?",
43: 17 => "?match?",
44: 18 => "match.tmp",
45: 19 => "/match.tmp",
46: 20 => "/match.tmp/",
47: 21 => 'match.tmp',
48: 22 => 'match.tmp\0',
49: 23 => "match.tmp\0",
50: 24 => "match\0.tmp",
51: 25 => chr(109).chr(97)."tch.tmp",
52: 26 => chr(109).chr(97).chr(116).chr(99).chr(104).".tmp",
53: 27 => chr(109).chr(97).chr(116).chr(99).chr(104).chr(46).chr(116).chr(120).chr(116),
54: 28 => chr(109).chr(97).chr(116).chr(99).chr(104).".".chr(116).chr(120).chr(116),
55: 29 => "MATCH.TMP",
56: 30 => "MATCH*",
57: 31 => $file_name,
58:
59: /* binary inputs */
60: 32 => b"match*",
61: 33 => b"*.tmp",
62: 34 => b"mat*",
63: 35 => b"mat*tmp",
64: 36 => b"m*t",
65: );
66:
67: for( $i = 0; $i<count($pattern_arr); $i++ ) {
68: echo "-- Iteration $i --\n";
69: var_dump( fnmatch($pattern_arr[$i], $file_name) );
70: }
71: unlink($file_name);
72:
73:
74: echo "\n*** Testing fnmatch() with other types other than files ***";
75:
76: /* defining a common function */
77: function match( $pattern, $string ) {
78: for( $i = 0; $i<count($pattern); $i++ ) {
79: echo "-- Iteration $i --\n";
80: for( $j = 0; $j<count($string); $j++ ) {
81: var_dump( fnmatch($pattern[$i], $string[$j]) );
82: }
83: }
84: }
85:
86: echo "\n--- With Integers ---\n";
87: $int_arr = array(
88: 16,
89: 16.00,
90: 020,
91: 020.00,
92: 0xF,
93: 0xF0000
94: );
95: match($int_arr, $int_arr);
96:
97: echo "\n--- With Strings ---\n";
98: $str_arr = array(
99: "string",
100: "string\0",
101: 'string',
102: "str\0ing",
103: "stringstring",
104:
105: /* binary input */
106: b"string"
107: );
108: match($str_arr, $str_arr);
109:
110: echo "\n--- With booleans ---\n";
111: $bool_arr = array(
112: TRUE,
113: true,
114: 1,
115: 10,
116: FALSE,
117: false,
118: 0,
119: "",
120: "string"
121: );
122: match($bool_arr, $bool_arr);
123:
124: echo "\n--- With NULL ---\n";
125: $null_arr = array(
126: NULL,
127: null,
128: "",
129: "\0",
130: "string",
131: 0
132: );
133: match($null_arr, $null_arr);
134:
135: echo "\n*** Done ***\n";
136: ?>
1.1.1.2 ! misho 137: --EXPECTF--
1.1 misho 138: *** Testing fnmatch() with file and various patterns ***
139: -- Iteration 0 --
140: bool(true)
141: -- Iteration 1 --
142: bool(false)
143: -- Iteration 2 --
144: bool(false)
145: -- Iteration 3 --
146: bool(false)
147: -- Iteration 4 --
148: bool(false)
149: -- Iteration 5 --
150: bool(false)
151: -- Iteration 6 --
152: bool(true)
153: -- Iteration 7 --
154: bool(true)
155: -- Iteration 8 --
156: bool(false)
157: -- Iteration 9 --
158: bool(true)
159: -- Iteration 10 --
160: bool(false)
161: -- Iteration 11 --
162: bool(false)
163: -- Iteration 12 --
164: bool(false)
165: -- Iteration 13 --
166: bool(false)
167: -- Iteration 14 --
168: bool(false)
169: -- Iteration 15 --
170: bool(false)
171: -- Iteration 16 --
172: bool(false)
173: -- Iteration 17 --
174: bool(false)
175: -- Iteration 18 --
176: bool(false)
177: -- Iteration 19 --
178: bool(false)
179: -- Iteration 20 --
180: bool(false)
181: -- Iteration 21 --
182: bool(false)
183: -- Iteration 22 --
184: bool(false)
185: -- Iteration 23 --
1.1.1.2 ! misho 186:
! 187: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 188: NULL
1.1 misho 189: -- Iteration 24 --
1.1.1.2 ! misho 190:
! 191: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 192: NULL
1.1 misho 193: -- Iteration 25 --
194: bool(false)
195: -- Iteration 26 --
196: bool(false)
197: -- Iteration 27 --
198: bool(false)
199: -- Iteration 28 --
200: bool(false)
201: -- Iteration 29 --
202: bool(false)
203: -- Iteration 30 --
204: bool(false)
205: -- Iteration 31 --
206: bool(true)
207: -- Iteration 32 --
208: bool(false)
209: -- Iteration 33 --
210: bool(true)
211: -- Iteration 34 --
212: bool(false)
213: -- Iteration 35 --
214: bool(false)
215: -- Iteration 36 --
216: bool(false)
217:
218: *** Testing fnmatch() with other types other than files ***
219: --- With Integers ---
220: -- Iteration 0 --
221: bool(true)
222: bool(true)
223: bool(true)
224: bool(false)
225: bool(false)
226: bool(false)
227: -- Iteration 1 --
228: bool(true)
229: bool(true)
230: bool(true)
231: bool(false)
232: bool(false)
233: bool(false)
234: -- Iteration 2 --
235: bool(true)
236: bool(true)
237: bool(true)
238: bool(false)
239: bool(false)
240: bool(false)
241: -- Iteration 3 --
242: bool(false)
243: bool(false)
244: bool(false)
245: bool(true)
246: bool(false)
247: bool(false)
248: -- Iteration 4 --
249: bool(false)
250: bool(false)
251: bool(false)
252: bool(false)
253: bool(true)
254: bool(false)
255: -- Iteration 5 --
256: bool(false)
257: bool(false)
258: bool(false)
259: bool(false)
260: bool(false)
261: bool(true)
262:
263: --- With Strings ---
264: -- Iteration 0 --
265: bool(true)
1.1.1.2 ! misho 266:
! 267: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 268: NULL
1.1 misho 269: bool(true)
1.1.1.2 ! misho 270:
! 271: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 272: NULL
1.1 misho 273: bool(false)
274: bool(true)
275: -- Iteration 1 --
1.1.1.2 ! misho 276:
! 277: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 278: NULL
! 279:
! 280: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 281: NULL
! 282:
! 283: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 284: NULL
! 285:
! 286: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 287: NULL
! 288:
! 289: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 290: NULL
! 291:
! 292: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 293: NULL
1.1 misho 294: -- Iteration 2 --
295: bool(true)
1.1.1.2 ! misho 296:
! 297: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 298: NULL
1.1 misho 299: bool(true)
1.1.1.2 ! misho 300:
! 301: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 302: NULL
1.1 misho 303: bool(false)
304: bool(true)
305: -- Iteration 3 --
1.1.1.2 ! misho 306:
! 307: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 308: NULL
! 309:
! 310: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 311: NULL
! 312:
! 313: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 314: NULL
! 315:
! 316: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 317: NULL
! 318:
! 319: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 320: NULL
! 321:
! 322: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 323: NULL
1.1 misho 324: -- Iteration 4 --
325: bool(false)
1.1.1.2 ! misho 326:
! 327: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 328: NULL
1.1 misho 329: bool(false)
1.1.1.2 ! misho 330:
! 331: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 332: NULL
1.1 misho 333: bool(true)
334: bool(false)
335: -- Iteration 5 --
336: bool(true)
1.1.1.2 ! misho 337:
! 338: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 339: NULL
1.1 misho 340: bool(true)
1.1.1.2 ! misho 341:
! 342: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 343: NULL
1.1 misho 344: bool(false)
345: bool(true)
346:
347: --- With booleans ---
348: -- Iteration 0 --
349: bool(true)
350: bool(true)
351: bool(true)
352: bool(false)
353: bool(false)
354: bool(false)
355: bool(false)
356: bool(false)
357: bool(false)
358: -- Iteration 1 --
359: bool(true)
360: bool(true)
361: bool(true)
362: bool(false)
363: bool(false)
364: bool(false)
365: bool(false)
366: bool(false)
367: bool(false)
368: -- Iteration 2 --
369: bool(true)
370: bool(true)
371: bool(true)
372: bool(false)
373: bool(false)
374: bool(false)
375: bool(false)
376: bool(false)
377: bool(false)
378: -- Iteration 3 --
379: bool(false)
380: bool(false)
381: bool(false)
382: bool(true)
383: bool(false)
384: bool(false)
385: bool(false)
386: bool(false)
387: bool(false)
388: -- Iteration 4 --
389: bool(false)
390: bool(false)
391: bool(false)
392: bool(false)
393: bool(true)
394: bool(true)
395: bool(false)
396: bool(true)
397: bool(false)
398: -- Iteration 5 --
399: bool(false)
400: bool(false)
401: bool(false)
402: bool(false)
403: bool(true)
404: bool(true)
405: bool(false)
406: bool(true)
407: bool(false)
408: -- Iteration 6 --
409: bool(false)
410: bool(false)
411: bool(false)
412: bool(false)
413: bool(false)
414: bool(false)
415: bool(true)
416: bool(false)
417: bool(false)
418: -- Iteration 7 --
419: bool(false)
420: bool(false)
421: bool(false)
422: bool(false)
423: bool(true)
424: bool(true)
425: bool(false)
426: bool(true)
427: bool(false)
428: -- Iteration 8 --
429: bool(false)
430: bool(false)
431: bool(false)
432: bool(false)
433: bool(false)
434: bool(false)
435: bool(false)
436: bool(false)
437: bool(true)
438:
439: --- With NULL ---
440: -- Iteration 0 --
441: bool(true)
442: bool(true)
443: bool(true)
1.1.1.2 ! misho 444:
! 445: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 446: NULL
1.1 misho 447: bool(false)
448: bool(false)
449: -- Iteration 1 --
450: bool(true)
451: bool(true)
452: bool(true)
1.1.1.2 ! misho 453:
! 454: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 455: NULL
1.1 misho 456: bool(false)
457: bool(false)
458: -- Iteration 2 --
459: bool(true)
460: bool(true)
461: bool(true)
1.1.1.2 ! misho 462:
! 463: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 464: NULL
1.1 misho 465: bool(false)
466: bool(false)
467: -- Iteration 3 --
1.1.1.2 ! misho 468:
! 469: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 470: NULL
! 471:
! 472: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 473: NULL
! 474:
! 475: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 476: NULL
! 477:
! 478: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 479: NULL
! 480:
! 481: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 482: NULL
! 483:
! 484: Warning: fnmatch() expects parameter 1 to be a valid path, string given in %s on line %d
! 485: NULL
1.1 misho 486: -- Iteration 4 --
487: bool(false)
488: bool(false)
489: bool(false)
1.1.1.2 ! misho 490:
! 491: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 492: NULL
1.1 misho 493: bool(true)
494: bool(false)
495: -- Iteration 5 --
496: bool(false)
497: bool(false)
498: bool(false)
1.1.1.2 ! misho 499:
! 500: Warning: fnmatch() expects parameter 2 to be a valid path, string given in %s on line %d
! 501: NULL
1.1 misho 502: bool(false)
503: bool(true)
504:
505: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>