From 12f62b94d6ccdca90dcd0edfbff82031fec3912f Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Wed, 22 Sep 2021 10:51:41 -0700 Subject: Upgrade rust/crates/bytes to 1.1.0 Test: make Change-Id: I62c795247b1a9f37ec66c3ef6b1add6b78530482 --- tests/test_chain.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test_chain.rs') 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()); +} -- cgit v1.2.3