Annotation of embedaddon/php/ext/standard/tests/strings/strspn_variation6.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strspn() function : usage variations - with heredoc strings, varying mask & default start and len args
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: /*
13: * Testing strspn() : with heredoc string, varying mask and default start and len arguments
14: */
15:
16: echo "*** Testing strspn() : with different mask strings ***\n";
17:
18: // initialing required variables
19: // defining different heredoc strings
20: $empty_heredoc = <<<EOT
21: EOT;
22:
23: $heredoc_with_newline = <<<EOT
24: \n
25:
26: EOT;
27:
28: $heredoc_with_characters = <<<EOT
29: first line of heredoc string
30: second line of heredoc string
31: third line of heredocstring
32: EOT;
33:
34: $heredoc_with_newline_and_tabs = <<<EOT
35: hello\tworld\nhello\nworld\n
36: EOT;
37:
38: $heredoc_with_alphanumerics = <<<EOT
39: hello123world456
40: 1234hello\t1234
41: EOT;
42:
43: $heredoc_with_embedded_nulls = <<<EOT
44: hello\0world\0hello
45: \0hello\0
46: EOT;
47:
48: $heredoc_with_hexa_octal = <<<EOT
49: hello\0\100\xaaworld\0hello
50: \0hello\0
51: EOT;
52:
53: // defining array of different heredoc strings
54: $heredoc_strings = array(
55: $empty_heredoc,
56: $heredoc_with_newline,
57: $heredoc_with_characters,
58: $heredoc_with_newline_and_tabs,
59: $heredoc_with_alphanumerics,
60: $heredoc_with_embedded_nulls,
61: $heredoc_with_hexa_octal
62: );
63:
64: // defining array of different mask strings
65: $mask_array = array(
66: "",
67: '',
68: "fh\ne\trlsti \l",
69: 'fieh\n\trlsti \l',
70: "\t",
71: "lt\ ",
72: 'l\t',
73: "fl\t\eh ",
74: "l \te",
75: "lf\the\i\100\xaa"
76: );
77:
78:
79: // loop through each element of the array for different heredoc and mask strings
80:
81: $count = 1;
82:
83: foreach($heredoc_strings as $str) {
84: echo "\n-- Iteration $count --\n";
85: foreach($mask_array as $mask) {
86: var_dump( strspn($str,$mask) ); // with default start and len value
87: }
88: $count++;
89: }
90:
91: echo "Done"
92: ?>
93: --EXPECTF--
94: *** Testing strspn() : with different mask strings ***
95:
96: -- Iteration 1 --
97: int(0)
98: int(0)
99: int(0)
100: int(0)
101: int(0)
102: int(0)
103: int(0)
104: int(0)
105: int(0)
106: int(0)
107:
108: -- Iteration 2 --
109: int(0)
110: int(0)
111: int(2)
112: int(0)
113: int(0)
114: int(0)
115: int(0)
116: int(0)
117: int(0)
118: int(0)
119:
120: -- Iteration 3 --
121: int(0)
122: int(0)
123: int(8)
124: int(11)
125: int(0)
126: int(0)
127: int(0)
128: int(1)
129: int(0)
130: int(2)
131:
132: -- Iteration 4 --
133: int(0)
134: int(0)
135: int(4)
136: int(4)
137: int(0)
138: int(0)
139: int(0)
140: int(4)
141: int(0)
142: int(4)
143:
144: -- Iteration 5 --
145: int(0)
146: int(0)
147: int(4)
148: int(4)
149: int(0)
150: int(0)
151: int(0)
152: int(4)
153: int(0)
154: int(4)
155:
156: -- Iteration 6 --
157: int(0)
158: int(0)
159: int(4)
160: int(4)
161: int(0)
162: int(0)
163: int(0)
164: int(4)
165: int(0)
166: int(4)
167:
168: -- Iteration 7 --
169: int(0)
170: int(0)
171: int(4)
172: int(4)
173: int(0)
174: int(0)
175: int(0)
176: int(4)
177: int(0)
178: int(4)
179: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>