This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
document qw's whitespace rules
[perl5.git] / t / op / yadayada.t
CommitLineData
be25f609 1#!./perl
2
341b7876
NC
3BEGIN {
4 chdir 't' if -d 't';
341b7876 5 require './test.pl';
624c42e2 6 set_up_inc('../lib');
341b7876 7}
be25f609 8
341b7876
NC
9use strict;
10
12d22d1f 11plan 9;
341b7876 12
12d22d1f
JK
13my $err;
14my $err1 = "Unimplemented at $0 line ";
15my $err2 = ".\n";
be25f609 16
12d22d1f 17$err = $err1 . ( __LINE__ + 1 ) . $err2;
be25f609 18eval { ... };
12d22d1f
JK
19is $@, $err, "Execution of ellipsis statement reported 'Unimplemented' code";
20$@ = '';
be25f609 21
12d22d1f
JK
22note("RT #122661: Semicolon before ellipsis statement disambiguates to indicate block rather than hash reference");
23my @input = (3..5);
24my @transformed;
25$err = $err1 . ( __LINE__ + 1 ) . $err2;
26eval { @transformed = map {; ... } @input; };
27is $@, $err, "Disambiguation case 1";
28$@ = '';
29e8de64 29
12d22d1f
JK
30$err = $err1 . ( __LINE__ + 1 ) . $err2;
31eval { @transformed = map {;...} @input; };
32is $@, $err, "Disambiguation case 2";
33$@ = '';
34
35$err = $err1 . ( __LINE__ + 1 ) . $err2;
36eval { @transformed = map {; ...} @input; };
37is $@, $err, "Disambiguation case 3";
38$@ = '';
39
40$err = $err1 . ( __LINE__ + 1 ) . $err2;
41eval { @transformed = map {;... } @input; };
42is $@, $err, "Disambiguation case 4";
43$@ = '';
29e8de64
A
44
45#
46# Regression tests, making sure ... is still parsable as an operator.
47#
48my @lines = split /\n/ => <<'--';
49
50# Check simple range operator.
51my @arr = 'A' ... 'D';
52
53# Range operator with print.
54print 'D' ... 'A';
55
56# Without quotes, 'D' could be a file handle.
57print D ... A ;
58
59# Another possible interaction with a file handle.
60print ${\"D"} ... A ;
61--
62
63foreach my $line (@lines) {
64 next if $line =~ /^\s*#/ || $line !~ /\S/;
65 my $mess = qq {Parsing '...' in "$line" as a range operator};
66 eval qq {
67 {local *STDOUT; no strict "subs"; $line;}
68 pass \$mess;
69 1;
70 } or do {
71 my $err = $@;
72 $err =~ s/\n//g;
73 fail "$mess ($err)";
74 }
75}