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 / swaptwostmts.t
CommitLineData
28ac2b49
Z
1use warnings;
2use strict;
3
a7aaec61 4use Test::More tests => 26;
28ac2b49
Z
5
6BEGIN { $^H |= 0x20000; }
7
8my $t;
9
10$t = "";
11eval q{
83f8bb56 12 use XS::APItest ();
28ac2b49
Z
13 $t .= "a";
14 swaptwostmts
15 $t .= "b";
16 $t .= "c";
17 $t .= "d";
18};
19isnt $@, "";
20
21$t = "";
22eval q{
83f8bb56 23 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
24 $t .= "a";
25 swaptwostmts
26 $t .= "b";
27 $t .= "c";
28 $t .= "d";
29};
30is $@, "";
31is $t, "acbd";
32
33$t = "";
34eval q{
83f8bb56 35 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
36 $t .= "a";
37 swaptwostmts
38 if(1) { $t .= "b"; }
39 $t .= "c";
40 $t .= "d";
41};
42is $@, "";
43is $t, "acbd";
44
45$t = "";
46eval q{
83f8bb56 47 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
48 $t .= "a";
49 swaptwostmts
50 $t .= "b";
51 if(1) { $t .= "c"; }
52 $t .= "d";
53};
54is $@, "";
55is $t, "acbd";
56
57$t = "";
58eval q{
83f8bb56 59 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
60 $t .= "a";
61 swaptwostmts
62 $t .= "b";
63 foreach(1..3) {
64 $t .= "c";
65 swaptwostmts
66 $t .= "d";
67 $t .= "e";
68 $t .= "f";
69 }
70 $t .= "g";
71};
72is $@, "";
73is $t, "acedfcedfcedfbg";
74
75$t = "";
76eval q{
83f8bb56 77 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
78 $t .= "a";
79 swaptwostmts
80 $t .= "b";
81 $t .= "c";
82};
83is $@, "";
84is $t, "acb";
85
86$t = "";
87eval q{
83f8bb56 88 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
89 $t .= "a";
90 swaptwostmts
91 $t .= "b";
92 $t .= "c"
93};
94is $@, "";
95is $t, "acb";
96
97$t = "";
98eval q{
83f8bb56 99 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
100 $t .= "a";
101 swaptwostmts
102 $t .= "b"
103};
104isnt $@, "";
105
106$t = "";
107eval q{
83f8bb56 108 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
109 $_ = $t;
110 $_ .= "a";
111 swaptwostmts
112 if(1) { $_ .= "b"; }
113 tr/a-z/A-Z/;
114 $_ .= "d";
115 $t = $_;
116};
117is $@, "";
118is $t, "Abd";
119
120$t = "";
121eval q{
83f8bb56 122 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
123 sub add_to_t { $t .= $_[0]; }
124 add_to_t "a";
125 swaptwostmts
126 if(1) { add_to_t "b"; }
127 add_to_t "c";
128 add_to_t "d";
129};
130is $@, "";
131is $t, "acbd";
132
133$t = "";
134eval q{
83f8bb56 135 use XS::APItest qw(swaptwostmts);
28ac2b49
Z
136 { $t .= "a"; }
137 swaptwostmts
138 if(1) { { $t .= "b"; } }
139 { $t .= "c"; }
140 { $t .= "d"; }
141};
142is $@, "";
143is $t, "acbd";
144
145$t = "";
146eval q{
83f8bb56 147 use XS::APItest qw(swaptwostmts);
28ac2b49 148 no warnings "void";
a7aaec61
Z
149 { $t .= "a"; }
150 swaptwostmts
151 if(1) { { $t .= "b"; } }
152 {};
153 { $t .= "d"; }
154};
155is $@, "";
156is $t, "abd";
157
158$t = "";
159eval q{
160 use XS::APItest qw(swaptwostmts);
161 no warnings "void";
162 { $t .= "a"; }
163 swaptwostmts
164 if(1) { { $t .= "b"; } }
165 [];
166 { $t .= "d"; }
167};
168is $@, "";
169is $t, "abd";
170
171$t = "";
172eval q{
173 use XS::APItest qw(swaptwostmts);
174 no warnings "void";
28ac2b49
Z
175 "@{[ $t .= 'a' ]}";
176 swaptwostmts
177 if(1) { "@{[ $t .= 'b' ]}"; }
178 "@{[ $t .= 'c' ]}";
179 "@{[ $t .= 'd' ]}";
180};
181is $@, "";
182is $t, "acbd";
183
1841;