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
#![crate_type= "lib"]
pub use args::{Arg, SubCommand, ArgMatches};
pub use app::App;
mod app;
mod args;
#[cfg(test)]
mod tests {
use super::{App, Arg, SubCommand};
#[test]
fn create_app() {
let _ = App::new("test").version("1.0").author("kevin").about("does awesome things").get_matches();
}
#[test]
fn add_multiple_arg() {
let _ = App::new("test")
.args( vec![
Arg::new("test").short("s"),
Arg::new("test2").short("l")])
.get_matches();
}
#[test]
fn create_flag() {
let _ = App::new("test")
.arg(Arg::new("test")
.short("t")
.long("test")
.help("testing testing"))
.get_matches();
}
#[test]
fn create_positional() {
let _ = App::new("test")
.arg(Arg::new("test")
.index(1)
.help("testing testing"))
.get_matches();
}
#[test]
fn create_option() {
let _ = App::new("test")
.arg(Arg::new("test")
.short("t")
.long("test")
.takes_value(true)
.help("testing testing"))
.get_matches();
}
#[test]
fn create_subcommand() {
let _ = App::new("test")
.subcommand(SubCommand::new("some")
.arg(Arg::new("test")
.short("t")
.long("test")
.takes_value(true)
.help("testing testing")))
.arg(Arg::new("other").long("other"))
.get_matches();
}
#[test]
fn create_multiple_subcommands() {
let _ = App::new("test")
.subcommands(vec![ SubCommand::new("some")
.arg(Arg::new("test")
.short("t")
.long("test")
.takes_value(true)
.help("testing testing")),
SubCommand::new("add")
.arg(Arg::new("roster").short("r"))])
.arg(Arg::new("other").long("other"))
.get_matches();
}
#[test]
#[should_panic]
fn unique_arg_names(){
App::new("some").args(vec![
Arg::new("arg").short("a"),
Arg::new("arg").short("b")
]);
}
#[test]
#[should_panic]
fn unique_arg_shorts(){
App::new("some").args(vec![
Arg::new("arg1").short("a"),
Arg::new("arg2").short("a")
]);
}
#[test]
#[should_panic]
fn unique_arg_longs(){
App::new("some").args(vec![
Arg::new("arg1").long("long"),
Arg::new("arg2").long("long")
]);
}
}