gdritter repos thermidor / 75a9eb8
Added another test Getty Ritter 8 years ago
1 changed file(s) with 11 addition(s) and 8 deletion(s). Collapse all Expand all
44 /// can parse things more easily.
55 pub struct ByteReader<Rd> {
66 bytes: Rd,
7 }
8
9 #[test]
10 fn reader_tests() {
11 assert!(ByteReader::from_slice(&[0x00]).read_twip() == Ok(-32.0));
12 assert!(ByteReader::from_slice(&[0x00]).read_prefix_int() == Ok(0x00));
13 assert!(ByteReader::from_slice(&[0x7f]).read_prefix_int() == Ok(0x7f));
14 assert!(ByteReader::from_slice(&[0x80,0xff]).read_prefix_int() == Ok(0xff));
157 }
168
179 const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &|s| s.ok();
5143 pub fn from_slice(lst: &'a [u8]) -> Self {
5244 ByteReader { bytes: lst.iter().map(DEREF) }
5345 }
46 }
47
48 #[test]
49 fn reader_tests() {
50 assert!(ByteReader::from_slice(&[0x00]).read_twip() == Ok(-32.0));
51 assert!(ByteReader::from_slice(&[0x00]).read_prefix_int() == Ok(0x00));
52 assert!(ByteReader::from_slice(&[0x7f]).read_prefix_int() == Ok(0x7f));
53 assert!(ByteReader::from_slice(&[0x80,0xff]).read_prefix_int() == Ok(0xff));
54 assert!(ByteReader::from_slice(&[0x03,0x00,0x00,0x00])
55 .read_several(|r| r.read_twip()) ==
56 Ok(vec![-32.0,-32.0,-32.0]));
5457 }
5558
5659 impl<T> ByteReader<T> where T: Iterator<Item=u8> {