This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handle bracket stack better in recdescent parsing
[perl5.git] / ext / XS-APItest / t / scopelessblock.t
1 use warnings;
2 use strict;
3
4 use Test::More tests => 18;
5
6 BEGIN { $^H |= 0x20000; }
7
8 my $t;
9
10 $t = "";
11 eval q{
12         use XS::APItest qw(scopelessblock);
13         $t .= "a";
14         scopelessblock {
15                 $t .= "b";
16         }
17         $t .= "c";
18 };
19 is $@, "";
20 is $t, "abc";
21
22 $t = "";
23 eval q{
24         use XS::APItest qw(scopelessblock);
25         $t .= "a";
26         scopelessblock {
27                 my $t = "z";
28                 $t .= "b";
29         }
30         $t .= "c";
31 };
32 is $@, "";
33 is $t, "a";
34
35 $t = "";
36 eval q{
37         use XS::APItest qw(scopelessblock);
38         my $f = 1.5;
39         $t .= "a(".($f+$f).")";
40         scopelessblock {
41                 use integer;
42                 $t .= "b(".($f+$f).")";
43         }
44         $t .= "c(".($f+$f).")";
45 };
46 is $@, "";
47 is $t, "a(3)b(2)c(2)";
48
49 $t = "";
50 eval q{
51         use XS::APItest qw(scopelessblock);
52         our $z = "z";
53         $t .= "a$z";
54         scopelessblock {
55                 local $z = "y";
56                 $t .= "b$z";
57         }
58         $t .= "c$z";
59 };
60 is $@, "";
61 is $t, "azbycy";
62
63 $t = "";
64 eval q{
65         use XS::APItest qw(scopelessblock);
66         $t .= "A";
67         do {
68                 $t .= "a";
69                 scopelessblock {
70                         $t .= "b";
71                 }
72                 $t .= "c";
73         };
74         $t .= "B";
75 };
76 is $@, "";
77 is $t, "AabcB";
78
79 $t = "";
80 eval q|
81         use XS::APItest qw(scopelessblock);
82         $t .= "a";
83         scopelessblock {
84                 $t .= "b";
85         ]
86         $t .= "c";
87 |;
88 isnt $@, "";
89 is $t, "";
90
91 $SIG{__WARN__} = sub { };
92 $t = "";
93 eval q|
94         use XS::APItest qw(scopelessblock);
95         $t .= "a";
96         scopelessblock {
97                 $t .= "b";
98         )
99         $t .= "c";
100 |;
101 isnt $@, "";
102 is $t, "";
103
104 $t = "";
105 eval q{
106         use XS::APItest qw(scopelessblock);
107         { $t .= "a"; }
108         scopelessblock {
109                 { $t .= "b"; }
110         }
111         { $t .= "c"; }
112 };
113 is $@, "";
114 is $t, "abc";
115
116 $t = "";
117 eval q{
118         use XS::APItest qw(scopelessblock);
119         $t .= "A";
120         do {
121                 { $t .= "a"; }
122                 scopelessblock {
123                         { $t .= "b"; }
124                 }
125                 { $t .= "c"; }
126         };
127         $t .= "B";
128 };
129 is $@, "";
130 is $t, "AabcB";
131
132 1;