/
autovivification.t
140 lines (114 loc) 路 2.13 KB
/
autovivification.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use v6;
use Test;
plan 23;
# L<S03/Assignment operators/>
{
my $x;
$x++;
ok $x == 1, 'my $x; $x++ works'
}
{
my Int $x;
$x++;
ok $x == 1, 'my Int $x; $x++ works'
}
{
my $x;
$x += 1;
ok $x == 1, 'my $x; $x += 1 works'
}
{
my Int $x;
$x += 1;
ok $x == 1, 'my Int $x; $x += 1 works'
}
{
my $x;
$x -= 1;
ok $x == -1, 'my $x; $x -= 1 works'
}
{
my Int $x;
$x -= 1;
ok $x == -1, 'my Int $x; $x -= 1 works'
}
{
my $s;
$s ~= 'ab';
is $s, 'ab', 'my $s; $s ~= "ab" works'
}
{
my Str $s;
$s ~= 'ab';
is $s, 'ab', 'my Str $s; $s ~= "ab" works'
}
{
my $x;
$x *= 2;
ok $x == 2, 'my $x; $x *= 2 works'
}
{
my $x;
$x **= 2;
ok $x == 1, 'my $x; $x **= 2 works'
}
{
my Int $x;
$x *= 2;
ok $x == 2, 'my Int $x; $x *= 2 works'
}
{
my Int $x;
$x **= 2;
ok $x == 1, 'my Int $x; $x **= 2 works'
}
{
my $x;
$x = $x + 1i;
is-approx($x, 0 + 1i, 'my $x; $x = $x + 1i; works');
}
{
my $x;
$x += 1i;
is-approx($x, 0 + 1i, 'my $x; $x += 1i; works');
}
{
my $i **= $i;
is $i, 1, 'my $i **= $i';
}
{
my $x;
$x *= 1i;
is-approx($x, 1i, 'my $x; $x *= 1i works');
}
# L<S03/Assignment operators/"If you apply an assignment operator to a
# container">
{
# yes, this is serious. It's in the specs ;-)
my Int $x;
$x *= 5;
is $x, 5, '*= autovivifies with correct neutral element (with Num proto)';
}
{
my $x;
$x *= 5;
is $x, 5, '*= autovivifies with correct neutral element (without type constraint)';
}
{
my Int %h;
is (%h<foo> *= 23), 23, '*= autovivifies with correct neutral element (with Int proto on hash items)';
}
{
my %h;
is (%h<foo> *= 23), 23, '*= autovivifies with correct neutral element (without proto on hash items)';
}
{
my @empty;
is +@empty, 0, 'Sanity: empty array, @empty, has 0 elements';
my $before = @empty.perl;
@empty[5] ~~ /nothing/;
my $after = @empty.perl;
is +@empty,0,'empty array, @empty, has 0 elements';
is $after,$before,"Array elements are not auto-vivified by smartmatch";
}
# vim: ft=perl6