/
02-env-only.t
75 lines (57 loc) · 1.81 KB
/
02-env-only.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
use v6.c;
use Test;
use Trait::Env;
use lib "{$*PROGRAM.dirname}/lib";
use Config;
class TestClass {
has $.attribute is env;
has $.ATTRIBUTE is env;
has $.dash-to-underscore is env;
has $.dash_to_underscore is env;
has Int $.int is env;
has Bool $.bool is env;
has Str $.str is env;
}
subtest {
temp %*ENV = { "ATTRIBUTE" => "Here" };
my $tc;
ok $tc = TestClass.new(), "Test Class created OK";
is $tc.attribute, "Here", "We have a test value";
is $tc.ATTRIBUTE, "Here", "We have a test value (uc WORKS)";
}, "Basic Test Class. ENV Var exists";
subtest {
temp %*ENV = {};
my $tc;
ok $tc = TestClass.new(), "Test Class created OK";
is $tc.attribute, Any, "Test value is undefined";
}, "Basic Test Class. ENV Var not set";
subtest {
temp %*ENV = { "DASH_TO_UNDERSCORE" => "Worked" };
my $tc;
ok $tc = TestClass.new(), "Test Class created OK";
is $tc.dash-to-underscore, "Worked", "Dashes converted";
is $tc.dash_to_underscore, "Worked", "Underscore version works too.";
}, "Dashes -> Underscores";
subtest {
temp %*ENV = { INT => "5", BOOL => "", STR => "String" };
my $tc;
ok $tc = TestClass.new(), "Test Class created OK";
is $tc.int, 5, "Integer interploated";
is $tc.bool, False, "Bool interpolated";
is $tc.str, "String", "String interpolated";
}, "Interpolation";
subtest {
temp %*ENV = {};
my $tc;
ok $tc = TestClass.new(), "Test Class created OK";
is $tc.int, Int, "Integer not found";
is $tc.bool, Bool, "Bool not found";
is $tc.str, Str, "String not found";
}, "Interpolation not found";
subtest {
temp %*ENV = { :VALUE<value> }
my $c;
ok $c = Config.new(), "External Class created OK";
is $c.value, 'value', "Config value OK";
}, "External class test";
done-testing;