/
fmt-interpolation.t
62 lines (49 loc) 路 1.33 KB
/
fmt-interpolation.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use v6;
use Test;
=begin kwid
=head1 String interpolation and fmt
These tests exercise a bug found at least in r16241 of Pugs
=end kwid
plan 11;
# L<S02/Interpolation rules/Bare scalar variables>
my $x = 'A';
my $y;
is("\$x is $x", '$x is A', 'normal scalar variable interpolation');
is(
"ord of \$x is $x.ord()",
'ord of $x is 65',
'normal scalar variable builtin call as a method'
);
lives_ok(sub { $y = "ord of \$x is $x.ord.fmt('%d')" },
'fmt and scalar interpolation live');
is($y, 'ord of $x is 65', 'fmt and scalar interpolation behave well');
is("\$x is {$x}", '$x is A', 'normal scalar variable interpolation');
is(
"ord of \$x is {$x.ord()}",
'ord of $x is 65',
'normal scalar variable builtin call as a method'
);
lives_ok(sub { $y = "hex-formatted ord of \$x is {$x.ord().fmt('%x')}" },
'fmt and code interpolation live');
is(
$y,
'hex-formatted ord of $x is 41',
'fmt and code interpolation behave well'
);
# These tests actually exercise what's a bug in EVAL() IMHO -- polettix
my $z;
my $expected = 'hex-formatted ord of $x is 41';
is(
EVAL(
q[
$y = "hex-formatted ord of \$x is {$x.ord().fmt('%x')}";
$z = 1;
$y;
]
),
$expected,
'evals ok'
);
ok($z, 'EVAL was *really* ok');
is($y, $expected, 'fmt and code interpolation behave well');
# vim: ft=perl6