1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#!./perl -w
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
}
watchdog(10);
plan(tests => 43);
use strict;
use vars '$x';
use Config;
my $have_alarm = $Config{d_alarm};
$x = "abc\ndef\n";
study($x);
ok($x =~ /^abc/);
ok($x !~ /^def/);
# used to be a test for $*
ok($x =~ /^def/m);
$_ = '123';
study;
ok(/^([0-9][0-9]*)/);
ok(!($x =~ /^xxx/));
ok(!($x !~ /^abc/));
ok($x =~ /def/);
ok(!($x !~ /def/));
study($x);
ok($x !~ /.def/);
ok(!($x =~ /.def/));
ok($x =~ /\ndef/);
ok(!($x !~ /\ndef/));
$_ = 'aaabbbccc';
study;
ok(/(a*b*)(c*)/);
is($1, 'aaabbb');
is($2,'ccc');
ok(/(a+b+c+)/);
is($1, 'aaabbbccc');
ok(!/a+b?c+/);
$_ = 'aaabccc';
study;
ok(/a+b?c+/);
ok(/a*b+c*/);
$_ = 'aaaccc';
study;
ok(/a*b?c*/);
ok(!/a*b+c*/);
$_ = 'abcdef';
study;
ok(/bcd|xyz/);
ok(/xyz|bcd/);
ok(m|bc/*d|);
ok(/^$_$/);
# used to be a test for $*
ok("ab\ncd\n" =~ /^cd/m);
TODO: {
# Even with the alarm() OS/390 and BS2000 can't manage these tests
# (Perl just goes into a busy loop, luckily an interruptable one)
todo_skip('busy loop - compiler bug?', 2)
if $^O eq 'os390' or $^O eq 'posix-bc';
# [ID ] tests 25..26 may loop
$_ = 'FGF';
study;
ok(!/G.F$/, 'bug 20010618.006');
ok(!/[F]F$/, 'bug 20010618.006');
}
{
my $a = 'QaaQaabQaabbQ';
study $a;
my @a = split /aab*/, $a;
is("@a", 'Q Q Q Q', 'split with studied string passed to the regep engine');
}
{
$_ = "AABBAABB";
study;
is(s/AB+/1/ge, 2, 'studied scalar passed to pp_substconst');
is($_, 'A1A1');
}
{
$_ = "AABBAABB";
study;
is(s/(A)B+/1/ge, 2,
'studied scalar passed to pp_substconst with RX_MATCH_COPIED() true');
is($1, 'A');
is($2, undef);
is($_, 'A1A1');
}
{
my @got;
$a = "ydydydyd";
$b = "xdx";
push @got, $_ foreach $a =~ /[^x]d(?{})[^x]d/g;
is("@got", 'ydyd ydyd', '#92696 control');
@got = ();
$a = "ydydydyd";
$b = "xdx";
study $a;
push @got, $_ foreach $a =~ /[^x]d(?{})[^x]d/g;
is("@got", 'ydyd ydyd', '#92696 study $a');
@got = ();
$a = "ydydydyd";
$b = "xdx";
study $b;
push @got, $_ foreach $a =~ /[^x]d(?{})[^x]d/g;
is("@got", 'ydyd ydyd', '#92696 study $b');
@got = ();
$a = "ydydydyd";
$b = "xdx";
push @got, $_ foreach $a =~ /[^x]d(?{study $b})[^x]d/g;
is("@got", 'ydyd ydyd', '#92696 study $b inside (?{}), nothing studied');
@got = ();
$a = "ydydydyd";
$b = "xdx";
my $c = 'zz';
study $c;
push @got, $_ foreach $a =~ /[^x]d(?{study $b})[^x]d/g;
is("@got", 'ydyd ydyd', '#92696 study $b inside (?{}), $c studied');
@got = ();
$a = "ydydydyd";
$b = "xdx";
study $a;
push @got, $_ foreach $a =~ /[^x]d(?{study $b})[^x]d/g;
is("@got", 'ydyd ydyd', '#92696 study $b inside (?{}), $a studied');
@got = ();
$a = "ydydydyd";
$b = "xdx";
study $a;
push @got, $_ foreach $a =~ /[^x]d(?{$a .= ''})[^x]d/g;
is("@got", 'ydyd ydyd', '#92696 $a .= \'\' inside (?{}), $a studied');
}
|