Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 114 lines (96 sloc) 2.602 kB
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
1 use v6;
2
3 use Test;
4
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
5 plan 25;
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
6
4242675 [gsoc_spectest] smartlink cleanups
Auzon authored
7 # L<S09/Autovivification/In Perl 6 these read-only operations are indeed non-destructive:>
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
8 {
cb5beb6 @lizmat Some more test passing now that we have Any.exists
lizmat authored
9 my %h;
10 my $b = %h<a><b>;
11 is %h.keys.elems, 0, "fetching doesn't autovivify.";
12 ok $b === Any, 'and the return value is not defined';
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
13 }
14
15 {
cb5beb6 @lizmat Some more test passing now that we have Any.exists
lizmat authored
16 my %h;
17 my $exists = %h<a><b>:exists;
18 is %h.keys.elems, 0, "exists doesn't autovivify.";
19 ok $exists === False, '... and it returns the right value';
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
20 }
21
4242675 [gsoc_spectest] smartlink cleanups
Auzon authored
22 # L<S09/Autovivification/But these bindings do autovivify:>
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
23 {
cb5beb6 @lizmat Some more test passing now that we have Any.exists
lizmat authored
24 my %h;
25 bar(%h<a><b>);
26 is %h.keys.elems, 0, "in ro arguments doesn't autovivify.";
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
27 }
28
29 {
cb5beb6 @lizmat Some more test passing now that we have Any.exists
lizmat authored
30 my %h;
31 my $b := %h<a><b>;
6ef1b5d @coke niecza fudge
coke authored
32 #?niecza todo "https://github.com/sorear/niecza/issues/176"
cb5beb6 @lizmat Some more test passing now that we have Any.exists
lizmat authored
33 is %h.keys.elems, 0, 'binding does not immediately autovivify';
34 ok $b === Any, '... to an undefined value';
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
35 $b = 42;
cb5beb6 @lizmat Some more test passing now that we have Any.exists
lizmat authored
36 is %h.keys.elems, 1, '.. but autovivifies after assignment';
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
37 is %h<a><b>, 42, 'having it in there';
cb5beb6 @lizmat Some more test passing now that we have Any.exists
lizmat authored
38 ok %h<a><b> =:= $b, 'check binding';
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
39 }
40
41 {
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
42 my %h;
43 my $b = \(%h<a><b>);
44 is %h.keys.elems, 0, 'capturing does not autovivify';
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
45 }
46
47 {
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
48 my %h;
49 foo(%h<a><b>);
6ef1b5d @coke niecza fudge
coke authored
50 #?niecza todo "https://github.com/sorear/niecza/issues/176"
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
51 is %h.keys.elems, 0, 'in rw arguments does not autovivify';
52 foo(%h<a><b>,42);
53 is %h.keys.elems, 1, 'storing from within the sub does autovivify';
54 is %h<a><b>, 42, 'got the right value';
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
55 }
56
57 {
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
58 my %h;
59 %h<a><b> = 42;
60 is %h.keys.elems, 1, 'store autovivify.';
61 is %h<a><b>, 42, 'got the right value';
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
62 }
63
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
64 # helper subs
65 sub foo ($baz is rw, $assign? ) { $baz = $assign if $assign }
66 sub bar ($baz is readonly) { }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
67
ef0e875 @moritz RT #77038, &push autovivifies its first argument
moritz authored
68 # RT #77038
26a959e @colomon Fudge for Niecza.
colomon authored
69 #?niecza skip "Unable to resolve method push in type Any"
ef0e875 @moritz RT #77038, &push autovivifies its first argument
moritz authored
70 {
71 my %h;
72 push %h<a>, 4, 2;
73 is %h<a>.join, '42', 'can autovivify in sub form of push';
0b03c96 &unshift autovivifies its first argument
Jimmy Zhuo authored
74 unshift %h<b>, 5, 3;
75 is %h<b>.join, '53', 'can autovivify in sub form of unshift';
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
76 %h<c><d>.push( 7, 8 );
77 is %h<c><d>.join, '78', 'can autovivify in method form of push';
78 %h<e><f>.unshift( 9, 10 );
79 is %h<e><f>.join, '910', 'can autovivify in method form of unshift';
80 is %h.keys.elems, 4, 'successfully autovivified lower level';
81 }
82
83 {
84 my $a;
85 $a[0] = '4';
86 $a[1] = '2';
87 is $a.join, '42', 'Can autovivify Array';
ef0e875 @moritz RT #77038, &push autovivifies its first argument
moritz authored
88 }
89
5436ea7 @moritz RT #77048, autovivification of Array-typed scalars
moritz authored
90 # RT #77048
91 {
92 my Array $a;
93 $a[0] = '4';
94 $a[1] = '2';
95 is $a.join, '42', 'Can autovivify Array-typed scalar';
96 }
97
478c26a @lizmat Add some more auto-vivification tests
lizmat authored
98 {
99 my $h;
100 $h<a> = '4';
101 $h<b> = '2';
102 is $h<a b>.join, '42', 'Can autovivify Hash';
103 }
104
105 {
106 my Hash $h;
107 $h<a> = '4';
108 $h<b> = '2';
109 is $h<a b>.join, '42', 'Can autovivify Hash-typed scalar';
110 }
111
112
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
113 # vim: ft=perl6
Something went wrong with that request. Please try again.