Drop all the unnecessary "use utf8" clauses and some of
[p5sagit/p5-mst-13.2.git] / t / op / study.t
CommitLineData
378cc40b 1#!./perl
2
27c93d93 3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
378cc40b 7
0dec986a 8print "1..26\n";
378cc40b 9
10$x = "abc\ndef\n";
11study($x);
12
13if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
14if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
15
16$* = 1;
17if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
18$* = 0;
19
20$_ = '123';
21study;
22if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
23
24if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
25if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
26
27if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
28if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
29
30study($x);
31if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
32if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
33
34if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
35if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
36
37$_ = 'aaabbbccc';
38study;
39if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
40 print "ok 13\n";
41} else {
42 print "not ok 13\n";
43}
44if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
45 print "ok 14\n";
46} else {
47 print "not ok 14\n";
48}
49
50if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
51
52$_ = 'aaabccc';
53study;
54if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
55if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
56
57$_ = 'aaaccc';
58study;
59if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
60if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
61
62$_ = 'abcdef';
63study;
64if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
65if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
66
67if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
68
69if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
70
71$* = 1; # test 3 only tested the optimized version--this one is for real
72if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
0dec986a 73
51153910 74if ($^O eq 'os390') {
75 # Even with the alarm() OS/390 can't manage these tests
76 # (Perl just goes into a busy loop, luckily an interruptable one)
77 for (25..26) { print "not ok $_ # compiler bug?\n" }
78} else {
79 # [ID 20010618.006] tests 25..26 may loop
0dec986a 80 use Config;
27c93d93 81 my $have_alarm = $Config{d_alarm};
82 local $SIG{ALRM} = sub { die "timeout\n" };
83
84 $_ = 'FGF';
85 study;
86 my $ok = $have_alarm
87 ? eval { alarm(2); my $match = /G.F$/; alarm(0); !$match }
88 : eval { !/G.F$/ };
89 if ($ok && !$@) {
90 print "ok 25\n";
91 } else {
92 print "not ok 25\t# " . $@ || "should not match\n";
93 }
94 $ok = $have_alarm
95 ? eval { alarm(2); my $match = /[F]F$/; alarm(0); !$match }
96 : eval { !/[F]F$/ };
97 if ($ok && !$@) {
98 print "ok 26\n";
0dec986a 99 } else {
27c93d93 100 print "not ok 26\t# " . $@ || "should not match\n";
0dec986a 101 }
102}
51153910 103