3 # Test scoping issues with embedded code in regexps.
5 BEGIN { chdir 't'; @INC = qw "lib ../lib"; require './test.pl' }
9 # Functions for turning to-do-ness on and off (as there are so many
11 sub on { $::TODO = "(?{}) implementation is screwy" }
12 sub off { undef $::TODO }
16 fresh_perl_is <<'CODE', '7817', {}, '(?{}) has its own lexical scope';
17 my $x = 7; print "a" =~ /(?{ print $x; my $x = 8; print $x; my $y })a/;
21 fresh_perl_is <<'CODE',
28 a (?{ print $y; local $y = $y+1; print $x; my $x = 8; print $x })
29 b (?{ print $y; local $y = $y+1; print $x; my $x = 9; print $x })
30 c (?{ print $y; local $y = $y+1; print $x; my $x = 10; print $x })
36 '1a82a93a104a85a96a101a 1b82b93b104b85b96b101b 1c82c93c104c85c96c101c ',
38 'multiple (?{})s in loop with lexicals';
40 fresh_perl_is <<'CODE', '7817', {}, 'run-time re-eval has its own scope';
41 my $x = 7; print "a" =~ /(?{ print $x; my $x = 8; print $x; my $y })a/;
45 fresh_perl_is <<'CODE', '1782793710478579671017', {},
52 a (?{ print $y; local $y = $y+1; print $x; my $x = 8; print $x })
53 b (?{ print $y; local $y = $y+1; print $x; my $x = 9; print $x })
54 c (?{ print $y; local $y = $y+1; print $x; my $x = 10; print $x })
59 'multiple (?{})s in "foo" =~ $string';
61 fresh_perl_is <<'CODE', '1782793710478579671017', {},
68 a (?{ print $y; local $y = $y+1; print $x; my $x = 8; print $x })
69 b (?{ print $y; local $y = $y+1; print $x; my $x = 9; print $x })
70 c (?{ print $y; local $y = $y+1; print $x; my $x = 10; print $x })
75 'multiple (?{})s in "foo" =~ /$string/x';
77 fresh_perl_is <<'CODE', '123123', {},
79 push @regexps = qr/(?{ print $x })a/;
81 "a" =~ $_ for @regexps;
82 "ba" =~ /b$_/ for @regexps;
84 'qr/(?{})/ is a closure';
88 "a" =~ do { package foo; qr/(?{ $::pack = __PACKAGE__ })a/ };
89 is $pack, 'foo', 'qr// inherits package';
90 "a" =~ do { use re "/x"; qr/(?{ $::re = qr-- })a/ };
91 is $re, '(?^x:)', 'qr// inherits pragmata';
95 "ba" =~ /b${\do { package baz; qr|(?{ $::pack = __PACKAGE__ })a| }}/;
96 is $pack, 'baz', '/text$qr/ inherits package';
97 "ba" =~ m+b${\do { use re "/i"; qr|(?{ $::re = qr-- })a| }}+;
98 is $re, '(?^i:)', '/text$qr/ inherits pragmata';
104 "ba" =~ /${\'(?{ $::pack = __PACKAGE__ })a'}/;
106 is $pack, 'bar', '/$text/ containing (?{}) inherits package';
109 "ba" =~ /${\'(?{ $::re = qr -- })a'}/;
111 is $re, '(?^m:)', '/$text/ containing (?{}) inherits pragmata';
115 fresh_perl_is <<'CODE', 'ok', { stderr => 1 }, '(?{die})';
116 eval { "a" =~ /(?{die})a/ }; print "ok"
118 fresh_perl_is <<'CODE', 'ok', { stderr => 1 }, '(?{last})';
119 { "a" =~ /(?{last})a/ }; print "ok"
121 fresh_perl_is <<'CODE', 'ok', { stderr => 1 }, '(?{next})';
122 { "a" =~ /(?{last})a/ }; print "ok"
124 fresh_perl_is <<'CODE', 'ok', { stderr => 1 }, '(?{return})';
125 print sub { "a" =~ /(?{return "ok"})a/ }->();
127 fresh_perl_is <<'CODE', 'ok', { stderr => 1 }, '(?{goto})';
128 "a" =~ /(?{goto _})a/; die; _: print "ok"