aboutsummaryrefslogtreecommitdiff
path: root/tests/test_chain.rs
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-09-22 10:51:41 -0700
committerJoel Galenson <jgalenson@google.com>2021-09-22 10:51:41 -0700
commit12f62b94d6ccdca90dcd0edfbff82031fec3912f (patch)
tree8e48eb122f9388d510dacf7066a11e16c9b411d3 /tests/test_chain.rs
parent199730d90816980d7cac4cb1dabcce07bc548a38 (diff)
downloadbytes-12f62b94d6ccdca90dcd0edfbff82031fec3912f.tar.gz
Upgrade rust/crates/bytes to 1.1.0
Test: make Change-Id: I62c795247b1a9f37ec66c3ef6b1add6b78530482
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());
+}