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.
This commit is contained in:
Mikhail Zabaluev
2019-12-01 14:00:42 -08:00
committed by Carl Lerche
parent 98951ba26c
commit af606aab9b
2 changed files with 13 additions and 3 deletions
+12
View File
@@ -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"[..];