MCPcopy Create free account
hub / github.com/RustCrypto/utils / test_vlq

Function test_vlq

blobby/src/encode.rs:149–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

147 #[test]
148 #[rustfmt::skip]
149 fn test_vlq() {
150 let mut example_buf: &[u8] = &[
151 0b0000_0000, // 0
152 0b0000_0010, // 2
153 0b0111_1111, // 127
154 0b1000_0000, 0b0000_0000, // 128
155 0b1111_1111, 0b0111_1111, // 16511
156 0b1000_0000, 0b1000_0000, 0b0000_0000, // 16512
157 0b1111_1111, 0b1111_1111, 0b0111_1111, // 2113663
158 0b1000_0000, 0b1000_0000, 0b1000_0000, 0b0000_0000, // 2113664
159 0b1111_1111, 0b1111_1111, 0b1111_1111, 0b0111_1111, // 270549119
160 0b1111_1111, 0b1111_1111, 0b1111_1111, 0b1111_1111, 0b0111_1111,
161 ];
162
163 let targets = [
164 (0, 1),
165 (2, 1),
166 (127, 1),
167 (128, 2),
168 (16511, 2),
169 (16512, 3),
170 (2113663, 3),
171 (2113664, 4),
172 (270549119, 4),
173 ];
174
175 let mut buf = [0u8; 4];
176
177 let mut rem_len = example_buf.len();
178
179 for (target_val, target_size) in targets {
180 assert_eq!(encode_vlq(target_val, &mut buf), &example_buf[..target_size]);
181
182 let val = read_vlq(&mut example_buf).unwrap();
183 assert_eq!(val, target_val);
184
185 rem_len -= target_size;
186 assert_eq!(example_buf.len(), rem_len);
187
188 }
189
190 // Only VLQ values of up to 4 bytes are supported
191 assert_eq!(read_vlq(&mut example_buf), Err(Error::InvalidVlq));
192 }
193}

Callers

nothing calls this directly

Calls 3

read_vlqFunction · 0.85
lenMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected