Unsplit improvements (#173)

* Handle empty self and other for unsplit.
* Change extend() to extend_from_slice().
This commit is contained in:
jq-rs
2018-01-05 16:20:59 -08:00
committed by Carl Lerche
parent 6a3d20bb8d
commit ba9a975358
2 changed files with 38 additions and 1 deletions
+24
View File
@@ -566,6 +566,30 @@ fn unsplit_basic() {
assert_eq!(b"aaabbbcccddd", &buf[..]);
}
#[test]
fn unsplit_empty_other() {
let mut buf = BytesMut::with_capacity(64);
buf.extend_from_slice(b"aaabbbcccddd");
// empty other
let other = BytesMut::new();
buf.unsplit(other);
assert_eq!(b"aaabbbcccddd", &buf[..]);
}
#[test]
fn unsplit_empty_self() {
// empty self
let mut buf = BytesMut::new();
let mut other = BytesMut::with_capacity(64);
other.extend_from_slice(b"aaabbbcccddd");
buf.unsplit(other);
assert_eq!(b"aaabbbcccddd", &buf[..]);
}
#[test]
fn unsplit_inline_arc() {
let mut buf = BytesMut::with_capacity(8); //inline