Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 88 lines (68 sloc) 2.161 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
c15d965 Test for RT #76896
Ivan Baidakou authored
7 plan 22;
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
fcf62f1 @coke Remove any Pugs fudges
coke authored
29 # //= and the hash() contextualizer can work together
4502acb [t] merge hash_sub.t into spec/
moritz authored
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 placeholders...
moritz authored
41 {
42 ok {; a => 1 } ~~ Block, '{; ... } is a Block';
43 ok { a => 1 } ~~ Hash, '{ a => 1} is a Hash';
44 ok { $^a => $^b } ~~ Block, 'placeholders force it to be a block';
45 ok { $^a => 'b' } ~~ Block, '... as a key';
46 ok { a => $^x } ~~ Block, '... as a value';
47 ok { b => 3, a => $^x, 4 => 5 } ~~ Block, '... somewhere deep inside';
db19c85 @TimToady jvm chokes on compiling a {;}
TimToady authored
48 #?rakudo.jvm skip 'jvm chokes on compiling {;} for some reason'
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 placeholders...
moritz authored
50 }
51
d49c1dc @colomon Fudge for niecza.
colomon authored
52 #?niecza skip "Thinks the block is a hash"
af688d3 @jnthn Test to cover declaring symbols in a block making it a hash for sure.
jnthn authored
53 {
54 my @foo = <a b>;
55 my %hash = map { (state $counter)++ => $_ }, @foo;
56 is %hash<0>, 'a', 'state variable declaration certainly makes it a block (1)';
57 is %hash<1>, 'b', 'state variable declaration certainly makes it a block (2)';
58 }
59
639a766 @moritz RT #68298, $_ in block makes it not a hash
moritz authored
60 # RT #68298
ecd7e35 @colomon (Re)Fudge for Niecza.
colomon authored
61 #?niecza skip "Thinks the block is a hash"
639a766 @moritz RT #68298, $_ in block makes it not a hash
moritz authored
62 is (map { $_ => $_ * $_ }, 1..3).hash<2>, 4, 'block with $_ is not a hash';
63
c15d965 Test for RT #76896
Ivan Baidakou authored
64 # RT #76896
65 {
66 my %fs = ();
67
68 %fs{ lc( 'A' ) } = &fa;
69 sub fa() {
70 return 'FA';
71 }
72
73 %fs{ lc( 'B' ) } = &fb;
74 sub fb() {
75 return 'FB'
76 }
77
78 my $fname = lc( 'A' );
79 is('FA', %fs{ $fname }(), "fa has been called");
80 is('FA', %fs{ lc( 'A' ) }(), "fa has been called");
81 $fname = lc( 'B' );
82 is('FB', %fs{ $fname }(), "fb has been called");
83 is('FB', %fs{ lc( 'B' ) }(), "fb has been called");
84 }
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
85 done;
5870014 [t/spec] test hash vs. block distinction with leading ; and placeholders...
moritz authored
86
4502acb [t] merge hash_sub.t into spec/
moritz authored
87 # vim: ft=perl6
Something went wrong with that request. Please try again.