Small optimisations, by Brandon Black
[p5sagit/p5-mst-13.2.git] / t / op / rxcode.t
CommitLineData
19842e53 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
72e9e8b1 9plan tests => 38;
768bc71f 10
11$^R = undef;
12like( 'a', qr/^a(?{1})(?:b(?{2}))?/, 'a =~ ab?' );
13cmp_ok( $^R, '==', 1, '..$^R after a =~ ab?' );
14
15$^R = undef;
16unlike( 'abc', qr/^a(?{3})(?:b(?{4}))$/, 'abc !~ a(?:b)$' );
17ok( !defined $^R, '..$^R after abc !~ a(?:b)$' );
18
19$^R = undef;
20like( 'ab', qr/^a(?{5})b(?{6})/, 'ab =~ ab' );
21cmp_ok( $^R, '==', 6, '..$^R after ab =~ ab' );
22
23$^R = undef;
24like( 'ab', qr/^a(?{7})(?:b(?{8}))?/, 'ab =~ ab?' );
25
72e9e8b1 26cmp_ok( $^R, '==', 8, '..$^R after ab =~ ab?' );
768bc71f 27
28$^R = undef;
29like( 'ab', qr/^a(?{9})b?(?{10})/, 'ab =~ ab? (2)' );
30cmp_ok( $^R, '==', 10, '..$^R after ab =~ ab? (2)' );
31
32$^R = undef;
33like( 'ab', qr/^(a(?{11})(?:b(?{12})))?/, 'ab =~ (ab)? (3)' );
72e9e8b1 34cmp_ok( $^R, '==', 12, '..$^R after ab =~ ab? (3)' );
768bc71f 35
36$^R = undef;
37unlike( 'ac', qr/^a(?{13})b(?{14})/, 'ac !~ ab' );
38ok( !defined $^R, '..$^R after ac !~ ab' );
39
40$^R = undef;
41like( 'ac', qr/^a(?{15})(?:b(?{16}))?/, 'ac =~ ab?' );
42cmp_ok( $^R, '==', 15, '..$^R after ac =~ ab?' );
43
44my @ar;
45like( 'ab', qr/^a(?{push @ar,101})(?:b(?{push @ar,102}))?/, 'ab =~ ab? with code push' );
46cmp_ok( scalar(@ar), '==', 2, '..@ar pushed' );
47cmp_ok( $ar[0], '==', 101, '..first element pushed' );
48cmp_ok( $ar[1], '==', 102, '..second element pushed' );
49
50$^R = undef;
51unlike( 'a', qr/^a(?{103})b(?{104})/, 'a !~ ab with code push' );
52ok( !defined $^R, '..$^R after a !~ ab with code push' );
53
54@ar = ();
55unlike( 'a', qr/^a(?{push @ar,105})b(?{push @ar,106})/, 'a !~ ab (push)' );
56cmp_ok( scalar(@ar), '==', 0, '..nothing pushed' );
57
58@ar = ();
59unlike( 'abc', qr/^a(?{push @ar,107})b(?{push @ar,108})$/, 'abc !~ ab$ (push)' );
60cmp_ok( scalar(@ar), '==', 0, '..still nothing pushed' );
61
62use vars '@var';
63
64like( 'ab', qr/^a(?{push @var,109})(?:b(?{push @var,110}))?/, 'ab =~ ab? push to package var' );
65cmp_ok( scalar(@var), '==', 2, '..@var pushed' );
66cmp_ok( $var[0], '==', 109, '..first element pushed (package)' );
67cmp_ok( $var[1], '==', 110, '..second element pushed (package)' );
68
69@var = ();
70unlike( 'a', qr/^a(?{push @var,111})b(?{push @var,112})/, 'a !~ ab (push package var)' );
71cmp_ok( scalar(@var), '==', 0, '..nothing pushed (package)' );
72
73@var = ();
74unlike( 'abc', qr/^a(?{push @var,113})b(?{push @var,114})$/, 'abc !~ ab$ (push package var)' );
75cmp_ok( scalar(@var), '==', 0, '..still nothing pushed (package)' );
76
72e9e8b1 77{
78 local $^R = undef;
79 ok( 'ac' =~ /^a(?{30})(?:b(?{31})|c(?{32}))?/, 'ac =~ a(?:b|c)?' );
80 ok( $^R == 32, '$^R == 32' );
81}
82{
83 local $^R = undef;
84 ok( 'abbb' =~ /^a(?{36})(?:b(?{37})|c(?{38}))+/, 'abbbb =~ a(?:b|c)+' );
85 ok( $^R == 37, '$^R == 37' ) or print "# \$^R=$^R\n";
86}