comparison utils/src/bitstream.rs @ 758:daa23a4ff24d

utils: Replace custom SeekableSlice struct with std::io::Cursor.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 05 Jan 2021 04:11:18 +0100
parents 21b186be2590
children
comparison
equal deleted inserted replaced
757:21b186be2590 758:daa23a4ff24d
70 } 70 }
71 71
72 #[cfg(test)] 72 #[cfg(test)]
73 mod tests { 73 mod tests {
74 use super::*; 74 use super::*;
75 use crate::util::SeekableSlice; 75 use std::io::Cursor;
76 76
77 #[test] 77 #[test]
78 fn bit_by_bit() { 78 fn bit_by_bit() {
79 let data = SeekableSlice::new(&[1, 2, 3]); 79 let data = Cursor::new(vec![1, 2, 3]);
80 let mut bitstream = BitStream::new(data); 80 let mut bitstream = BitStream::new(data);
81 81
82 // 1 82 // 1
83 assert_eq!(bitstream.read_bit().unwrap(), false); 83 assert_eq!(bitstream.read_bit().unwrap(), false);
84 assert_eq!(bitstream.read_bit().unwrap(), false); 84 assert_eq!(bitstream.read_bit().unwrap(), false);
113 bitstream.read_bit().unwrap_err(); 113 bitstream.read_bit().unwrap_err();
114 } 114 }
115 115
116 #[test] 116 #[test]
117 fn byte_by_byte() { 117 fn byte_by_byte() {
118 let data = SeekableSlice::new(&[1, 2, 3]); 118 let data = Cursor::new(vec![1, 2, 3]);
119 let mut bitstream = BitStream::new(data); 119 let mut bitstream = BitStream::new(data);
120 120
121 assert_eq!(bitstream.read(8).unwrap(), 1); 121 assert_eq!(bitstream.read(8).unwrap(), 1);
122 assert_eq!(bitstream.read(8).unwrap(), 2); 122 assert_eq!(bitstream.read(8).unwrap(), 2);
123 assert_eq!(bitstream.read(8).unwrap(), 3); 123 assert_eq!(bitstream.read(8).unwrap(), 3);
126 bitstream.read(1).unwrap_err(); 126 bitstream.read(1).unwrap_err();
127 } 127 }
128 128
129 #[test] 129 #[test]
130 fn unaligned_bytes() { 130 fn unaligned_bytes() {
131 let data = SeekableSlice::new(&[0, 129, 1, 128]); 131 let data = Cursor::new(vec![0, 129, 1, 128]);
132 let mut bitstream = BitStream::new(data); 132 let mut bitstream = BitStream::new(data);
133 133
134 assert_eq!(bitstream.read_bit().unwrap(), false); 134 assert_eq!(bitstream.read_bit().unwrap(), false);
135 assert_eq!(bitstream.read(8).unwrap(), 1); 135 assert_eq!(bitstream.read(8).unwrap(), 1);
136 assert_eq!(bitstream.read(8).unwrap(), 2); 136 assert_eq!(bitstream.read(8).unwrap(), 2);