Add test for Write

This commit is contained in:
bluss
2015-09-10 19:48:17 +02:00
parent 81b5bd32c0
commit def1be54ed
2 changed files with 12 additions and 0 deletions
+1
View File
@@ -677,6 +677,7 @@ impl<A: Array> Ord for ArrayVec<A> where A::Item: Ord {
} }
} }
/// `Write` appends written data to the end of the vector.
impl<A: Array<Item=u8>> io::Write for ArrayVec<A> { impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
fn write(&mut self, data: &[u8]) -> io::Result<usize> { fn write(&mut self, data: &[u8]) -> io::Result<usize> {
unsafe { unsafe {
+11
View File
@@ -249,3 +249,14 @@ fn test_into_inner_3_() {
v.extend(1..); v.extend(1..);
assert_eq!(v.into_inner().unwrap(), [1, 2, 3, 4]); assert_eq!(v.into_inner().unwrap(), [1, 2, 3, 4]);
} }
#[test]
fn test_write() {
use std::io::Write;
let mut v = ArrayVec::<[_; 8]>::new();
write!(&mut v, "\x01\x02\x03").unwrap();
assert_eq!(&v[..], &[1, 2, 3]);
let r = v.write(&[9; 16]).unwrap();
assert_eq!(r, 5);
assert_eq!(&v[..], &[1, 2, 3, 9, 9, 9, 9, 9]);
}