1use strict;
2use warnings;
3
4use Test::More;
5
6BEGIN{
7    BAIL_OUT "A bug in Perl 5.20 regex compilation prevents the use of PPR under that release"
8        if $] > 5.020 && $] < 5.022;
9}
10
11
12use PPR;
13
14local $/ = "\n
15####\n";
16while ( my $source = readline *DATA ) {
17    chomp $source;
18
19    my $matched
20        = $source =~ m{ \A (?&PerlOWS) (?&PerlBlock) (?&PerlOWS) \Z $PPR::GRAMMAR }xms;
21
22    ok $matched             => "Matched heredoc'd block $.";
23    diag $source if !$matched;
24}
25
26done_testing();
27
28__DATA__
29{
30    say <<'END', '...';
31Heredoc text
32    END
33}
34More text
35END
36    say 'done';
37}
38
39####
40{
41    say <<~    "END"
42        Heredoc text
43        }
44        More text
45        END
46    , $foo, <<'ETC', '...';
47    et
48    cetera
49ETC
50    say 'done';
51}
52
53####
54{
55    say <<`END`, '...';
56Heredoc text
57    END
58}
59More text
60END
61    say 'done';
62}
63
64####
65{
66    say <<"END", '...';
67Heredoc text
68    END
69}
70More text
71END
72    say 'done';
73}
74
75####
76{
77    say <<END, '...';
78Heredoc text
79    END
80}
81More text
82END
83    say 'done';
84}
85
86####
87{
88    say <<~END, '...';
89        Heredoc text
90        }
91        More text
92        END
93    say 'done';
94}
95
96####
97{
98    say <<\END, '...';
99Heredoc text
100    END
101}
102More text
103END
104    say 'done';
105}
106
107####
108{
109    say <<~\END, '...';
110        Heredoc text
111        }
112        More text
113        END
114    say 'done';
115}
116
117####
118{
119    say <<~`END`, '...';
120        Heredoc text
121        }
122        More text
123        END
124    say 'done';
125}
126
127####
128{
129    say <<~'END', '...';
130        Heredoc text
131        }
132        More text
133        END
134    say 'done';
135}
136
137####
138{
139    say <<~"END", '...';
140        Heredoc text
141        }
142        More text
143        END
144    say 'done';
145}
146
147####
148{
149    say <<    'END', '...';
150Heredoc text
151    END
152}
153More text
154END
155    say 'done';
156}
157
158####
159{
160    say <<    `END`, '...';
161Heredoc text
162    END
163}
164More text
165END
166    say 'done';
167}
168
169####
170{
171    say <<    "END", '...';
172Heredoc text
173    END
174}
175More text
176END
177    say 'done';
178}
179
180####
181{
182    say <<~    'END', '...';
183        Heredoc text
184        }
185        More text
186        END
187    say 'done';
188}
189
190####
191{
192    say <<~    `END`, '...';
193        Heredoc text
194        }
195        More text
196        END
197    say 'done';
198}
199
200####
201{
202    say <<~    "END", '...';
203        Heredoc text
204        }
205        More text
206        END
207    say 'done';
208}
209
210####
211{
212    say <<'END', '...', <<'ETC', '...';
213Heredoc text
214    END
215}
216More text
217END
218    et
219    cetera
220ETC
221    say 'done';
222}
223
224####
225{
226    say <<`END`, $foo, <<'ETC', '...';
227Heredoc text
228    END
229}
230More text
231END
232    et
233    cetera
234ETC
235    say 'done';
236}
237
238####
239{
240    say <<"END", $foo, <<'ETC', '...';
241Heredoc text
242    END
243}
244More text
245END
246    et
247    cetera
248ETC
249    say 'done';
250}
251
252####
253{
254    say <<END, $foo, <<'ETC', '...';
255Heredoc text
256    END
257}
258More text
259END
260    et
261    cetera
262ETC
263    say 'done';
264}
265
266####
267{
268    say <<~END, $foo, <<'ETC', '...';
269        Heredoc text
270        }
271        More text
272        END
273    say 'done';
274    et
275    cetera
276ETC
277}
278
279####
280{
281    say <<\END, $foo, <<'ETC', '...';
282Heredoc text
283    END
284}
285More text
286END
287    et
288    cetera
289ETC
290    say 'done';
291}
292
293####
294{
295    say <<~\END, $foo, <<'ETC', '...';
296        Heredoc text
297        }
298        More text
299        END
300    et
301    cetera
302ETC
303    say 'done';
304}
305
306####
307{
308    say <<~`END`, $foo, <<'ETC', '...';
309        Heredoc text
310        }
311        More text
312        END
313    et
314    cetera
315ETC
316    say 'done';
317}
318
319####
320{
321    say <<~'END', $foo, <<'ETC', '...';
322        Heredoc text
323        }
324        More text
325        END
326    et
327    cetera
328ETC
329    say 'done';
330}
331
332####
333{
334    say <<~"END", $foo, <<'ETC', '...';
335        Heredoc text
336        }
337        More text
338        END
339    et
340    cetera
341ETC
342    say 'done';
343}
344
345####
346{
347    say <<    'END', $foo, <<'ETC', '...';
348Heredoc text
349    END
350}
351More text
352END
353    et
354    cetera
355ETC
356    say 'done';
357}
358
359####
360{
361    say <<    `END`, $foo, <<'ETC', '...';
362Heredoc text
363    END
364}
365More text
366END
367    et
368    cetera
369ETC
370    say 'done';
371}
372
373####
374{
375    say <<    "END", $foo, <<'ETC', '...';
376Heredoc text
377    END
378}
379More text
380END
381    et
382    cetera
383ETC
384    say 'done';
385}
386
387####
388{
389    say <<~    'END', $foo, <<'ETC', '...';
390        Heredoc text
391        }
392        More text
393        END
394    et
395    cetera
396ETC
397    say 'done';
398}
399
400####
401{
402    say <<~    `END`, $foo, <<'ETC', '...';
403        Heredoc text
404        }
405        More text
406        END
407    et
408    cetera
409ETC
410    say 'done';
411}
412
413####
414{
415    say <<~    "END", $foo, <<'ETC', '...';
416        Heredoc text
417        }
418        More text
419        END
420    et
421    cetera
422ETC
423    say 'done';
424}
425
426####
427{
428    say <<~    "END",
429        Heredoc text
430        }
431        More text
432        END
433    $foo, <<'ETC', '...';
434    et
435    cetera
436ETC
437    say 'done';
438}
439
440####
441