-
Notifications
You must be signed in to change notification settings - Fork 4
/
vdotenv_test.v
72 lines (62 loc) · 1.86 KB
/
vdotenv_test.v
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
module vdotenv
import os
/*
Sample .env file for tests:
.env
TEST=OVERLOADENV
TEST1='LOADENV'
TEST2=LOADENV
#TEST3=NOLOADENV
TEST4=NOHASH#COMMENTSTARTSHERe
TEST5=NOHASH #TEST6=NOLOADENV
TEST7 = "HASH #ENV" # COMMENT
.env.parse
WORDONE=HELLO
WORDTWO=WORLD
*/
fn test_load() {
// loads env vars from a .env file.
load()
env_var := os.getenv('TEST2')
assert env_var == 'LOADENV'
}
fn test_load_quoted() {
// loads env vars from a .env file.
load()
env_var := os.getenv('TEST1')
assert env_var == 'LOADENV'
}
fn test_over_load() {
// over loads env vars from .env file.
over_load()
env_var := os.getenv('TEST')
assert env_var == 'OVERLOADENV'
}
fn test_comments_start_line() {
// loads env vars and verifies that comments that start a line are ignored
load()
env_var := os.getenv('TEST3')
assert env_var == ''
}
fn test_comments_end_line() {
load()
// loads env vars and verifies that comments are removed from the end of values
env_var := os.getenv('TEST4')
assert env_var == 'NOHASH'
env_var2 := os.getenv('TEST5')
assert env_var2 == 'NOHASH'
}
fn test_quoted_hash() {
load()
// load env vars and verify comments are ignored without affecting hashes within quotes
env_var := os.getenv('TEST7')
assert env_var == 'HASH #ENV'
}
fn test_parse() {
// test that returning a hash of env vars parsed from the default '.env' file
assert parse(true) == '{ /* file: .env */ "TEST" : "OVERLOADENV", "TEST1" : "LOADENV", "TEST2" : "LOADENV", "TEST4" : "NOHASH", "TEST5" : "NOHASH", "TEST7" : "HASH #ENV" }'
}
fn test_parse_multifiles() {
// test that returning a hash of env vars parsed from a variable number of files
assert parse(true, '.env', '.env.parse') == '{ /* file: .env */ "TEST" : "OVERLOADENV", "TEST1" : "LOADENV", "TEST2" : "LOADENV", "TEST4" : "NOHASH", "TEST5" : "NOHASH", "TEST7" : "HASH #ENV", /* file: .env.parse */ "WORDONE" : "HELLO", "WORDTWO" : "WORLD" }'
}