Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 136 lines (108 sloc) 3.752 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
8bed649 Added svn props to test scripts
cosimo authored
2
3 use Test;
4
3261c0a [kv.t] Fixed test count, which was only off by two orders of magnitude.....
lwall authored
5 plan 27;
8bed649 Added svn props to test scripts
cosimo authored
6
ccbbe70 [t/spec] Convert pod markers to pod6
cosimo authored
7 =begin pod
8bed649 Added svn props to test scripts
cosimo authored
8
5f35d0f [t/spec] fix smartlinks in S32-hash
moritz authored
9 Basic C<kv> tests, see S32::Containers.
8bed649 Added svn props to test scripts
cosimo authored
10
ccbbe70 [t/spec] Convert pod markers to pod6
cosimo authored
11 =end pod
8bed649 Added svn props to test scripts
cosimo authored
12
5f35d0f [t/spec] fix smartlinks in S32-hash
moritz authored
13 # L<S32::Containers/"Hash"/=item kv>
8bed649 Added svn props to test scripts
cosimo authored
14 { # check the invocant form
79de2c6 Solomon Foster Change tests so they no longer depend on the order of sorting numbers wi...
colomon authored
15 my %hash = (a => "x", b => "xx", c => "xxx", d => "xxxx");
8bed649 Added svn props to test scripts
cosimo authored
16 my @kv = %hash.kv;
17 is(+@kv, 8, '%hash.kv returns the correct number of elems');
79de2c6 Solomon Foster Change tests so they no longer depend on the order of sorting numbers wi...
colomon authored
18 is(~@kv.sort, "a b c d x xx xxx xxxx", '%hash.kv has no inner list');
8bed649 Added svn props to test scripts
cosimo authored
19 }
20
21 { # check the non-invocant form
79de2c6 Solomon Foster Change tests so they no longer depend on the order of sorting numbers wi...
colomon authored
22 my %hash = (a => "x", b => "xx", c => "xxx", d => "xxxx");
8bed649 Added svn props to test scripts
cosimo authored
23 my @kv = kv(%hash);
24 is(+@kv, 8, 'kv(%hash) returns the correct number of elems');
79de2c6 Solomon Foster Change tests so they no longer depend on the order of sorting numbers wi...
colomon authored
25 is(~@kv.sort, "a b c d x xx xxx xxxx", 'kv(%hash) has no inner list');
8bed649 Added svn props to test scripts
cosimo authored
26 }
27
28 # See "Questions about $pair.kv" thread on perl-6 lang
29 {
30 my $pair = (a => 1);
31 my @kv = $pair.kv;
32 is(+@kv, 2, '$pair.kv returned one elem');
33 is(+@kv, 2, '$pair.kv inner list has two elems');
34 is(~@kv, "a 1", '$pair.kv inner list matched expectation');
35 }
36
37 {
38 my $sub = sub (Hash $hash) { $hash.kv };
79de2c6 Solomon Foster Change tests so they no longer depend on the order of sorting numbers wi...
colomon authored
39 my %hash = (a => "x", b => "y");
40 is ~kv(%hash).sort, "a b x y", ".kv works with normal hashes (sanity check)";
41 is ~$sub(%hash).sort, "a b x y", ".kv works with constant hash references";
8bed649 Added svn props to test scripts
cosimo authored
42 }
43
44 {
45 # "%$hash" is not idiomatic Perl, but should work nevertheless.
46 my $sub = sub (Hash $hash) { %$hash.kv };
79de2c6 Solomon Foster Change tests so they no longer depend on the order of sorting numbers wi...
colomon authored
47 my %hash = (a => "x", b => "y");
48 is ~kv(%hash).sort, "a b x y", ".kv works with normal hashes (sanity check)";
49 is ~$sub(%hash).sort, "a b x y", ".kv works with dereferenced constant hash references";
8bed649 Added svn props to test scripts
cosimo authored
50 }
51
52 # test3 and test4 illustrate a bug
53
f60ff61 [fudge] more sub counting tweaks
lwall authored
54 #?DOES 2
8bed649 Added svn props to test scripts
cosimo authored
55 sub test1{
56 my $pair = boo=>'baz';
f85b8bf Fix a bunch of typeobject stringifications.
kboga authored
57 my $type = $pair.WHAT.gist;
643450f [kv.t] must have space before -> and {
lwall authored
58 for $pair.kv -> $key, $value {
8bed649 Added svn props to test scripts
cosimo authored
59 is($key, 'boo', "test1: $type \$pair got the right \$key");
60 is($value, 'baz', "test1: $type \$pair got the right \$value");
61 }
62 }
63 test1;
64
f60ff61 [fudge] more sub counting tweaks
lwall authored
65 #?DOES 2
8bed649 Added svn props to test scripts
cosimo authored
66 sub test2{
67 my %pair = boo=>'baz';
f85b8bf Fix a bunch of typeobject stringifications.
kboga authored
68 my $type = %pair.WHAT.gist;
8bed649 Added svn props to test scripts
cosimo authored
69 my $elems= +%pair;
643450f [kv.t] must have space before -> and {
lwall authored
70 for %pair.kv -> $key, $value {
41f65ff [t/spec] more variable declaration fixes
moritz authored
71 is($key, 'boo', "test2: $elems elem $type \%pair got the right \$key");
72 is($value, 'baz', "test2: $elems elem $type \%pair got the right \$value");
8bed649 Added svn props to test scripts
cosimo authored
73 }
74 }
75 test2;
76
77 my %hash = ('foo' => 'baz');
f60ff61 [fudge] more sub counting tweaks
lwall authored
78 #?DOES 2
afa0332 [t/spec] fix wrong usage of Hash %h and Array @a
moritz authored
79 sub test3 (%h){
643450f [kv.t] must have space before -> and {
lwall authored
80 for %h.kv -> $key, $value {
f85b8bf Fix a bunch of typeobject stringifications.
kboga authored
81 is($key, 'foo', "test3: from {+%h}-elem {%h.WHAT.gist} \%h got the right \$key");
82 is($value, 'baz', "test3: from {+%h}-elem {%h.WHAT.gist} \%h got the right \$value");
8bed649 Added svn props to test scripts
cosimo authored
83 }
84 }
85 test3 %hash;
86
afa0332 [t/spec] fix wrong usage of Hash %h and Array @a
moritz authored
87 sub test4 (%h){
8bed649 Added svn props to test scripts
cosimo authored
88 for 0..%h.kv.end -> $idx {
f85b8bf Fix a bunch of typeobject stringifications.
kboga authored
89 is(%h.kv[$idx], %hash.kv[$idx], "test4: elem $idx of {%h.kv.elems}-elem {%h.kv.WHAT.gist} \%hash.kv correctly accessed");
8bed649 Added svn props to test scripts
cosimo authored
90 }
91 }
ee8a33c Will Coleda niecza fudge
coke authored
92 #?DOES 2
8bed649 Added svn props to test scripts
cosimo authored
93 test4 %hash;
94
95 # sanity
643450f [kv.t] must have space before -> and {
lwall authored
96 for %hash.kv -> $key, $value {
f85b8bf Fix a bunch of typeobject stringifications.
kboga authored
97 is($key, 'foo', "for(): from {+%hash}-elem {%hash.WHAT.gist} \%hash got the right \$key");
98 is($value, 'baz', "for(): from {+%hash}-elem {%hash.WHAT.gist} \%hash got the right \$value");
8bed649 Added svn props to test scripts
cosimo authored
99 }
100
101 # The things returned by .kv should be aliases
102 {
103 my %hash = (:a(1), :b(2), :c(3));
104
105 lives_ok { for %hash.kv -> $key, $value is rw {
106 $value += 100;
107 } }, 'aliases returned by %hash.kv should be rw (1)';
108
109 is %hash<b>, 102, 'aliases returned by %hash.kv should be rw (2)';
110 }
111
112 {
113 my @array = (17, 23, 42);
114
115 lives_ok { for @array.kv -> $key, $value is rw {
116 $value += 100;
117 } }, 'aliases returned by @array.kv should be rw (1)';
118
119 is @array[1], 123, 'aliases returned by @array.kv should be rw (2)';
120 }
121
122 {
123 my $pair = (a => 42);
124
ee8a33c Will Coleda niecza fudge
coke authored
125 #?niecza todo 'aliases should be rw'
8bed649 Added svn props to test scripts
cosimo authored
126 lives_ok { for $pair.kv -> $key, $value is rw {
127 $value += 100;
128 } }, 'aliases returned by $pair.kv should be rw (1)';
129
ee8a33c Will Coleda niecza fudge
coke authored
130 #?niecza todo 'aliases should be rw'
8bed649 Added svn props to test scripts
cosimo authored
131 is $pair.value, 142, 'aliases returned by $pair.kv should be rw (2)';
132 }
133
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
134
135 # vim: ft=perl6
Something went wrong with that request. Please try again.