/
create.t
68 lines (51 loc) · 1.87 KB
/
create.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
use v6;
use Test;
plan 12;
# L<S32::Containers/"Array"/"=item ">
=begin pod
built-in "Array" tests
=end pod
my $array_obj = Array.new(4, 5, 6);
is($array_obj.WHAT.gist, Array.gist, 'Creating a new list object with new works.');
is($array_obj, list(4, 5, 6), 'The list object contains the right values.');
is(+$array_obj, 3, 'Finding the length functions properly.');
{
ok +Array[Int].new(1, 2, 3, 4), "typed array";
throws-like(q{ Array[Int].new(1, 2, "Foo") }, X::TypeCheck);
throws-like(q{ Array[Str].new(1, 2, "Foo") }, X::TypeCheck);
}
{ # coverage; 2016-09-21
is-deeply circumfix:<[ ]>(), $[], 'circumfix:<[ ]>() creates Array';
is-deeply [], $[], '[ ] creates Array';
}
# RT #130583
eval-lives-ok 「(1,2,3).Array[0]++」,
'array elements get writable containers';
{ # RT #129762
subtest 'Array.clone [partially-reified]' => {
plan 3;
my @a = 1, {rand} … *;
my @b = @a.clone;
is-deeply @a[^20], @b[^20], 'clone and original array share reifier';
@b[5] = 42;
cmp-ok @a[5], '!=', 42, 'changing clone does not impact original';
@a[3] = 72;
cmp-ok @b[3], '!=', 72, 'changing original does not impact clone';
}
subtest 'Array.clone [fully-reified]' => {
plan 5;
my @a = 1, 2, 3, 4;
my @b = @a.clone;
is-deeply @a, @b, 'clone and original array have same values';
@b[3] = 42;
cmp-ok @a[3], '!=', 42, 'changing clone does not impact original';
@a[2] = 72;
cmp-ok @b[2], '!=', 72, 'changing original does not impact clone';
@b.push: 42;
is-deeply +@b, 1+@a, 'adding items to clone does not affect original';
@a.append: 42, 72;
is-deeply +@a, 1+@b, 'adding items to original does not affect clone';
}
is-deeply Array.clone, Array, 'Array:U clone gives an Array:U';
}
# vim: ft=perl6