aboutsummaryrefslogtreecommitdiff
path: root/tests/test_chain.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_chain.rs')
-rw-r--r--tests/test_chain.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_chain.rs b/tests/test_chain.rs
index 500ccd4..affaf7a 100644
--- a/tests/test_chain.rs
+++ b/tests/test_chain.rs
@@ -132,3 +132,24 @@ fn vectored_read() {
assert_eq!(iovecs[3][..], b""[..]);
}
}
+
+#[test]
+fn chain_get_bytes() {
+ let mut ab = Bytes::copy_from_slice(b"ab");
+ let mut cd = Bytes::copy_from_slice(b"cd");
+ let ab_ptr = ab.as_ptr();
+ let cd_ptr = cd.as_ptr();
+ let mut chain = (&mut ab).chain(&mut cd);
+ let a = chain.copy_to_bytes(1);
+ let bc = chain.copy_to_bytes(2);
+ let d = chain.copy_to_bytes(1);
+
+ assert_eq!(Bytes::copy_from_slice(b"a"), a);
+ assert_eq!(Bytes::copy_from_slice(b"bc"), bc);
+ assert_eq!(Bytes::copy_from_slice(b"d"), d);
+
+ // assert `get_bytes` did not allocate
+ assert_eq!(ab_ptr, a.as_ptr());
+ // assert `get_bytes` did not allocate
+ assert_eq!(cd_ptr.wrapping_offset(1), d.as_ptr());
+}