Skip to content

Commit 09eb964

Browse files
committed
Perlito5 - parser - add failing string interpolation tests
1 parent 1aa5804 commit 09eb964

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

t5/01-perlito/04-string.t

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v5;
22
use strict;
33
use feature 'say';
44

5-
say '1..10';
5+
say '1..18';
66

77
my $x = "abcd";
88
if (substr($x,1,1) ne "b") {
@@ -51,3 +51,52 @@ say "ok 9 # $tail";
5151
print 'not ' if $z ne 'tr';
5252
say 'ok 10';
5353

54+
55+
# interpolation
56+
57+
my $v = 123;
58+
my $r = "-$v-";
59+
print 'not ' if $r ne '-123-'; say 'ok 11 - scalar interpolation';
60+
61+
my @v = (234, 567);
62+
$r = "-$v[1]-";
63+
print 'not ' if $r ne '-567-'; say 'ok 12 - array element interpolation';
64+
65+
$r = "-${v[1]}-";
66+
print 'not ' if $r ne '-567-'; say 'ok 13 - array element interpolation';
67+
68+
$r = "-@v-";
69+
print 'not ' if $r ne '-234 567-'; say 'ok 14 - array interpolation';
70+
71+
my %v = (xyz => 234, abc => 567);
72+
$r = "-$v{xyz}-";
73+
print 'not ' if $r ne '-234-'; say 'ok 15 - hash element interpolation';
74+
75+
$r = "-${v{xyz}}-";
76+
print 'not ' if $r ne '-234-'; say 'ok 16 - hash element interpolation';
77+
78+
$v = { xyz => 123, abc => 567 };
79+
$r = "-$v->{xyz}-";
80+
print 'not ' if $r ne '-123-'; say "ok 17 - hash deref interpolation - $r";
81+
82+
# {
83+
# no strict 'refs';
84+
# # Can't use bareword ("v") as a HASH ref while "strict refs" in use
85+
# # Global symbol "%v" requires explicit package name
86+
# $r = "-${v->{xyz}}-";
87+
# print 'not ' if $r ne '-234-'; say 'ok 18 - hash deref interpolation';
88+
# }
89+
90+
$v = [ 123, 567, 890 ];
91+
$r = "-$v->[2]-";
92+
print 'not ' if $r ne '-890-'; say "ok 18 - array deref interpolation - $r";
93+
94+
# {
95+
# no strict 'refs';
96+
# # Can't use bareword ("v") as a HASH ref while "strict refs" in use
97+
# # Global symbol "@v" requires explicit package name
98+
# $r = "-${v->[2]}-";
99+
# print 'not ' if $r ne '-890-'; say 'ok 18 - array deref interpolation';
100+
# }
101+
102+

0 commit comments

Comments
 (0)