3 # Checks if the parser behaves correctly in edge case
4 # (including weird syntax errors)
12 use open qw( :utf8 :std );
13 no warnings qw(misc reserved);
15 plan (tests => 65880);
17 # ${single:colon} should not be valid syntax
22 eval "\${\x{30cd}single:\x{30cd}colon} = 1";
24 qr/syntax error .* near "\x{30cd}single:/,
25 '${\x{30cd}single:\x{30cd}colon} should not be valid syntax'
30 evalbytes '${single:colon} = 1';
32 qr/syntax error .* near "single:/,
33 '...same with ${single:colon}'
37 # ${yadda'etc} and ${yadda::etc} should both work under strict
40 eval q<use strict; ${flark::fleem}>;
41 is($@, '', q<${package::var} works>);
44 eval q<use strict; ${fleem'flark}>;
45 is($@, '', q<...as does ${package'var}>);
48 # The first character in ${...} should respect the rules
53 like($@, qr/\QUnrecognized character/, q(the first character in ${...} isn't special))
56 # Checking that at least some of the special variables work
57 for my $v (qw( ^V ; < > ( ) {^GLOBAL_PHASE} ^W _ 1 4 0 [ ] ! @ / \ = )) {
59 skip_if_miniperl('No $[ under miniperl', 2) if $v eq '[';
62 is $@, '', "No syntax error for \$$v";
65 eval "use utf8; \$$v;";
66 is $@, '', "No syntax error for \$$v under use utf8";
70 # Checking if the Latin-1 range behaves as expected, and that the behavior is the
71 # same whenever under strict or not.
73 no warnings 'closure';
75 my $esc = sprintf("%X", ord $chr);
76 utf8::downgrade($chr);
77 if ($chr !~ /\p{XIDS}/u) {
78 is evalbytes "no strict; \$$chr = 10",
80 sprintf("\\x%02x, part of the latin-1 range, is legal as a length-1 variable", $_);
84 eval "no strict; use utf8; \$$chr = 1";
86 qr/\QUnrecognized character \x{\E\L$esc/,
87 sprintf("..but is illegal as a length-1 variable under use utf8", $_);
93 evalbytes "no strict; \$$chr = 1";
94 is($@, '', sprintf("\\x%02x, =~ \\p{XIDS}, latin-1, no utf8, no strict, is a valid length-1 variable", $_));
97 evalbytes "use strict; \$$chr = 1";
100 sprintf("\\x%02x under no utf8 does not have to be required under strict, even though it matches XIDS", $_)
104 evalbytes "\$a$chr = 1";
106 qr/Unrecognized character /,
107 sprintf("...but under no utf8, it's not allowed in two-or-more character variables")
111 evalbytes "\$a$chr = 1";
113 qr/Unrecognized character /,
114 sprintf("...but under no utf8, it's not allowed in two-or-more character variables")
122 eval "no strict; \$$u = 1";
123 is($@, '', sprintf("\\x%02x, =~ \\p{XIDS}, UTF-8, use utf8, no strict, is a valid length-1 variable", $_));
126 eval "use strict; \$$u = 1";
128 qr/Global symbol "\$$u" requires explicit package name/,
129 sprintf("\\x%02x under utf8 has to be required under strict", $_)
137 my $ret = eval "my \$c\x{327} = 100; \$c\x{327}"; # c + cedilla
138 is($@, '', "ASCII character + combining character works as a variable name");
139 is($ret, 100, "...and returns the correct value");
142 # From Tom Christiansen's 'highly illegal variable names are now accidentally legal' mail
144 "\N{EM DASH}", "\x{F8FF}", "\N{POUND SIGN}", "\N{SOFT HYPHEN}",
145 "\N{THIN SPACE}", "\x{11_1111}", "\x{DC00}", "\N{COMBINING DIAERESIS}",
146 "\N{COMBINING ENCLOSING CIRCLE BACKSLASH}",
149 no warnings 'non_unicode';
150 my $esc = sprintf("%x", ord $chr);
152 eval "\$$chr = 1; \$$chr";
154 qr/\QUnrecognized character \x{$esc};/,
155 "\\x{$esc} is illegal for a length-one identifier"
159 for my $i (0x100..0xffff) {
161 my $esc = sprintf("%x", $i);
163 eval "my \$$chr = q<test>; \$$chr;";
164 if ( $chr =~ /^\p{_Perl_IDStart}$/ ) {
165 is($@, '', sprintf("\\x{%04x} is XIDS, works as a length-1 variable", $i));
169 qr/\QUnrecognized character \x{$esc};/,
170 "\\x{$esc} isn't XIDS, illegal as a length-1 variable",
176 # Bleadperl v5.17.9-109-g3283393 breaks ZEFRAM/Module-Runtime-0.013.tar.gz
177 # https://rt.perl.org/rt3/Public/Bug/Display.html?id=117101
183 is($$1, $$, q{$$1 parses as ${$1}});
189 is( $$$$1, $test, q{$$$$1 parses as ${${${$1}}}} );
191 is($@, '', q{$$1 parses correctly});
193 for my $chr ( q{@}, "\N{U+FF10}", "\N{U+0300}" ) {
194 my $esc = sprintf("\\x{%x}", ord $chr);
202 qr/syntax error|Unrecognized character/,
203 qq{\$\$$esc is a syntax error}
209 # bleadperl v5.17.9-109-g3283393 breaks JEREMY/File-Signature-1.009.tar.gz
210 # https://rt.perl.org/rt3/Ticket/Display.html?id=117145
218 '${ var } works under strict'
223 # Silence the deprecation warning for literal controls
224 no warnings 'deprecated';
226 for my $var ( '$', "\7LOBAL_PHASE", "^GLOBAL_PHASE", "^V" ) {
228 is($@, '', "\${ $var} works" );
230 is($@, '', "\${$var } works" );
232 is($@, '', "\${ $var } works" );
241 "Newlines at the start of an identifier should be skipped over"
248 "...but \$^J is still legal"
251 no warnings 'deprecated';
252 my $ret = eval "\${\cT\n}";
253 is($@, "", 'No errors from using ${\n\cT\n}');
254 is($ret, $^T, "...and we got the right value");
258 # Originally from t/base/lex.t, moved here since we can't
259 # turn deprecation warnings off in that file.
261 no warnings 'deprecated';
266 # Does the syntax where we use the literal control character still work?
270 "Literal control character variables work"
273 eval "\$\cQ = 24"; # Literal control character
274 is($@, "", "...and they can be assigned to without error");
275 is(${"\cQ"}, 24, "...and the assignment works");
276 is($^Q, 24, "...even if we access the variable through the caret name");
277 is(\${"\cQ"}, \$^Q, '\${\cQ} == \$^Q');
281 # Prior to 5.19.4, the following changed behavior depending
282 # on the presence of the newline after '@{'.
285 my $ret = @{ foo { "a" } };
286 is($ret, $foo{a}, '@{ foo { "a" } } is parsed as @foo{a}');
291 is($ret, $foo{a}, '@{\nfoo { "a" } } is still parsed as @foo{a}');