Added another test
Getty Ritter
8 years ago
4 | 4 | /// can parse things more easily. |
5 | 5 | pub struct ByteReader<Rd> { |
6 | 6 | 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)); | |
15 | 7 | } |
16 | 8 | |
17 | 9 | const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &|s| s.ok(); |
51 | 43 | pub fn from_slice(lst: &'a [u8]) -> Self { |
52 | 44 | ByteReader { bytes: lst.iter().map(DEREF) } |
53 | 45 | } |
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])); | |
54 | 57 | } |
55 | 58 | |
56 | 59 | impl<T> ByteReader<T> where T: Iterator<Item=u8> { |