Get rid of BufError

This commit is contained in:
Carl Lerche
2016-08-05 21:54:29 -07:00
parent 6529f6392a
commit b6a424d892
12 changed files with 61 additions and 78 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ pub fn test_initial_buf_empty() {
assert_eq!(buf.bytes(), b"hello world");
let view1 = buf.slice(0, 11);
view1.buf().copy_to(&mut dst).unwrap();
view1.buf().copy_to(&mut dst);
assert_eq!(dst, b"hello world");
assert_eq!(view1, buf.slice(0, 11));
@@ -47,7 +47,7 @@ pub fn test_append_buf_from_pool() {
assert_eq!(buf.bytes(), b"hello world");
let view1 = buf.slice(0, 11);
view1.buf().copy_to(&mut dst).unwrap();
view1.buf().copy_to(&mut dst);
assert_eq!(dst, b"hello world");
assert_eq!(view1, buf.slice(0, 11));
+2 -2
View File
@@ -35,7 +35,7 @@ pub fn test_vec_as_mut_buf() {
assert!(buf.mut_bytes().len() >= 64);
}
buf.copy_from(&b"zomg"[..]).unwrap();
buf.copy_from(&b"zomg"[..]);
assert_eq!(&buf, b"zomg");
@@ -43,7 +43,7 @@ pub fn test_vec_as_mut_buf() {
assert_eq!(buf.capacity(), 64);
for _ in 0..16 {
buf.copy_from(&b"zomg"[..]).unwrap();
buf.copy_from(&b"zomg"[..]);
}
assert_eq!(buf.len(), 68);
+10 -10
View File
@@ -20,10 +20,10 @@ pub fn test_initial_buf_empty() {
#[test]
pub fn test_byte_buf_bytes() {
let mut buf = ByteBuf::mut_with_capacity(32);
buf.copy_from(&b"hello "[..]).unwrap();
buf.copy_from(&b"hello "[..]);
assert_eq!(&b"hello "[..], buf.bytes());
buf.copy_from(&b"world"[..]).unwrap();
buf.copy_from(&b"world"[..]);
assert_eq!(&b"hello world"[..], buf.bytes());
let buf = buf.flip();
assert_eq!(&b"hello world"[..], buf.bytes());
@@ -33,37 +33,37 @@ pub fn test_byte_buf_bytes() {
pub fn test_byte_buf_read_write() {
let mut buf = ByteBuf::mut_with_capacity(32);
buf.copy_from(&b"hello world"[..]).unwrap();
buf.copy_from(&b"hello world"[..]);
assert_eq!(21, buf.remaining());
buf.copy_from(&b" goodbye"[..]).unwrap();
buf.copy_from(&b" goodbye"[..]);
assert_eq!(13, buf.remaining());
let mut buf = buf.flip();
let mut dst = [0; 5];
buf.mark();
assert_eq!(5, buf.copy_to(&mut dst[..]).unwrap());
assert_eq!(5, buf.copy_to(&mut dst[..]));
assert_eq!(b"hello", &dst);
buf.reset();
assert_eq!(5, buf.copy_to(&mut dst[..]).unwrap());
assert_eq!(5, buf.copy_to(&mut dst[..]));
assert_eq!(b"hello", &dst);
assert_eq!(5, buf.copy_to(&mut dst[..]).unwrap());
assert_eq!(5, buf.copy_to(&mut dst[..]));
assert_eq!(b" worl", &dst);
let mut dst = [0; 2];
assert_eq!(2, buf.copy_to(&mut dst[..]).unwrap());
assert_eq!(2, buf.copy_to(&mut dst[..]));
assert_eq!(b"d ", &dst);
let mut dst = [0; 7];
assert_eq!(7, buf.copy_to(&mut dst[..]).unwrap());
assert_eq!(7, buf.copy_to(&mut dst[..]));
assert_eq!(b"goodbye", &dst);
let mut buf = buf.resume();
assert_eq!(13, buf.remaining());
buf.copy_from(&b" have fun"[..]).unwrap();
buf.copy_from(&b" have fun"[..]);
assert_eq!(4, buf.remaining());
let buf = buf.flip();
+1 -1
View File
@@ -26,7 +26,7 @@ fn test_pool_with_one_capacity() {
let mut dst = vec![];
buf.copy_to(&mut dst).unwrap();
buf.copy_to(&mut dst);
assert_eq!(&dst[..], b"Hello World");
+21 -21
View File
@@ -6,10 +6,10 @@ pub fn test_initial_buf_empty() {
assert_eq!(MutBuf::remaining(&buf), 16);
assert_eq!(Buf::remaining(&buf), 0);
let bytes_written = buf.copy_from(&[1, 2, 3][..]).unwrap();
let bytes_written = buf.copy_from(&[1, 2, 3][..]);
assert_eq!(bytes_written, 3);
let bytes_written = buf.copy_from(&[][..]).unwrap();
let bytes_written = buf.copy_from(&[][..]);
assert_eq!(bytes_written, 0);
assert_eq!(MutBuf::remaining(&buf), 13);
assert_eq!(Buf::remaining(&buf), 3);
@@ -18,11 +18,11 @@ pub fn test_initial_buf_empty() {
let mut out = [0u8; 3];
buf.mark();
let bytes_read = buf.copy_to(&mut out[..]).unwrap();;
let bytes_read = buf.copy_to(&mut out[..]);
assert_eq!(bytes_read, 3);
assert_eq!(out, [1, 2, 3]);
buf.reset();
let bytes_read = buf.copy_to(&mut out[..]).unwrap();;
let bytes_read = buf.copy_to(&mut out[..]);
assert_eq!(bytes_read, 3);
assert_eq!(out, [1, 2, 3]);
@@ -35,19 +35,19 @@ fn test_wrapping_write() {
let mut buf = RingBuf::new(16);
let mut out = [0;10];
buf.copy_from(&[42;12][..]).unwrap();
let bytes_read = buf.copy_to(&mut out[..]).unwrap();
buf.copy_from(&[42;12][..]);
let bytes_read = buf.copy_to(&mut out[..]);
assert_eq!(bytes_read, 10);
let bytes_written = buf.copy_from(&[23;8][..]).unwrap();
let bytes_written = buf.copy_from(&[23;8][..]);
assert_eq!(bytes_written, 8);
buf.mark();
let bytes_read = buf.copy_to(&mut out[..]).unwrap();
let bytes_read = buf.copy_to(&mut out[..]);
assert_eq!(bytes_read, 10);
assert_eq!(out, [42, 42, 23, 23, 23, 23, 23, 23, 23, 23]);
buf.reset();
let bytes_read = buf.copy_to(&mut out[..]).unwrap();
let bytes_read = buf.copy_to(&mut out[..]);
assert_eq!(bytes_read, 10);
assert_eq!(out, [42, 42, 23, 23, 23, 23, 23, 23, 23, 23]);
}
@@ -57,16 +57,16 @@ fn test_io_write_and_read() {
let mut buf = RingBuf::new(16);
let mut out = [0u8;8];
let written = buf.copy_from(&[1;8][..]).unwrap();
let written = buf.copy_from(&[1;8][..]);
assert_eq!(written, 8);
buf.copy_to(&mut out[..]).unwrap();
buf.copy_to(&mut out[..]);
assert_eq!(out, [1;8]);
let written = buf.copy_from(&[2;8][..]).unwrap();
let written = buf.copy_from(&[2;8][..]);
assert_eq!(written, 8);
let bytes_read = buf.copy_to(&mut out[..]).unwrap();
let bytes_read = buf.copy_to(&mut out[..]);
assert_eq!(bytes_read, 8);
assert_eq!(out, [2;8]);
}
@@ -75,10 +75,10 @@ fn test_io_write_and_read() {
#[should_panic]
fn test_wrap_reset() {
let mut buf = RingBuf::new(8);
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]).unwrap();
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]);
buf.mark();
buf.copy_to(&mut [0; 4][..]).unwrap();
buf.copy_from(&[1, 2, 3, 4][..]).unwrap();
buf.copy_to(&mut [0; 4][..]);
buf.copy_from(&[1, 2, 3, 4][..]);
buf.reset();
}
@@ -86,13 +86,13 @@ fn test_wrap_reset() {
// Test that writes across a mark/reset are preserved.
fn test_mark_write() {
let mut buf = RingBuf::new(8);
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]).unwrap();
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7][..]);
buf.mark();
buf.copy_from(&[8][..]).unwrap();
buf.copy_from(&[8][..]);
buf.reset();
let mut buf2 = [0; 8];
buf.copy_to(&mut buf2[..]).unwrap();
buf.copy_to(&mut buf2[..]);
assert_eq!(buf2, [1, 2, 3, 4, 5, 6, 7, 8]);
}
@@ -101,7 +101,7 @@ fn test_mark_write() {
// full buffer to zero.
fn test_reset_full() {
let mut buf = RingBuf::new(8);
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7, 8][..]).unwrap();
buf.copy_from(&[1, 2, 3, 4, 5, 6, 7, 8][..]);
assert_eq!(MutBuf::remaining(&buf), 0);
buf.mark();
buf.reset();
@@ -113,7 +113,7 @@ fn test_reset_full() {
// Test that "RingBuf::clear" does the full reset
fn test_clear() {
let mut buf = RingBuf::new(8);
buf.copy_from(&[0; 8][..]).unwrap();
buf.copy_from(&[0; 8][..]);
assert_eq!(MutBuf::remaining(&buf), 0);
assert_eq!(Buf::remaining(&buf), 8);
buf.clear();
+5 -5
View File
@@ -33,7 +33,7 @@ pub fn test_rope_round_trip() {
assert_eq!(4, rope.len());
let mut dst = vec![];
rope.buf().copy_to(&mut dst).unwrap();
rope.buf().copy_to(&mut dst);
assert_eq!(b"zomg", &dst[..]);
}
@@ -45,19 +45,19 @@ pub fn test_rope_slice() {
let bytes = Rope::from_slice(TEST_BYTES_1);
assert_eq!(TEST_BYTES_1.len(), bytes.len());
bytes.buf().copy_to(&mut dst).unwrap();
bytes.buf().copy_to(&mut dst);
assert_eq!(dst, TEST_BYTES_1);
let left = bytes.slice_to(250);
assert_eq!(250, left.len());
left.buf().copy_to(&mut dst).unwrap();
left.buf().copy_to(&mut dst);
assert_eq!(dst, &TEST_BYTES_1[..250]);
let right = bytes.slice_from(250);
assert_eq!(TEST_BYTES_1.len() - 250, right.len());
right.buf().copy_to(&mut dst).unwrap();
right.buf().copy_to(&mut dst);
assert_eq!(dst, &TEST_BYTES_1[250..]);
}
@@ -72,7 +72,7 @@ pub fn test_rope_concat_two_byte_str() {
assert_eq!(both.len(), TEST_BYTES_1.len() + TEST_BYTES_2.len());
both.buf().copy_to(&mut dst).unwrap();
both.buf().copy_to(&mut dst);
let mut expected = Vec::new();
expected.extend(TEST_BYTES_1.iter().cloned());
expected.extend(TEST_BYTES_2.iter().cloned());
+1 -1
View File
@@ -9,7 +9,7 @@ pub fn test_slice_round_trip() {
let s = SeqByteStr::from_slice(&src);
assert_eq!(2000, s.len());
s.buf().copy_to(&mut dst).unwrap();
s.buf().copy_to(&mut dst);
assert_eq!(dst, src);
}
+1 -1
View File
@@ -9,7 +9,7 @@ pub fn test_slice_round_trip() {
let s = SmallByteStr::from_slice(&src).unwrap();
assert_eq!(3, s.len());
s.buf().copy_to(&mut dst).unwrap();
s.buf().copy_to(&mut dst);
assert_eq!(dst, src);
}