Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 62 lines (46 sloc) 1.531 kB
3e06152 [t] move nested_hashrefs.t to spec
moritz authored
1 use v6;
2
3 use Test;
4
eda6db1 [t/spec] move smartlinks from POD to ordinary comments
moritz authored
5 # L<S06/Anonymous hashes vs blocks>
6
af688d3 @jnthn Test to cover declaring symbols in a block making it a hash for sure.
jnthn authored
7 plan 17;
3e06152 [t] move nested_hashrefs.t to spec
moritz authored
8
9 my $hash = {
10 '1' => { '2' => 3, '4' => 5 },
11 };
12
13
14 is( $hash<1><2>, '3', 'First nested element.');
15 is( $hash<1><4>, '5', 'Second nested element.');
16
17 my $h2 = {
18 x => [2,3]
19 };
20 is( $h2<x>[0], '2', 'First nested element.');
21 is( $h2<x>[1], '3', 'Second nested element.');
22
23 my %foo = (1 => 2);
24 my $bar = { %foo };
885130b [t/spec] todo test passes now
kyle authored
25
3e06152 [t] move nested_hashrefs.t to spec
moritz authored
26 ok $bar ~~ Hash, '%foo in a block causes hash composing';
27
4502acb [t] merge hash_sub.t into spec/
moritz authored
28
29 # pugs had problems with //= and the hash() contextualizer
30 {
31 my %hash;
32 %hash<foo> //= hash();
33 %hash<bar> //= hash;
34 my $h_ref;
35 $h_ref //= hash();
f85b8bf Fix a bunch of typeobject stringifications.
kboga authored
36 is(%hash<foo>.WHAT.gist, ::Hash.gist, "Parses as two items");
37 is(%hash<bar>.WHAT.gist, ::Hash.gist, "Parens do not help");
38 is($h_ref.WHAT.gist, ::Hash.gist, "It is not limited to hash values");
4502acb [t] merge hash_sub.t into spec/
moritz authored
39 }
40
5870014 [t/spec] test hash vs. block distinction with leading ; and placehold…
moritz authored
41 {
42 ok {; a => 1 } ~~ Block, '{; ... } is a Block';
43 ok { a => 1 } ~~ Hash, '{ a => 1} is a Hash';
9dac81d @coke pugs fudge
coke authored
44 #?pugs 4 skip "Missing required parameters"
5870014 [t/spec] test hash vs. block distinction with leading ; and placehold…
moritz authored
45 ok { $^a => $^b } ~~ Block, 'placeholders force it to be a block';
46 ok { $^a => 'b' } ~~ Block, '... as a key';
47 ok { a => $^x } ~~ Block, '... as a value';
48 ok { b => 3, a => $^x, 4 => 5 } ~~ Block, '... somewhere deep inside';
d66c0c5 [t/spec] test for RT #76198, {;} should be a Block
moritz authored
49 ok {;} ~~ Block, '{;} is a Block';
5870014 [t/spec] test hash vs. block distinction with leading ; and placehold…
moritz authored
50 }
51
af688d3 @jnthn Test to cover declaring symbols in a block making it a hash for sure.
jnthn authored
52 {
53 my @foo = <a b>;
54 my %hash = map { (state $counter)++ => $_ }, @foo;
55 is %hash<0>, 'a', 'state variable declaration certainly makes it a block (1)';
56 is %hash<1>, 'b', 'state variable declaration certainly makes it a block (2)';
57 }
58
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
59 done;
5870014 [t/spec] test hash vs. block distinction with leading ; and placehold…
moritz authored
60
4502acb [t] merge hash_sub.t into spec/
moritz authored
61 # vim: ft=perl6
Something went wrong with that request. Please try again.