use super::preprocess;
pub fn test_substitution<F>(filter_name: &str, mut substitute: F, tests: &[(&str, &str)])
where
F: FnMut(&slog::Logger, &mut String),
{
let mut string = String::new();
let log = crate::build_logger();
for (input, expected) in tests {
string.clear();
string.push_str(input);
info!(log, "Testing {} substitution", filter_name; "input" => input, "expected" => expected);
substitute(&log, &mut string);
assert_eq!(
&string, expected,
"Output of {} substitution test didn't match",
filter_name,
);
}
}
const PREFILTER_TEST_CASES: [(&str, &str); 10] = [
("", ""),
("tab\ttest", "tab test"),
(
"fn main() {\n\tprintln!();\n\tlet _ = ();\n}",
"fn main() {\n println!();\n let _ = ();\n}",
),
("newlines:\r\nA\rB\nC\nD\n\rE", "newlines:\nA\nB\nC\nD\n\nE"),
(
"compress:\nA\n\nB\n\n\nC\n\n\n\nD\n\n\n\n\nE\n\n\n\n\n\n",
"compress:\nA\n\nB\n\nC\n\nD\n\nE",
),
(
"concat:\nApple Banana \\\nCherry\\\nPineapple \\ Grape\nBlueberry\n",
"concat:\nApple Banana CherryPineapple \\ Grape\nBlueberry",
),
("[\n \n \n \n \n \n \n \n]", "[\n\n]"),
(
"SCP-4455-Ω said, ``It was a dark and stormy night. I looked down on my arch-nemesis, the Streamliner.''",
"SCP-4455-Ω said, “It was a dark and stormy night. I looked down on my arch-nemesis, the Streamliner.”",
),
(
",,あんたはばかです!''\n``Ehh?''\n,,ほんと!''",
"„あんたはばかです!”\n“Ehh?”\n„ほんと!”",
),
(
" . . . I'm not sure about this,",
" … I'm not sure about this,",
),
];
#[test]
fn prefilter() {
test_substitution(
"prefilter",
|log, text| preprocess(log, text),
&PREFILTER_TEST_CASES,
);
}