8 print "#1\t:$_: eq :\$x:\n";
9 if ($_ eq '$x') {print "ok 1\n";} else {print "not ok 1\n";}
13 print "#2\t:$_: eq :foo:\n";
14 if ($_ eq 'foo') {print "ok 2\n";} else {print "not ok 2\n";}
18 print "#3\t:$_: eq :\$x foo:\n";
19 if ($_ eq '$x foo') {print "ok 3\n";} else {print "not ok 3\n";}
22 ($a = 'abcdef') =~ s<(b${b}e)>'\n$1';
23 print "#4\t:$1: eq :bcde:\n";
24 print "#4\t:$a: eq :a\\n\$1f:\n";
25 if ($1 eq 'bcde' && $a eq 'a\n$1f') {print "ok 4\n";} else {print "not ok 4\n";}
28 if (($a =~ s/a/x/g) == 4 && $a eq 'xbxcxdx')
29 {print "ok 5\n";} else {print "not ok 5\n";}
31 if (($a =~ s/a/y/g) == 0 && $a eq 'xbxcxdx')
32 {print "ok 6\n";} else {print "not ok 6 $a\n";}
34 if (($a =~ s/b/y/g) == 1 && $a eq 'xyxcxdx')
35 {print "ok 7\n";} else {print "not ok 7 $a\n";}
38 if (/a/i && s///gi && $_ eq 'BCD') {print "ok 8\n";} else {print "not ok 8 $_\n";}
41 if (length($_) == 4) {print "ok 9\n";} else {print "not ok 9\n";}
43 if ($_ eq '\\' x 8) {print "ok 10\n";} else {print "not ok 10 $_\n";}
46 if (length($_) == 8) {print "ok 11\n";} else {print "not ok 11\n";}
48 if ($_ eq '\\//' x 4) {print "ok 12\n";} else {print "not ok 12\n";}
49 if (length($_) == 12) {print "ok 13\n";} else {print "not ok 13\n";}
53 print $_ eq 'aaXXXXbbb' ? "ok 14\n" : "not ok 14\n";
57 print $_ eq 'aaXXXXbbb' ? "ok 15\n" : "not ok 15\n";
61 print $_ eq 'baaXXXXbbb' ? "ok 16\n" : "not ok 16\n";
65 print $_ eq 'baaXXXXbbb' ? "ok 17\n" : "not ok 17\n";
69 print $_ eq 'aXXXXbbb' ? "ok 18\n" : "not ok 18\n";
73 print $_ eq 'baXXXXbbb' ? "ok 19\n" : "not ok 19\n";
77 print $_ eq 'aaaXXXXbb' ? "ok 20\n" : "not ok 20\n";
81 print $_ eq 'aaaXXXXbb' ? "ok 21\n" : "not ok 21\n";
85 print $_ eq 'aaaXXXXb' ? "ok 22\n" : "not ok 22\n";
89 print $_ eq 'aayXXXbbb' ? "ok 23\n" : "not ok 23\n";
93 print $_ eq 'aaaXXXzbb' ? "ok 24\n" : "not ok 24\n";
97 print $_ eq 'ab' ? "ok 25\n" : "not ok 25\n";
101 print $_ eq 'aaaXXXXxb' ? "ok 26\n" : "not ok 26\n";
103 # now for some unoptimized versions of the same.
107 print $_ eq 'aaXXXXbbb' ? "ok 27\n" : "not ok 27\n";
111 print $_ eq 'aaXXXXbbb' ? "ok 28\n" : "not ok 28\n";
115 print $_ eq 'baaXXXXbbb' ? "ok 29\n" : "not ok 29\n";
119 print $_ eq 'baaXXXXbbb' ? "ok 30\n" : "not ok 30\n";
123 print $_ eq 'aXXXXbbb' ? "ok 31\n" : "not ok 31\n";
127 print $_ eq 'baXXXXbbb' ? "ok 32\n" : "not ok 32\n";
131 print $_ eq 'aaaXXXXbb' ? "ok 33\n" : "not ok 33\n";
135 print $_ eq 'aaaXXXXbb' ? "ok 34\n" : "not ok 34\n";
139 print $_ eq 'aaaXXXXb' ? "ok 35\n" : "not ok 35\n";
143 print $_ eq 'aayXXXbbb' ? "ok 36\n" : "not ok 36\n";
147 print $_ eq 'aaaXXXzbb' ? "ok 37\n" : "not ok 37\n";
150 $x ne $x || s/aaX.*Xbb//;
151 print $_ eq 'ab' ? "ok 38\n" : "not ok 38\n";
155 print $_ eq 'aaaXXXXxb' ? "ok 39\n" : "not ok 39\n";
158 s/(\d+)/$1*2/e; # yields 'abc246xyz'
159 print $_ eq 'abc246xyz' ? "ok 40\n" : "not ok 40\n";
160 s/(\d+)/sprintf("%5d",$1)/e; # yields 'abc 246xyz'
161 print $_ eq 'abc 246xyz' ? "ok 41\n" : "not ok 41\n";
162 s/(\w)/$1 x 2/eg; # yields 'aabbcc 224466xxyyzz'
163 print $_ eq 'aabbcc 224466xxyyzz' ? "ok 42\n" : "not ok 42\n";
166 print y/a/b/ == 5 ? "ok 43\n" : "not ok 43\n";
167 print y/a/b/ == 0 ? "ok 44\n" : "not ok 44\n";
168 print y/b// == 5 ? "ok 45\n" : "not ok 45\n";
169 print y/b/c/s == 5 ? "ok 46\n" : "not ok 46\n";
170 print y/c// == 1 ? "ok 47\n" : "not ok 47\n";
171 print y/c//d == 1 ? "ok 48\n" : "not ok 48\n";
172 print $_ eq "" ? "ok 49\n" : "not ok 49\n";
174 $_ = "Now is the %#*! time for all good men...";
175 print (($x=(y/a-zA-Z //cd)) == 7 ? "ok 50\n" : "not ok 50\n");
176 print y/ / /s == 8 ? "ok 51\n" : "not ok 51\n";
178 $_ = 'abcdefghijklmnopqrstuvwxyz0123456789';
181 print $_ eq 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ? "ok 52\n" : "not ok 52\n";
183 # same as tr/A-Z/a-z/;
184 if ($^O eq 'os390') { # An EBCDIC variant.
186 y[\301-\351][\201-\251];
187 } else { # Ye Olde ASCII. Or something like it.
188 y[\101-\132][\141-\172];
191 print $_ eq 'abcdefghijklmnopqrstuvwxyz0123456789' ? "ok 53\n" : "not ok 53\n";
193 if (ord("+") == ord(",") - 1 && ord(",") == ord("-") - 1 &&
194 ord("a") == ord("b") - 1 && ord("b") == ord("c") - 1) {
197 print "not " unless $_ eq 'abc';
203 print $_ eq 'a,/' ? "ok 55\n" : "not ok 55\n";
207 print $_ eq 'b-a' ? "ok 56\n" : "not ok 56\n";
210 # test recursive substitutions
211 # code based on the recursive expansion of makefile variables
214 AAAAA => '$(B)', B=>'$(C)', C => 'D', # long->short
215 E => '$(F)', F=>'p $(G) q', G => 'HHHHH', # short->long
216 DIR => '$(UNDEFINEDNAME)/xxx',
219 my($var,$level) = @_;
220 return "\$($var)" unless exists $MK{$var};
221 return exp_vars($MK{$var}, $level+1); # can recurse
224 my($str,$level) = @_;
225 $str =~ s/\$\((\w+)\)/var($1, $level+1)/ge; # can recurse
226 #warn "exp_vars $level = '$str'\n";
230 print exp_vars('$(AAAAA)',0) eq 'D'
231 ? "ok 57\n" : "not ok 57\n";
232 print exp_vars('$(E)',0) eq 'p HHHHH q'
233 ? "ok 58\n" : "not ok 58\n";
234 print exp_vars('$(DIR)',0) eq '$(UNDEFINEDNAME)/xxx'
235 ? "ok 59\n" : "not ok 59\n";
236 print exp_vars('foo $(DIR)/yyy bar',0) eq 'foo $(UNDEFINEDNAME)/xxx/yyy bar'
237 ? "ok 60\n" : "not ok 60\n";
239 # a match nested in the RHS of a substitution:
242 s/(..)/$x = $1, m#.#/eg;
243 print $x eq "cd" ? "ok 61\n" : "not ok 61\n";
245 # Subst and lookbehind
249 print $_ eq "xxxxx" ? "ok 62\n" : "not ok 62 # `$_' ne `xxxxx'\n";
253 print $_ eq "xxxxx" ? "ok 63\n" : "not ok 63 # `$_' ne `xxxxx'\n";
256 s/(?<!r)foobbar/foobar/g;
257 print $_ eq "foobarfoobbar" ? "ok 64\n" : "not ok 64 # `$_' ne `foobarfoobbar'\n";
260 s/(?<!ar)(foobbar)/foobar/g;
261 print $_ eq "foobarfoobbar" ? "ok 65\n" : "not ok 65 # `$_' ne `foobarfoobbar'\n";
264 s/(?<!ar)foobbar/foobar/g;
265 print $_ eq "foobarfoobbar" ? "ok 66\n" : "not ok 66 # `$_' ne `foobarfoobbar'\n";
267 # check parsing of split subst with comment
268 eval 's{foo} # this is a comment, not a delimiter
270 print @? ? "not ok 67\n" : "ok 67\n";
272 # check if squashing works at the end of string
275 print $_ eq "bbcbb" ? "ok 68\n" : "not ok 68 # `$_' ne `bbcbb'\n";
277 # XXX TODO: Most tests above don't test return values of the ops. They should.
279 print (s/a/b/ == 1 ? "ok 69\n" : "not ok 69\n");
282 $url = new URI::URL "http://www/"; die if $url eq "xXx";
286 $foo = ' $@%#lowercase $@%# lowercase UPPERCASE$@%#UPPERCASE' .
287 ' $@%#lowercase$@%#lowercase$@%# lowercase lowercase $@%#lowercase' .
288 ' lowercase $@%#MiXeD$@%# ';
290 s{ \d+ \b [,.;]? (?{ 'digits' })
292 [a-z]+ \b [,.;]? (?{ 'lowercase' })
294 [A-Z]+ \b [,.;]? (?{ 'UPPERCASE' })
296 [A-Z] [a-z]+ \b [,.;]? (?{ 'Capitalized' })
298 [A-Za-z]+ \b [,.;]? (?{ 'MiXeD' })
300 [A-Za-z0-9]+ \b [,.;]? (?{ 'alphanumeric' })
304 [^A-Za-z0-9\s]+ (?{ '$@%#' })
306 print ($_ eq $foo ? "ok 70\n" : "not ok 70\n#'$_'\n#'$foo'\n");
310 $foo = '<>' . ('<x><>' x 20) ;
311 print ($_ eq $foo ? "ok 71\n" : "not ok 71\n#'$_'\n#'$foo'\n");