Annotation of embedaddon/php/tests/strings/001.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: String functions
3: --FILE--
4: <?php
5:
6: error_reporting(0);
7:
8: echo "Testing strtok: ";
9:
10: $str = "testing 1/2\\3";
11: $tok1 = strtok($str, " ");
12: $tok2 = strtok("/");
13: $tok3 = strtok("\\");
14: $tok4 = strtok(".");
15: if ($tok1 != "testing") {
16: echo("failed 1\n");
17: } elseif ($tok2 != "1") {
18: echo("failed 2\n");
19: } elseif ($tok3 != "2") {
20: echo("failed 3\n");
21: } elseif ($tok4 != "3") {
22: echo("failed 4\n");
23: } else {
24: echo("passed\n");
25: }
26:
27: echo "Testing strstr: ";
28: $test = "This is a test";
29: $found1 = strstr($test, 32);
30: $found2 = strstr($test, "a ");
31: if ($found1 != " is a test") {
32: echo("failed 1\n");
33: } elseif ($found2 != "a test") {
34: echo("failed 2\n");
35: } else {
36: echo("passed\n");
37: }
38:
39: echo "Testing strrchr: ";
40: $test = "fola fola blakken";
41: $found1 = strrchr($test, "b");
42: $found2 = strrchr($test, 102);
43: if ($found1 != "blakken") {
44: echo("failed 1\n");
45: } elseif ($found2 != "fola blakken") {
46: echo("failed 2\n");
47: }
48: else {
49: echo("passed\n");
50: }
51:
52: echo "Testing strtoupper: ";
53: $test = "abCdEfg";
54: $upper = strtoupper($test);
55: if ($upper == "ABCDEFG") {
56: echo("passed\n");
57: } else {
58: echo("failed!\n");
59: }
60:
61: echo "Testing strtolower: ";
62: $test = "ABcDeFG";
63: $lower = strtolower($test);
64: if ($lower == "abcdefg") {
65: echo("passed\n");
66: } else {
67: echo("failed!\n");
68: }
69:
70: echo "Testing substr: ";
71: $tests = $ok = 0;
72: $string = "string12345";
73: $tests++; if (substr($string, 2, 10) == "ring12345") { $ok++; }
74: $tests++; if (substr($string, 4, 7) == "ng12345") { $ok++; }
75: $tests++; if (substr($string, 4) == "ng12345") { $ok++; }
76: $tests++; if (substr($string, 10, 2) == "5") { $ok++; }
77: $tests++; if (substr($string, 6, 0) == "") { $ok++; }
78: $tests++; if (substr($string, -2, 2) == "45") { $ok++; }
79: $tests++; if (substr($string, 1, -1) == "tring1234") { $ok++; }
80: $tests++; if (substr($string, -1, -2) == "") { $ok++; }
81: $tests++; if (substr($string, -3, -2) == "3") { $ok++; }
82:
83: if ($tests == $ok) {
84: echo("passed\n");
85: } else {
86: echo("failed!\n");
87: }
88:
89: $raw = ' !"#$%&\'()*+,-./0123456789:;<=>?'
90: . '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'
91: . '`abcdefghijklmnopqrstuvwxyz{|}~'
92: . "\0";
93:
94: echo "Testing rawurlencode: ";
95: $encoded = rawurlencode($raw);
96: $correct = '%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F'
97: . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_'
98: . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~'
99: . '%00';
100: if ($encoded == $correct) {
101: echo("passed\n");
102: } else {
103: echo("failed!\n");
104: }
105:
106: echo "Testing rawurldecode: ";
107: $decoded = rawurldecode($correct);
108: if ($decoded == $raw) {
109: echo("passed\n");
110: } else {
111: echo("failed!\n");
112: }
113:
114: echo "Testing urlencode: ";
115: $encoded = urlencode($raw);
116: $correct = '+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F'
117: . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_'
118: . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E'
119: . '%00';
120: if ($encoded == $correct) {
121: echo("passed\n");
122: } else {
123: echo("failed!\n");
124: }
125:
126: echo "Testing urldecode: ";
127: $decoded = urldecode($correct);
128: if ($decoded == $raw) {
129: echo("passed\n");
130: } else {
131: echo("failed!\n");
132: }
133:
134: echo "Testing quotemeta: ";
135: $raw = "a.\\+*?" . chr(91) . "^" . chr(93) . "b\$c";
136: $quoted = quotemeta($raw);
137: if ($quoted == "a\\.\\\\\\+\\*\\?\\[\\^\\]b\\\$c") {
138: echo("passed\n");
139: } else {
140: echo("failed!\n");
141: }
142:
143: echo "Testing ufirst: ";
144: $str = "fahrvergnuegen";
145: $uc = ucfirst($str);
146: if ($uc == "Fahrvergnuegen") {
147: echo("passed\n");
148: } else {
149: echo("failed!\n");
150: }
151:
152: echo "Testing strtr: ";
153: $str = "test abcdefgh";
154: $tr = strtr($str, "def", "456");
155: if ($tr == "t5st abc456gh") {
156: echo("passed\n");
157: } else {
158: echo("failed!\n");
159: }
160:
161: echo "Testing addslashes: ";
162: $str = "\"\\'";
163: $as = addslashes($str);
164: if ($as == "\\\"\\\\\\'") {
165: echo("passed\n");
166: } else {
167: echo("failed!\n");
168: }
169:
170: echo "Testing stripslashes: ";
171: $str = "\$\\'";
172: $ss = stripslashes($str);
173: if ($ss == "\$'") {
174: echo("passed\n");
175: } else {
176: echo("failed!\n");
177: }
178:
179:
180: echo "Testing uniqid: ";
181: $str = "prefix";
182: $ui1 = uniqid($str);
183: $ui2 = uniqid($str);
184:
185: $len = strncasecmp(PHP_OS, 'CYGWIN', 6) ? 19 : 29;
186:
187: if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) {
188: echo("passed\n");
189: } else {
190: echo("failed!\n");
191: }
192:
193: ?>
194: --EXPECT--
195: Testing strtok: passed
196: Testing strstr: passed
197: Testing strrchr: passed
198: Testing strtoupper: passed
199: Testing strtolower: passed
200: Testing substr: passed
201: Testing rawurlencode: passed
202: Testing rawurldecode: passed
203: Testing urlencode: passed
204: Testing urldecode: passed
205: Testing quotemeta: passed
206: Testing ufirst: passed
207: Testing strtr: passed
208: Testing addslashes: passed
209: Testing stripslashes: passed
210: Testing uniqid: passed
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>