/
06-arrays.t
130 lines (92 loc) · 2.67 KB
/
06-arrays.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
use v6.c;
use Test;
use Trait::Env;
class TestClass {
has @.simple-array is env(:default([1,2]));
}
subtest {
temp %*ENV = (
:SIMPLE_ARRAY_1<1>,
:SIMPLE_ARRAY_2<2>,
:SIMPLE_ARRAY_3<3>,
:SIMPLE_ARRAY_4<4>,
:NOT_ARRAY<5>
);
my $tc = TestClass.new();
is $tc.simple-array, ["1","2","3","4"], "Simple Array Works";
}, "Simple Numeric Array";
subtest {
temp %*ENV = (
:SIMPLE_ARRAY_A<1>,
:SIMPLE_ARRAY_B<2>,
:SIMPLE_ARRAY_C<3>,
:SIMPLE_ARRAY_D<4>,
:NOT_ARRAY<10>
);
my $tc = TestClass.new();
is $tc.simple-array, ["1","2","3","4"], "Simple Array Works";
}, "Lexical Ordering";
subtest {
temp %*ENV = (
:SIMPLE_ARRAY1<4>,
:SIMPLE_ARRAY2<3>,
:SIMPLE_ARRAY3<2>,
:SIMPLE_ARRAY4<1>
);
my $tc = TestClass.new();
is $tc.simple-array, ["4","3","2","1"], "Ordering on keys works";
}, "Check Ordering";
subtest {
temp %*ENV = ();
my $tc = TestClass.new();
is $tc.simple-array, [1,2], "Default OK";
}, "Check Default";
subtest {
my $value = <1 2 3 4>.join($*DISTRO.path-sep);
temp %*ENV = ( SIMPLE_ARRAY => $value );
my $tc = TestClass.new();
is $tc.simple-array, ["1","2","3","4"], "Fallback to path-sep works";
}, "If there's only one variable we default to path-sep";
class RequiredTest {
has @.required-array is env(:required);
}
subtest {
temp %*ENV = ();
throws-like { my $tc = RequiredTest.new() }, X::Trait::Env::Required::Not::Set, "Test Class dies with missing required";
}, "Required test";
class TypeTest {
has Bool @.bool is env;
has Int @.int is env;
has @.arr is env;
}
subtest {
temp %*ENV = ();
my $tc = TypeTest.new();
ok $tc.bool ~~ Array[Bool], "We have any empty type";
ok $tc.int ~~ Array[Int], "We have any empty type";
ok $tc.arr ~~ Array, "Empty Array";
}, "Empty Typed";
subtest {
temp %*ENV = ( :INTA<1>, :INTB<2>, :INTC<3> );
my $tc = TypeTest.new();
is-deeply $tc.int, Array[Int].new(1,2,3), "We have an array";
}, "Int Typed";
subtest {
temp %*ENV = ( :BOOL_A<True>, :BOOL_B<False>, :BOOL_C<1>, :BOOL_D('') );
my $tc = TypeTest.new();
is-deeply $tc.bool, Array[Bool].new(True,False,True,False), "We have an array";
}, "Bool Typed";
class SepTest {
has @.list is env{:sep<:>, :default( [1,2] ) };
}
subtest {
temp %*ENV = ( :LIST<1:2:3:4:5> );
my $tc = SepTest.new();
is $tc.list, <1 2 3 4 5>, "We have a seperated list";
}, "Seperated list";
subtest {
temp %*ENV = ();
my $tc = SepTest.new();
is $tc.list, <1 2>, "Default OK";
}, "Seperated list with default";
done-testing;