This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
yada-yada is a term, not an operator
[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
f5727a1c 11plan 12;
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 44
f5727a1c
LM
45note("RT #132150: ... is a term, not an operator");
46$err = $err1 . ( __LINE__ + 1 ) . $err2;
47eval { ... + 0 };
48is $@, $err, "... + 0 parses";
49$@ = '';
50
51$err = $err1 . ( __LINE__ + 1 ) . $err2;
52eval { ... % 1 };
53is $@, $err, "... % 1 parses";
54$@ = '';
55
56$err = $err1 . ( __LINE__ + 1 ) . $err2;
57eval { ... / 1 };
58is $@, $err, "... / 1 parses";
59$@ = '';
60
29e8de64
A
61#
62# Regression tests, making sure ... is still parsable as an operator.
63#
64my @lines = split /\n/ => <<'--';
65
66# Check simple range operator.
67my @arr = 'A' ... 'D';
68
69# Range operator with print.
70print 'D' ... 'A';
71
72# Without quotes, 'D' could be a file handle.
73print D ... A ;
74
75# Another possible interaction with a file handle.
76print ${\"D"} ... A ;
77--
78
79foreach my $line (@lines) {
80 next if $line =~ /^\s*#/ || $line !~ /\S/;
81 my $mess = qq {Parsing '...' in "$line" as a range operator};
82 eval qq {
83 {local *STDOUT; no strict "subs"; $line;}
84 pass \$mess;
85 1;
86 } or do {
87 my $err = $@;
88 $err =~ s/\n//g;
89 fail "$mess ($err)";
90 }
91}