-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_object.rs
More file actions
54 lines (51 loc) · 1.43 KB
/
env_object.rs
File metadata and controls
54 lines (51 loc) · 1.43 KB
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
use dotenv_cli::env_object::{EnvObject, EnvValue};
#[test]
fn resolve_single_variable() {
let mut env = EnvObject::new();
env.set(
"VAR1".to_string(),
EnvValue::with_lines("Hello".to_string(), 0, 0),
);
env.set(
"VAR2".to_string(),
EnvValue::with_lines("${VAR1} World".to_string(), 1, 1),
);
env.resolve_nested_variables();
assert_eq!(env.get("VAR2").unwrap().value, "Hello World");
}
#[test]
fn resolve_two_variables() {
let mut env = EnvObject::new();
env.set(
"VAR1".to_string(),
EnvValue::with_lines("Hello".to_string(), 0, 0),
);
env.set(
"VAR2".to_string(),
EnvValue::with_lines("World".to_string(), 1, 1),
);
env.set(
"VAR3".to_string(),
EnvValue::with_lines("${VAR1} ${VAR2}".to_string(), 2, 2),
);
env.resolve_nested_variables();
assert_eq!(env.get("VAR3").unwrap().value, "Hello World");
}
#[test]
fn resolve_merged_value() {
let mut env = EnvObject::new();
env.set(
"VAR1".to_string(),
EnvValue::with_lines("Hello".to_string(), 0, 0),
);
env.set(
"VAR2".to_string(),
EnvValue::with_lines("${VAR1} World".to_string(), 1, 1),
);
env.set(
"VAR3".to_string(),
EnvValue::with_lines("${VAR2} & Universe".to_string(), 2, 2),
);
env.resolve_nested_variables();
assert_eq!(env.get("VAR3").unwrap().value, "Hello World & Universe");
}