From af606aab9be1dde2aeefc1a21344a79beaba7bbe Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Mon, 2 Dec 2019 00:00:42 +0200 Subject: 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. --- tests/test_bytes.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/test_bytes.rs') 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 @@ -312,6 +312,18 @@ fn split_off_to_at_gt_len() { }).is_err()); } +#[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"[..]; -- cgit v1.2.3