Skip to content

Commit 709ae03

Browse files
committed
expand tests for indirect name lookups, include sigilless form ::() and lvalueness
1 parent 91cff9d commit 709ae03

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

S02-names/symbolic-deref.t

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v6;
22

33
use Test;
44

5-
plan 22;
5+
plan 36;
66

77
# See L<http://www.nntp.perl.org/group/perl.perl6.language/22858> --
88
# previously, "my $a; say $::("a")" died (you had to s/my/our/). Now, it was
@@ -14,13 +14,21 @@ plan 22;
1414
my $b_var = "a_var";
1515

1616
is $::($b_var), 42, 'basic symbolic scalar dereferentiation works';
17+
lives_ok { $::($b_var) = 23 }, 'can use $::(...) as lvalue';
18+
is $a_var, 23, 'and the assignment worked';
19+
$::($b_var) = 'a', 'b', 'c';
20+
is $a_var, 'a', '... and it is item assignment';
1721
}
1822

1923
{
2024
my @a_var = <a b c>;
2125
my $b_var = "a_var";
2226

2327
is @::($b_var)[1], "b", 'basic symbolic array dereferentiation works';
28+
@::($b_var) = ('X', 'Y', 'Z');
29+
is @a_var.join(' '), 'X Y Z', 'can assign to symbolic deref';
30+
@::($b_var) = 'u', 'v', 'w';
31+
is @a_var.join(' '), 'u v w', '... and it is list assignment when the sigil is @';
2432
}
2533

2634
{
@@ -37,6 +45,35 @@ plan 22;
3745
is &::($b_var)(), 42, 'basic symbolic code dereferentiation works';
3846
}
3947

48+
my $outer = 'outside';
49+
{
50+
my $inner = 'inside';
51+
52+
ok ::('Int') === Int, 'can look up a type object with ::()';
53+
is ::('$inner'), $inner, 'can look up lexical from same block';
54+
is ::('$outer'), $outer, 'can look up lexical from outer block';
55+
56+
lives_ok { ::('$outer') = 'new' }, 'Can use ::() as lvalue';
57+
is $outer, 'new', 'and the assignment worked';
58+
sub c { 'sub c' };
59+
is ::('&c').(), 'sub c', 'can look up lexical sub';
60+
61+
is ::('e'), e, 'Can look up numerical constants';
62+
}
63+
64+
{
65+
package Outer {
66+
class Inner { }
67+
}
68+
69+
class A::B { };
70+
71+
is ::('Outer::Inner').perl, Outer::Inner.perl, 'can look up name with :: (1)';
72+
#?rakudo skip 'A::B lookup'
73+
is ::('A::B').perl, A::B.perl, 'can look up name with :: (1)';
74+
}
75+
76+
4077
#?rakudo skip 'NYI'
4178
{
4279
$pugs::is::cool = 42;

0 commit comments

Comments
 (0)