From a2b5d44f1aa9d64f448a2a3cc2001272e2f60b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 1 Feb 2021 19:09:25 +0100 Subject: refactor: Reorganise integration tests (#9282) This commit reorganises cli/tests/integration_tests.rs. All integration tests had been moved into integration module, which allows to run only integration tests by "cargo test integration". Additionally some tests were further grouped under nested modules like "inspector", "file_watcher" or "repl". --- test_util/src/lib.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'test_util/src') diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 14ec723f2..da7c8703e 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -1558,6 +1558,70 @@ mod tests { } } + #[test] + fn test_pattern_match() { + // foo, bar, baz, qux, quux, quuz, corge, grault, garply, waldo, fred, plugh, xyzzy + + let wildcard = "[BAR]"; + assert!(pattern_match("foo[BAR]baz", "foobarbaz", wildcard)); + assert!(!pattern_match("foo[BAR]baz", "foobazbar", wildcard)); + + let multiline_pattern = "[BAR] +foo: +[BAR]baz[BAR]"; + + fn multi_line_builder(input: &str, leading_text: Option<&str>) -> String { + // If there is leading text add a newline so it's on it's own line + let head = match leading_text { + Some(v) => format!("{}\n", v), + None => "".to_string(), + }; + format!( + "{}foo: +quuz {} corge +grault", + head, input + ) + } + + // Validate multi-line string builder + assert_eq!( + "QUUX=qux +foo: +quuz BAZ corge +grault", + multi_line_builder("BAZ", Some("QUUX=qux")) + ); + + // Correct input & leading line + assert!(pattern_match( + multiline_pattern, + &multi_line_builder("baz", Some("QUX=quux")), + wildcard + )); + + // Correct input & no leading line + assert!(pattern_match( + multiline_pattern, + &multi_line_builder("baz", None), + wildcard + )); + + // Incorrect input & leading line + assert!(!pattern_match( + multiline_pattern, + &multi_line_builder("garply", Some("QUX=quux")), + wildcard + )); + + // Incorrect input & no leading line + assert!(!pattern_match( + multiline_pattern, + &multi_line_builder("garply", None), + wildcard + )); + } + #[test] fn max_mem_parse() { const TEXT: &str = include_str!("./testdata/time.out"); -- cgit v1.2.3