use super::*;
fn test_fn(vec: Vec<&str>, input: &str, output: &str) {
let config = Config::from_iter(vec);
let mut handle = BufWriter::new(MockStdout::new());
config.opt.choices[0]
.print_choice(&String::from(input), &config, &mut handle)
.unwrap();
assert_eq!(
String::from(output),
MockStdout::str_from_buf_writer(handle)
);
}
#[test]
fn print_0() {
test_fn(vec!["choose", "0"], "rust is pretty cool", "rust");
}
#[test]
fn print_after_end() {
test_fn(vec!["choose", "10"], "rust is pretty cool", "");
}
#[test]
fn print_out_of_order() {
let config = Config::from_iter(vec!["choose", "3", "1"]);
let mut handle = BufWriter::new(MockStdout::new());
let mut handle1 = BufWriter::new(MockStdout::new());
config.opt.choices[0]
.print_choice(&String::from("rust is pretty cool"), &config, &mut handle)
.unwrap();
assert_eq!(
String::from("cool"),
MockStdout::str_from_buf_writer(handle)
);
config.opt.choices[1]
.print_choice(&String::from("rust is pretty cool"), &config, &mut handle1)
.unwrap();
assert_eq!(String::from("is"), MockStdout::str_from_buf_writer(handle1));
}
#[test]
fn print_1_to_3_exclusive() {
test_fn(
vec!["choose", "1:3", "-x"],
"rust is pretty cool",
"is pretty",
);
}
#[test]
fn print_1_to_3() {
test_fn(
vec!["choose", "1:3"],
"rust is pretty cool",
"is pretty cool",
);
}
#[test]
fn print_1_to_3_separated_by_hashtag() {
test_fn(
vec!["choose", "1:3", "-f", "#"],
"rust#is#pretty#cool",
"is pretty cool",
);
}
#[test]
fn print_1_to_3_separated_by_varying_multiple_hashtag_exclusive() {
test_fn(
vec!["choose", "1:3", "-f", "#", "-x"],
"rust##is###pretty####cool",
"is pretty",
);
}
#[test]
fn print_1_to_3_separated_by_varying_multiple_hashtag() {
test_fn(
vec!["choose", "1:3", "-f", "#"],
"rust##is###pretty####cool",
"is pretty cool",
);
}
#[test]
fn print_1_to_3_separated_by_regex_group_vowels_exclusive() {
test_fn(
vec!["choose", "1:3", "-f", "[aeiou]", "-x"],
"the quick brown fox jumped over the lazy dog",
" q ck br",
);
}
#[test]
fn print_1_to_3_separated_by_regex_group_vowels() {
test_fn(
vec!["choose", "1:3", "-f", "[aeiou]"],
"the quick brown fox jumped over the lazy dog",
" q ck br wn f",
);
}
#[test]
fn print_3_to_1() {
test_fn(
vec!["choose", "3:1"],
"rust lang is pretty darn cool",
"pretty is lang",
);
}
#[test]
fn print_3_to_1_exclusive() {
test_fn(
vec!["choose", "3:1", "-x"],
"rust lang is pretty darn cool",
"is lang",
);
}
#[test]
fn print_1_to_3_nonexistant_field_separator() {
test_fn(
vec!["choose", "1:3", "-f", "#"],
"rust lang is pretty darn cool",
"",
);
}
#[test]
fn print_0_nonexistant_field_separator() {
test_fn(
vec!["choose", "0", "-f", "#"],
"rust lang is pretty darn cool",
"rust lang is pretty darn cool",
);
}
#[test]
fn print_0_to_3_nonexistant_field_separator() {
test_fn(
vec!["choose", "0:3", "-f", "#"],
"rust lang is pretty darn cool",
"rust lang is pretty darn cool",
);
}
#[test]
fn print_0_with_preceding_separator() {
test_fn(
vec!["choose", "0"],