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
+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();