diff options
author | Ryan Geary <rtgnj42@gmail.com> | 2019-09-17 23:09:26 -0400 |
---|---|---|
committer | Ryan Geary <rtgnj42@gmail.com> | 2019-09-17 23:40:35 -0400 |
commit | 5c969552570b4f91f932d905fbe600a8dbc80f7f (patch) | |
tree | 910fcff427e122a3e23dc402f33d6a23b4f57e00 | |
parent | 4afdc50158ff090fa0b3387b3565cf0a2efc7f11 (diff) |
Add a bunch of get_choice_slice tests
-rw-r--r-- | src/choice.rs | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/choice.rs b/src/choice.rs index e6dcf59..ab56fc0 100644 --- a/src/choice.rs +++ b/src/choice.rs @@ -78,6 +78,98 @@ mod tests { //} } + mod get_choice_slice_tests { + use super::*; + + #[test] + fn print_0() { + let opt = Opt::from_iter(vec!["choose", "0"]); + assert_eq!( + vec!["rust"], + opt.choice[0].get_choice_slice(&String::from("rust is pretty cool"), &opt) + ); + } + + #[test] + fn print_after_end() { + let opt = Opt::from_iter(vec!["choose", "10"]); + assert_eq!( + Vec::<&str>::new(), + opt.choice[0].get_choice_slice(&String::from("rust is pretty cool"), &opt) + ); + } + + #[test] + fn print_1_to_3() { + let opt = Opt::from_iter(vec!["choose", "1:3"]); + assert_eq!( + vec!["is", "pretty"], + opt.choice[0].get_choice_slice(&String::from("rust is pretty cool"), &opt) + ); + } + + #[test] + fn print_1_to_3_inclusive() { + let opt = Opt::from_iter(vec!["choose", "1:3", "-n"]); + assert_eq!( + vec!["is", "pretty", "cool"], + opt.choice[0].get_choice_slice(&String::from("rust is pretty cool"), &opt) + ); + } + + #[test] + fn print_1_to_3_separated_by_hashtag() { + let opt = Opt::from_iter(vec!["choose", "1:3", "-f", "#"]); + assert_eq!( + vec!["is", "pretty"], + opt.choice[0].get_choice_slice(&String::from("rust#is#pretty#cool"), &opt) + ); + } + + #[test] + fn print_1_to_3_separated_by_varying_multiple_hashtag() { + let opt = Opt::from_iter(vec!["choose", "1:3", "-f", "#"]); + assert_eq!( + vec!["is", "pretty"], + opt.choice[0].get_choice_slice(&String::from("rust##is###pretty####cool"), &opt) + ); + } + + #[test] + fn print_1_to_3_separated_by_varying_multiple_hashtag_inclusive() { + let opt = Opt::from_iter(vec!["choose", "1:3", "-f", "#", "-n"]); + assert_eq!( + vec!["is", "pretty", "cool"], + opt.choice[0].get_choice_slice(&String::from("rust##is###pretty####cool"), &opt) + ); + } + + #[test] + fn print_1_to_3_separated_by_regex_group_vowels() { + let opt = Opt::from_iter(vec!["choose", "1:3", "-f", "[aeiou]"]); + assert_eq!( + vec![" q", "ck br"], + opt.choice[0].get_choice_slice( + &String::from("the quick brown fox jumped over the lazy dog"), + &opt + ) + ); + } + + #[test] + fn print_1_to_3_separated_by_regex_group_vowels_inclusive() { + let opt = Opt::from_iter(vec!["choose", "1:3", "-f", "[aeiou]", "-n"]); + assert_eq!( + vec![" q", "ck br", "wn f"], + opt.choice[0].get_choice_slice( + &String::from("the quick brown fox jumped over the lazy dog"), + &opt + ) + ); + } + + } + } use regex::Regex; |