Skip to content

Commit 34985d2

Browse files
committed
be more exhaustive on polysigil interpolation
1 parent 54ad7fd commit 34985d2

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

S02-literals/string-interpolation.t

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use lib 't/spec/packages';
33

44
use Test;
55
use Test::Util;
6-
plan 17;
6+
plan 40;
77

88
# L<S02/Closures/"A bare closure also interpolates in double-quotish context.">
99

@@ -81,9 +81,64 @@ line 4
8181

8282
# RT #129257
8383
{
84-
is %%one @@two &&three rt%%one@@two&&three rt%% one@@ two&& three@@,
85-
"%%one @@two &&three rt%%one@@two&&three rt%% one@@ two&& three@@",
86-
'%%, @@, and && do not attempt to interpolate any variables';
84+
is "%%one @@two &&three rt%%one@@two&&three rt%% one@@ two&& three@@",
85+
%%one @@two &&three rt%%one@@two&&three rt%% one@@ two&& three@@,
86+
'bracketless %%, @@, and && do not attempt to interpolate any variables';
87+
88+
is "@%one @&two @&%three @%&four %@one %&two %&@three %@&four &@one &%two &%@three &@%four",
89+
@%one @&two @&%three @%&four %@one %&two %&@three %@&four &@one &%two &%@three &@%four,
90+
'and various mixtures do not attempt to interpolate any variables';
91+
92+
my $x = 'DX';
93+
is "%%$x @@$x &&$x",
94+
%%DX @@DX &&DX,
95+
'bracketless %%, @@, and && do not suppress following scalar interpolation';
96+
97+
is "@%$x @&$x @&%$x @%&$x %@$x %&$x %&@$x %@&$x &@$x &%$x &%@$x &@%$x",
98+
@%DX @&DX @&%DX @%&DX %@DX %&DX %&@DX %@&DX &@DX &%DX &%@DX &@%DX,
99+
'and various mixtures do not supress subsequent scalar interpolation';
100+
101+
is "%%@@&&@%@&@&%@%&%@%&%&@%@&&@&%&%@&@%$x",
102+
%%@@&&@%@&@&%@%&%@%&%&@%@&&@&%&%@&@%DX,
103+
'and it really does not matter how many there are before the $';
104+
105+
throws-like '"@$whoopsies[]"', X::Undeclared, symbol => '$whoopsies';
106+
throws-like '"%$whoopsies{}"', X::Undeclared, symbol => '$whoopsies';
107+
throws-like '"&$whoopsies()"', X::Undeclared, symbol => '$whoopsies';
108+
109+
throws-like '"@@whoopsies[]"', X::Undeclared, symbol => '@whoopsies';
110+
throws-like '"%@whoopsies{}"', X::Undeclared, symbol => '@whoopsies';
111+
throws-like '"&@whoopsies()"', X::Undeclared, symbol => '@whoopsies';
112+
113+
throws-like '"@%whoopsies[]"', X::Undeclared, symbol => '%whoopsies';
114+
throws-like '"%%whoopsies{}"', X::Undeclared, symbol => '%whoopsies';
115+
throws-like '"&%whoopsies()"', X::Undeclared, symbol => '%whoopsies';
116+
117+
throws-like '"@&whoopsies[]"', X::Undeclared::Symbols;
118+
throws-like '"%&whoopsies{}"', X::Undeclared::Symbols;
119+
throws-like '"&&whoopsies()"', X::Undeclared::Symbols;
120+
121+
# make sure existing refs don't fail
122+
123+
my $aref = ['value'];
124+
my $href = {:value};
125+
my $cref = {42};
126+
127+
throws-like '"$$aref $$aref[] $$whoopsies[]"', X::Undeclared, symbol => '$whoopsies';
128+
throws-like '"@$aref @$aref[] @$whoopsies[]"', X::Undeclared, symbol => '$whoopsies';
129+
throws-like '"%$href %$href{} %$whoopsies{}"', X::Undeclared, symbol => '$whoopsies';
130+
throws-like '"&$cref &$cref() &$whoopsies()"', X::Undeclared, symbol => '$whoopsies';
131+
132+
# make sure existing objects don't fail
133+
134+
my @arry = 42;
135+
my %hash = :foo;
136+
my &code = &exp;
137+
138+
throws-like '"$@arry $@arry[] $@whoopsies[]"', X::Undeclared, symbol => '@whoopsies';
139+
throws-like '"$%hash $%hash{} $%whoopsies{}"', X::Undeclared, symbol => '%whoopsies';
140+
throws-like '"$&code $&code() $&whoopsies()"', X::Undeclared::Symbols;
141+
87142
}
88143

89144
# vim: ft=perl6

0 commit comments

Comments
 (0)