1use warnings;
2use strict;
3
4use Test::More tests => 32;
5
6BEGIN { $^H |= 0x20000; }
7
8my $t;
9
10$t = "";
11eval q{
12	use XS::APItest ();
13	$t .= "a";
14	swaptwostmts
15	$t .= "b";
16	$t .= "c";
17	$t .= "d";
18};
19isnt $@, "";
20
21$t = "";
22eval q{
23	use XS::APItest qw(swaptwostmts);
24	$t .= "a";
25	swaptwostmts
26	$t .= "b";
27	$t .= "c";
28	$t .= "d";
29};
30is $@, "";
31is $t, "acbd";
32
33$t = "";
34eval q{
35	use XS::APItest qw(swaptwostmts);
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{
47	use XS::APItest qw(swaptwostmts);
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{
59	use XS::APItest qw(swaptwostmts);
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{
77	use XS::APItest qw(swaptwostmts);
78	$t .= "a";
79	swaptwostmts
80	$t .= "b";
81	$t .= "c";
82};
83is $@, "";
84is $t, "acb";
85
86$t = "";
87eval q{
88	use XS::APItest qw(swaptwostmts);
89	$t .= "a";
90	swaptwostmts
91	$t .= "b";
92	$t .= "c"
93};
94is $@, "";
95is $t, "acb";
96
97$t = "";
98eval q{
99	use XS::APItest qw(swaptwostmts);
100	$t .= "a";
101	swaptwostmts
102	$t .= "b"
103};
104isnt $@, "";
105
106$t = "";
107eval q{
108	use XS::APItest qw(swaptwostmts);
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{
122	use XS::APItest qw(swaptwostmts);
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{
135	use XS::APItest qw(swaptwostmts);
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{
147	use XS::APItest qw(swaptwostmts);
148	no warnings "void";
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";
175	"@{[ $t .= 'a' ]}";
176	swaptwostmts
177	if(1) { "@{[ $t .= 'b' ]}"; }
178	"@{[ $t .= 'c' ]}";
179	"@{[ $t .= 'd' ]}";
180};
181is $@, "";
182is $t, "acbd";
183
184$t = "";
185eval q{
186	use XS::APItest qw(swaptwostmts);
187	$t .= "a";
188	swaptwostmts
189	x:
190	$t .= "b";
191	z:
192	$t .= "c";
193	$t .= "d";
194};
195is $@, "";
196is $t, "acbd";
197
198$t = "";
199eval q{
200	use XS::APItest qw(swaptwostmts);
201	$t .= "a";
202	goto x;
203	$t .= "b";
204	swaptwostmts
205	x:
206	$t .= "c";
207	$t .= "d";
208	$t .= "e";
209};
210is $@, "";
211is $t, "ace";
212
213$t = "";
214eval q{
215	use XS::APItest qw(swaptwostmts);
216	$t .= "a";
217	goto x;
218	$t .= "b";
219	swaptwostmts
220	$t .= "c";
221	x:
222	$t .= "d";
223	$t .= "e";
224};
225is $@, "";
226is $t, "adce";
227
2281;
229