diff options
author | 2019-12-02 00:00:42 +0200 | |
---|---|---|
committer | 2019-12-01 14:00:42 -0800 | |
commit | af606aab9be1dde2aeefc1a21344a79beaba7bbe (patch) | |
tree | 3ed0e9a8d76d0628b43ef81f62908bdfa838bf7f /tests | |
parent | 98951ba26cccb0d613edf0286976aebf48257af0 (diff) | |
download | bytes-af606aab9be1dde2aeefc1a21344a79beaba7bbe.tar.gz bytes-af606aab9be1dde2aeefc1a21344a79beaba7bbe.tar.zst bytes-af606aab9be1dde2aeefc1a21344a79beaba7bbe.zip |
Fix regression in Bytes::truncate (#333)
When the length to truncate is greater than the buffer's current
length, do nothing instead of clearing the contents.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_bytes.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index 6e3c4b6..f615766 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -313,6 +313,18 @@ fn split_off_to_at_gt_len() { } #[test] +fn truncate() { + let s = &b"helloworld"[..]; + let mut hello = Bytes::from(s); + hello.truncate(15); + assert_eq!(hello, s); + hello.truncate(10); + assert_eq!(hello, s); + hello.truncate(5); + assert_eq!(hello, "hello"); +} + +#[test] fn freeze_clone_shared() { let s = &b"abcdefgh"[..]; let b = BytesMut::from(s).split().freeze(); |