clap/src/lib.rs

113 lines
3 KiB
Rust
Raw Normal View History

2015-02-28 03:19:48 +00:00
#![crate_type= "lib"]
2015-03-18 23:42:06 +00:00
// DOCS
2015-02-28 03:19:48 +00:00
pub use args::{Arg, SubCommand, ArgMatches};
2015-02-25 13:37:25 +00:00
pub use app::App;
mod app;
mod args;
2015-03-03 18:57:19 +00:00
#[cfg(test)]
mod tests {
2015-03-24 16:16:59 +00:00
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")
]);
}
}