From 886a2a2d022ce4c2ddfcec11b2f1cb9c883653ef Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Mon, 22 Oct 2018 08:42:41 -0400 Subject: [PATCH] Add tests for chartype --- src/codec.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/codec.rs b/src/codec.rs index 6921f7a..b1d298c 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -332,6 +332,7 @@ impl Encoder for SipCodec { } } +#[derive(PartialEq, Debug)] enum CharType { Line, Whitespace, @@ -345,3 +346,46 @@ fn chartype(char: Option<&u8>) -> CharType { Some(_) => CharType::Other, } } + +#[cfg(test)] +mod tests { + + use super::*; + + #[test] + fn test_chartype_none() { + assert_eq!(chartype(None), CharType::Line); + } + + #[test] + fn test_chartype_cr() { + assert_eq!(chartype(Some(&LF)), CharType::Line); + } + + #[test] + fn test_chartype_lf() { + assert_eq!(chartype(Some(&CR)), CharType::Line); + } + + #[test] + fn test_chartype_space() { + assert_eq!(chartype(Some(&SPACE)), CharType::Whitespace); + } + + #[test] + fn test_chartype_tab() { + assert_eq!(chartype(Some(&TAB)), CharType::Whitespace); + } + + #[test] + fn test_chartype_alpha() { + const A: u8 = b'a'; + assert_eq!(chartype(Some(&A)), CharType::Other); + } + + #[test] + fn test_chartype_number() { + const ONE: u8 = b'1'; + assert_eq!(chartype(Some(&ONE)), CharType::Other); + } +} -- 2.34.1