mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-16 00:00:15 +02:00
Rename & refactor ByteBuf -> SliceBuf
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ mod test_append;
|
||||
mod test_block;
|
||||
mod test_buf;
|
||||
mod test_buf_fill;
|
||||
mod test_byte_buf;
|
||||
mod test_slice_buf;
|
||||
mod test_mut_buf;
|
||||
mod test_ring;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ use std::io;
|
||||
#[test]
|
||||
pub fn test_readijng_buf_from_reader() {
|
||||
let mut reader = chunks(vec![b"foo", b"bar", b"baz"]);
|
||||
let mut buf = MutByteBuf::with_capacity(1024);
|
||||
let mut buf = AppendBuf::with_capacity(1024);
|
||||
|
||||
assert_eq!(3, reader.read_buf(&mut buf).unwrap());
|
||||
assert_eq!(Bytes::from(&b"foo"), Bytes::from(buf.flip()));
|
||||
assert_eq!(Bytes::from_slice(&b"foo"), Bytes::from(buf));
|
||||
}
|
||||
|
||||
fn chunks(chunks: Vec<&'static [u8]>) -> Chunked {
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ use bytes::*;
|
||||
|
||||
#[test]
|
||||
pub fn test_debug_short_str_valid_ascii() {
|
||||
let b = Bytes::from(b"abcdefghij234");
|
||||
let b = Bytes::from_slice(b"abcdefghij234");
|
||||
let d = format!("{:?}", b);
|
||||
|
||||
assert_eq!(d, "Bytes[len=13; abcdefghij234]");
|
||||
@@ -33,7 +33,7 @@ pub fn test_debug_long_str_valid_ascii() {
|
||||
|
||||
#[test]
|
||||
pub fn test_short_string_invalid_ascii() {
|
||||
let b = Bytes::from(b"foo\x00bar\xFFbaz");
|
||||
let b = Bytes::from_slice(b"foo\x00bar\xFFbaz");
|
||||
let d = format!("{:?}", b);
|
||||
|
||||
println!("{:?}", b);
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ pub fn test_slice_round_trip() {
|
||||
let mut dst = vec![];
|
||||
let src = gen_bytes(2000);
|
||||
|
||||
let s = Bytes::from(&src);
|
||||
let s = Bytes::from(src.clone());
|
||||
assert_eq!(2000, s.len());
|
||||
|
||||
s.buf().copy_to(&mut dst);
|
||||
@@ -17,7 +17,7 @@ pub fn test_slice_round_trip() {
|
||||
pub fn test_index() {
|
||||
let src = gen_bytes(2000);
|
||||
|
||||
let s = Bytes::from(&src);
|
||||
let s = Bytes::from(src.clone());
|
||||
|
||||
for i in 0..2000 {
|
||||
assert_eq!(src[i], s[i]);
|
||||
@@ -27,6 +27,6 @@ pub fn test_index() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn test_index_out_of_range() {
|
||||
let s = Bytes::from(&gen_bytes(2000));
|
||||
let s = Bytes::from(gen_bytes(2000));
|
||||
let _ = s[2001];
|
||||
}
|
||||
|
||||
@@ -1,51 +1,43 @@
|
||||
use bytes::{Buf, MutBuf};
|
||||
use bytes::buf::MutByteBuf;
|
||||
use bytes::buf::SliceBuf;
|
||||
|
||||
#[test]
|
||||
pub fn test_initial_buf_empty() {
|
||||
let buf = MutByteBuf::with_capacity(100);
|
||||
let buf = SliceBuf::with_capacity(100);
|
||||
|
||||
assert!(buf.capacity() == 128);
|
||||
assert!(buf.remaining() == 128);
|
||||
|
||||
let buf = buf.flip();
|
||||
|
||||
assert!(buf.remaining() == 0);
|
||||
|
||||
let buf = buf.flip();
|
||||
|
||||
assert!(buf.remaining() == 128);
|
||||
assert!(buf.remaining_write() == 128);
|
||||
assert!(buf.remaining_read() == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_byte_buf_bytes() {
|
||||
let mut buf = MutByteBuf::with_capacity(32);
|
||||
pub fn test_slice_buf_bytes() {
|
||||
let mut buf = SliceBuf::with_capacity(32);
|
||||
|
||||
buf.copy_from(&b"hello "[..]);
|
||||
assert_eq!(&b"hello "[..], buf.bytes());
|
||||
|
||||
buf.copy_from(&b"world"[..]);
|
||||
assert_eq!(&b"hello world"[..], buf.bytes());
|
||||
let buf = buf.flip();
|
||||
assert_eq!(&b"hello world"[..], buf.bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_byte_buf_read_write() {
|
||||
let mut buf = MutByteBuf::with_capacity(32);
|
||||
let mut buf = SliceBuf::with_capacity(32);
|
||||
|
||||
buf.copy_from(&b"hello world"[..]);
|
||||
assert_eq!(21, buf.remaining());
|
||||
assert_eq!(21, buf.remaining_write());
|
||||
|
||||
buf.copy_from(&b" goodbye"[..]);
|
||||
assert_eq!(13, buf.remaining());
|
||||
assert_eq!(13, buf.remaining_write());
|
||||
|
||||
let mut buf = buf.flip();
|
||||
let mut dst = [0; 5];
|
||||
|
||||
buf.mark();
|
||||
let pos = buf.position();
|
||||
assert_eq!(5, buf.copy_to(&mut dst[..]));
|
||||
assert_eq!(b"hello", &dst);
|
||||
buf.reset();
|
||||
|
||||
buf.set_position(pos);
|
||||
assert_eq!(5, buf.copy_to(&mut dst[..]));
|
||||
assert_eq!(b"hello", &dst);
|
||||
|
||||
@@ -60,12 +52,16 @@ pub fn test_byte_buf_read_write() {
|
||||
assert_eq!(7, buf.copy_to(&mut dst[..]));
|
||||
assert_eq!(b"goodbye", &dst);
|
||||
|
||||
let mut buf = buf.resume();
|
||||
assert_eq!(13, buf.remaining());
|
||||
assert_eq!(13, buf.remaining_write());
|
||||
|
||||
buf.copy_from(&b" have fun"[..]);
|
||||
assert_eq!(4, buf.remaining());
|
||||
assert_eq!(4, buf.remaining_write());
|
||||
|
||||
let buf = buf.flip();
|
||||
assert_eq!(buf.bytes(), b" have fun");
|
||||
|
||||
buf.set_position(0);
|
||||
assert_eq!(buf.bytes(), b"hello world goodbye have fun");
|
||||
|
||||
buf.clear();
|
||||
assert_eq!(buf.bytes(), b"");
|
||||
}
|
||||
+3
-3
@@ -6,7 +6,7 @@ pub fn test_slice_round_trip() {
|
||||
let mut dst = vec![];
|
||||
let src = gen_bytes(3);
|
||||
|
||||
let s = Bytes::from(&src);
|
||||
let s = Bytes::from(src.clone());
|
||||
assert_eq!(3, s.len());
|
||||
|
||||
s.buf().copy_to(&mut dst);
|
||||
@@ -17,7 +17,7 @@ pub fn test_slice_round_trip() {
|
||||
pub fn test_index() {
|
||||
let src = gen_bytes(3);
|
||||
|
||||
let s = Bytes::from(&src);
|
||||
let s = Bytes::from(src.clone());
|
||||
|
||||
for i in 0..3 {
|
||||
assert_eq!(src[i], s[i]);
|
||||
@@ -27,6 +27,6 @@ pub fn test_index() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn test_index_out_of_range() {
|
||||
let s = Bytes::from(&gen_bytes(3));
|
||||
let s = Bytes::from(gen_bytes(3));
|
||||
let _ = s[2001];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user