From: Richard Whitehouse Date: Mon, 22 Oct 2018 12:42:41 +0000 (-0400) Subject: Add tests for chartype X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=886a2a2d022ce4c2ddfcec11b2f1cb9c883653ef;p=rust-sip.git Add tests for chartype --- 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); + } +}