This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
s/\ba/./g was over-optimized
[perl5.git] / t / op / subst_amp.t
CommitLineData
f5c9036e
IZ
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib' if -d '../lib';
6 require Config; import Config;
7}
8
9print "1..13\n";
10
11$_ = 'x' x 20;
12s/\d*|x/<$&>/g;
13$foo = '<>' . ('<x><>' x 20) ;
14print ($_ eq $foo ? "ok 1\n" : "not ok 1\n#'$_'\n#'$foo'\n");
15
16$t = 'aaa';
17
18$_ = $t;
19@res = ();
20pos = 1;
21s/\Ga(?{push @res, $_, $`})/xx/g;
22print "not " unless "$_ @res" eq 'axxxx aaa a aaa aa';
23print "ok 2\n";
24
25$_ = $t;
26@res = ();
27pos = 1;
28s/\Ga(?{push @res, $_, $`})/x/g;
29print "not " unless "$_ @res" eq 'axx aaa a aaa aa';
30print "ok 3\n";
31
32$_ = $t;
33@res = ();
34pos = 1;
35s/\Ga(?{push @res, $_, $`})/xx/;
36print "not " unless "$_ @res" eq 'axxa aaa a';
37print "ok 4\n";
38
39$_ = $t;
40@res = ();
41pos = 1;
42s/\Ga(?{push @res, $_, $`})/x/;
43print "not " unless "$_ @res" eq 'axa aaa a';
44print "ok 5\n";
45
46$a = $t;
47@res = ();
48pos ($a) = 1;
49$a =~ s/\Ga(?{push @res, $_, $`})/xx/g;
50print "#'$a' '@res'\nnot " unless "$a @res" eq 'axxxx aaa a aaa aa';
51print "ok 6\n";
52
53$a = $t;
54@res = ();
55pos ($a) = 1;
56$a =~ s/\Ga(?{push @res, $_, $`})/x/g;
57print "#'$a' '@res'\nnot " unless "$a @res" eq 'axx aaa a aaa aa';
58print "ok 7\n";
59
60$a = $t;
61@res = ();
62pos ($a) = 1;
63$a =~ s/\Ga(?{push @res, $_, $`})/xx/;
64print "#'$a' '@res'\nnot " unless "$a @res" eq 'axxa aaa a';
65print "ok 8\n";
66
67$a = $t;
68@res = ();
69pos ($a) = 1;
70$a =~ s/\Ga(?{push @res, $_, $`})/x/;
71print "#'$a' '@res'\nnot " unless "$a @res" eq 'axa aaa a';
72print "ok 9\n";
73
74sub x2 {'xx'}
75sub x1 {'x'}
76
77$a = $t;
78@res = ();
79pos ($a) = 1;
80$a =~ s/\Ga(?{push @res, $_, $`})/x2/ge;
81print "#'$a' '@res'\nnot " unless "$a @res" eq 'axxxx aaa a aaa aa';
82print "ok 10\n";
83
84$a = $t;
85@res = ();
86pos ($a) = 1;
87$a =~ s/\Ga(?{push @res, $_, $`})/x1/ge;
88print "#'$a' '@res'\nnot " unless "$a @res" eq 'axx aaa a aaa aa';
89print "ok 11\n";
90
91$a = $t;
92@res = ();
93pos ($a) = 1;
94$a =~ s/\Ga(?{push @res, $_, $`})/x2/e;
95print "#'$a' '@res'\nnot " unless "$a @res" eq 'axxa aaa a';
96print "ok 12\n";
97
98$a = $t;
99@res = ();
100pos ($a) = 1;
101$a =~ s/\Ga(?{push @res, $_, $`})/x1/e;
102print "#'$a' '@res'\nnot " unless "$a @res" eq 'axa aaa a';
103print "ok 13\n";
104