pirate/tests/main.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

2015-04-28 01:10:37 -04:00
extern crate pirate;
use pirate::{Matches, Match, matches, usage, vars};
2015-04-28 01:10:37 -04:00
#[test]
2015-04-28 01:10:37 -04:00
fn main() {
2015-06-24 17:02:16 -04:00
let env_args: Vec<String> = vec![String::from("test"), String::from("-a"), String::from("2"),
String::from("3")];
2015-06-28 21:53:27 -04:00
let opts = vec!["a/addend#The right side of the addition equation; default=1:", "#Required Arguments",
":augend#The left side of an addition equation"];
let mut vars = vars("test", &opts).unwrap();
2015-06-28 21:53:27 -04:00
let matches: Matches = match matches(&env_args, &mut vars) {
2015-06-10 18:14:11 +00:00
Ok(m) => m,
Err(why) => {
println!("Error: {}", why);
usage(&vars);
return;
}
2015-04-28 01:10:37 -04:00
};
if matches.has_match("help") {
usage(&vars);
return;
}
let augend: i32 = matches.get("augend").unwrap().parse::<i32>().unwrap();
let addend: i32 = match matches.get("addend") {
Some(a) => a.parse::<i32>().unwrap(),
None => 1
};
let sum = augend + addend;
assert_eq!(augend, 3);
assert_eq!(addend, 2);
assert_eq!(sum, 5);
2015-04-28 01:10:37 -04:00
}