From 5e54a80064ea19b505915db4698be40cd575b08b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 24 Oct 2017 00:09:52 -0700 Subject: [PATCH] body tests --- src/body.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/body.rs b/src/body.rs index 3bdc975e9..155710958 100644 --- a/src/body.rs +++ b/src/body.rs @@ -174,3 +174,71 @@ impl AsRef<[u8]> for BinaryBody { } } } + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_static_str() { + assert_eq!(BinaryBody::from("test").len(), 4); + assert_eq!(BinaryBody::from("test").as_ref(), "test".as_bytes()); + } + + #[test] + fn test_static_bytes() { + assert_eq!(BinaryBody::from(b"test".as_ref()).len(), 4); + assert_eq!(BinaryBody::from(b"test".as_ref()).as_ref(), "test".as_bytes()); + assert_eq!(BinaryBody::from_slice(b"test".as_ref()).len(), 4); + assert_eq!(BinaryBody::from_slice(b"test".as_ref()).as_ref(), "test".as_bytes()); + } + + #[test] + fn test_vec() { + assert_eq!(BinaryBody::from(Vec::from("test")).len(), 4); + assert_eq!(BinaryBody::from(Vec::from("test")).as_ref(), "test".as_bytes()); + } + + #[test] + fn test_bytes() { + assert_eq!(BinaryBody::from(Bytes::from("test")).len(), 4); + assert_eq!(BinaryBody::from(Bytes::from("test")).as_ref(), "test".as_bytes()); + } + + #[test] + fn test_rc_bytes() { + let b = Rc::new(Bytes::from("test")); + assert_eq!(BinaryBody::from(b.clone()).len(), 4); + assert_eq!(BinaryBody::from(b.clone()).as_ref(), "test".as_bytes()); + assert_eq!(BinaryBody::from(&b).len(), 4); + assert_eq!(BinaryBody::from(&b).as_ref(), "test".as_bytes()); + } + + #[test] + fn test_rc_string() { + let b = Rc::new("test".to_owned()); + assert_eq!(BinaryBody::from(b.clone()).len(), 4); + assert_eq!(BinaryBody::from(b.clone()).as_ref(), "test".as_bytes()); + assert_eq!(BinaryBody::from(&b).len(), 4); + assert_eq!(BinaryBody::from(&b).as_ref(), "test".as_bytes()); + } + + #[test] + fn test_arc_bytes() { + let b = Arc::new(Bytes::from("test")); + assert_eq!(BinaryBody::from(b.clone()).len(), 4); + assert_eq!(BinaryBody::from(b.clone()).as_ref(), "test".as_bytes()); + assert_eq!(BinaryBody::from(&b).len(), 4); + assert_eq!(BinaryBody::from(&b).as_ref(), "test".as_bytes()); + } + + #[test] + fn test_arc_string() { + let b = Arc::new("test".to_owned()); + assert_eq!(BinaryBody::from(b.clone()).len(), 4); + assert_eq!(BinaryBody::from(b.clone()).as_ref(), "test".as_bytes()); + assert_eq!(BinaryBody::from(&b).len(), 4); + assert_eq!(BinaryBody::from(&b).as_ref(), "test".as_bytes()); + } +}