Skip to content

Commit

Permalink
std: add tests for the Vec<u8> Writer impl
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Dec 1, 2014
1 parent acad03a commit 6687b2a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libstd/io/mem.rs
Expand Up @@ -362,6 +362,16 @@ mod test {
use self::test::Bencher;
use str::StrPrelude;

#[test]
fn test_vec_writer() {
let mut writer = Vec::new();
writer.write(&[0]).unwrap();
writer.write(&[1, 2, 3]).unwrap();
writer.write(&[4, 5, 6, 7]).unwrap();
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
assert_eq!(writer.as_slice(), b);
}

#[test]
fn test_mem_writer() {
let mut writer = MemWriter::new();
Expand All @@ -385,6 +395,8 @@ mod test {
assert_eq!(writer.tell(), Ok(8));
writer.write(&[]).unwrap();
assert_eq!(writer.tell(), Ok(8));

assert!(writer.write(&[1]).is_err());
}
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
assert_eq!(buf.as_slice(), b);
Expand Down

0 comments on commit 6687b2a

Please sign in to comment.