-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqualifying_rules.rs
More file actions
122 lines (102 loc) · 2.55 KB
/
qualifying_rules.rs
File metadata and controls
122 lines (102 loc) · 2.55 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
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
use dotenv_cli::qualifying_rules::{qualifying_rules, Options};
fn options() -> Options {
Options {
full_env_path: ".env".to_string(),
env_object: None,
json: false,
no_json: false,
multiline: false,
action_set: false,
action_delete: false,
single_key: false,
return_all_keys: false,
target_keys: Vec::new(),
set_value: None,
debug: false,
}
}
fn error_message(opts: Options) -> String {
qualifying_rules(&opts).unwrap_err().to_string()
}
#[test]
fn allows_read_flags_without_set_or_delete() {
let mut opts = options();
opts.json = true;
opts.no_json = true;
opts.multiline = true;
opts.return_all_keys = true;
assert!(qualifying_rules(&opts).is_ok());
}
#[test]
fn allows_set_with_a_single_key() {
let mut opts = options();
opts.action_set = true;
opts.single_key = true;
assert!(qualifying_rules(&opts).is_ok());
}
#[test]
fn rejects_json_with_set() {
let mut opts = options();
opts.json = true;
opts.action_set = true;
opts.single_key = true;
assert_eq!(error_message(opts), "Cannot use --json and --set together");
}
#[test]
fn rejects_set_without_a_single_key() {
let mut opts = options();
opts.action_set = true;
assert_eq!(
error_message(opts),
"Must specify a single key when using --set"
);
}
#[test]
fn allows_delete_with_a_single_key() {
let mut opts = options();
opts.action_delete = true;
opts.single_key = true;
assert!(qualifying_rules(&opts).is_ok());
}
#[test]
fn rejects_delete_with_set() {
let mut opts = options();
opts.action_delete = true;
opts.action_set = true;
opts.single_key = true;
assert_eq!(
error_message(opts),
"Cannot use --delete with any other options"
);
}
#[test]
fn rejects_delete_with_json() {
let mut opts = options();
opts.action_delete = true;
opts.json = true;
opts.single_key = true;
assert_eq!(
error_message(opts),
"Cannot use --delete with any other options"
);
}
#[test]
fn rejects_delete_with_multiline() {
let mut opts = options();
opts.action_delete = true;
opts.multiline = true;
opts.single_key = true;
assert_eq!(
error_message(opts),
"Cannot use --delete with any other options"
);
}
#[test]
fn rejects_delete_without_a_single_key() {
let mut opts = options();
opts.action_delete = true;
assert_eq!(
error_message(opts),
"Must specify a single key when using --delete"
);
}