1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

body tests

This commit is contained in:
Nikolay Kim 2017-10-24 00:09:52 -07:00
parent ccb3f61d70
commit 5e54a80064

View File

@ -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());
}
}