/
03-default.t
38 lines (29 loc) · 963 Bytes
/
03-default.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
use v6.c;
use Test;
use Trait::Env;
class TestClass {
has $.attribute is env is default("attr");
has $.attribute-two is default("attr2") is env;
has $.attribute-three is env(:default<attr3>);
}
subtest {
temp %*ENV = {
ATTRIBUTE => "Here",
ATTRIBUTE_TWO => "Here2",
ATTRIBUTE_THREE => "Here3"
};
my $tc;
ok $tc = TestClass.new(), "Test Class created OK";
is $tc.attribute, "Here", "We have a test value";
is $tc.attribute-two, "Here2", "We have a test value";
is $tc.attribute-three, "Here3", "We have a test value";
}, "Defaults OK work and are ignored";
subtest {
temp %*ENV = {};
my $tc;
ok $tc = TestClass.new(), "Test Class created OK";
is $tc.attribute, "attr", "Test value is default";
is $tc.attribute-two, "attr2", "Test value is default";
is $tc.attribute-three, "attr3", "Internal default works";
}, "Defaults OK.";
done-testing;