Add tests for chartype
authorRichard Whitehouse <github@richardwhiuk.com>
Mon, 22 Oct 2018 12:42:41 +0000 (08:42 -0400)
committerRichard Whitehouse <github@richardwhiuk.com>
Mon, 22 Oct 2018 12:42:41 +0000 (08:42 -0400)
src/codec.rs

index 6921f7a9020f2d87c50149fd9dacaf018410e765..b1d298c157a1aae5414ada58c54a134ded5e1708 100644 (file)
@@ -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);
+    }
+}