diff options
author | Joel Galenson <jgalenson@google.com> | 2021-09-23 14:36:41 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-09-23 14:36:41 +0000 |
commit | 71a27c276bb9be9a39d10d082d01411f3ab82a2b (patch) | |
tree | 8e48eb122f9388d510dacf7066a11e16c9b411d3 /tests/test_bytes.rs | |
parent | 4793c4dfd140da5df7a79394901aa8454ba46f76 (diff) | |
parent | 12f62b94d6ccdca90dcd0edfbff82031fec3912f (diff) | |
download | bytes-71a27c276bb9be9a39d10d082d01411f3ab82a2b.tar.gz |
Upgrade rust/crates/bytes to 1.1.0 am: 12f62b94d6
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/bytes/+/1833594
Change-Id: Ic4433b68fef32c41a08a00a829f93be105cc4e8b
Diffstat (limited to 'tests/test_bytes.rs')
-rw-r--r-- | tests/test_bytes.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index b9e6ce4..f0cae99 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -785,6 +785,31 @@ fn bytes_mut_unsplit_empty_self() { } #[test] +fn bytes_mut_unsplit_other_keeps_capacity() { + let mut buf = BytesMut::with_capacity(64); + buf.extend_from_slice(b"aabb"); + + // non empty other created "from" buf + let mut other = buf.split_off(buf.len()); + other.extend_from_slice(b"ccddee"); + buf.unsplit(other); + + assert_eq!(buf.capacity(), 64); +} + +#[test] +fn bytes_mut_unsplit_empty_other_keeps_capacity() { + let mut buf = BytesMut::with_capacity(64); + buf.extend_from_slice(b"aabbccddee"); + + // empty other created "from" buf + let other = buf.split_off(buf.len()); + buf.unsplit(other); + + assert_eq!(buf.capacity(), 64); +} + +#[test] fn bytes_mut_unsplit_arc_different() { let mut buf = BytesMut::with_capacity(64); buf.extend_from_slice(b"aaaabbbbeeee"); @@ -961,3 +986,19 @@ fn bytes_with_capacity_but_empty() { let vec = Vec::with_capacity(1); let _ = Bytes::from(vec); } + +#[test] +fn bytes_put_bytes() { + let mut bytes = BytesMut::new(); + bytes.put_u8(17); + bytes.put_bytes(19, 2); + assert_eq!([17, 19, 19], bytes.as_ref()); +} + +#[test] +fn box_slice_empty() { + // See https://github.com/tokio-rs/bytes/issues/340 + let empty: Box<[u8]> = Default::default(); + let b = Bytes::from(empty); + assert!(b.is_empty()); +} |