diff --git a/src/buf/block.rs b/src/buf/block.rs index 086c90e530c6b3fb2d251b4c075dce4526e54fe7..988318bcbda7f85115a14dc35c637ee083cd5eb9 100644 --- a/src/buf/block.rs +++ b/src/buf/block.rs @@ -175,7 +175,7 @@ impl BlockBuf { block.drop(segment_n); - !MutBuf::has_remaining(block) + block.len() == 0 }; if pop { diff --git a/test/test.rs b/test/test.rs index f4edae29990698128afd6dfbe4b18ac454a281ca..51588564098c76043f23a2e7856d1e2fceafc081 100644 --- a/test/test.rs +++ b/test/test.rs @@ -6,6 +6,7 @@ extern crate byteorder; // == Buf mod test_append; +mod test_block; mod test_buf; mod test_buf_fill; mod test_byte_buf; diff --git a/test/test_block.rs b/test/test_block.rs new file mode 100644 index 0000000000000000000000000000000000000000..37a9334dcc0995f40e8408a8b7d483ba71b73d84 --- /dev/null +++ b/test/test_block.rs @@ -0,0 +1,22 @@ +use bytes::{MutBuf, BlockBuf}; + + +#[test] +pub fn test_block_drop() { + let mut buf = BlockBuf::new(2, 4); + + assert_eq!(buf.remaining(), 8); + + buf.write_slice(b"12345"); + buf.write_slice(b"678"); + assert_eq!(buf.remaining(), 0); + assert_eq!(buf.len(), 8); + + buf.drop(1); + assert_eq!(buf.len(), 7); + assert_eq!(buf.is_compact(), false); + + buf.drop(4); + assert_eq!(buf.len(), 3); + assert_eq!(buf.is_compact(), true); +}