From 5d32a8924cffe6e98a8f0bfb5c574b0233f9ac38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sat, 28 Nov 2020 14:23:15 +0100 Subject: [PATCH] Add some tests --- src/parsers/parameters.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/parsers/parameters.rs b/src/parsers/parameters.rs index ca5f2da..c6eaa83 100644 --- a/src/parsers/parameters.rs +++ b/src/parsers/parameters.rs @@ -321,4 +321,33 @@ mod tests { Address::Ip(_) => assert!(false), }; } + + #[test] + fn test_valid_parse_filter_auth() { + let test_vectors = vec![ + ("|derp\n", "derp"), + ("|derp.derpson@example.com\r\n", "derp.derpson@example.com"), + ]; + for (test, ref_auth) in test_vectors { + let res = parse_filter_auth(test.as_bytes()); + assert!(res.is_ok()); + let (input, auth) = res.unwrap(); + assert_eq!(input, b""); + assert_eq!(auth, ref_auth.to_string()); + } + } + + #[test] + fn test_invalid_parse_filter_auth() { + let test_vectors = vec![ + "|\n", + "|\r\n", + "|derp", + "|derp|derpson\n", + ]; + for test in test_vectors { + let res = parse_filter_auth(test.as_bytes()); + assert!(!res.is_ok()); + } + } }