Debian Codegraph @

third_party/rust/rmp/tests/func/decode/map.rs

raw
1 use super::Cursor;
2
3 use rmp::decode::*;
4 use rmp::Marker;
5
6 #[test]
7 fn from_fixmap_min_read_size() {
8 let buf: &[u8] = &[0x80];
9 let mut cur = Cursor::new(buf);
10
11 assert_eq!(0, read_map_len(&mut cur).unwrap());
12 assert_eq!(1, cur.position());
13 }
14
15 #[test]
16 fn from_fixmap_max_read_size() {
17 let buf: &[u8] = &[0x8f];
18 let mut cur = Cursor::new(buf);
19
20 assert_eq!(15, read_map_len(&mut cur).unwrap());
21 assert_eq!(1, cur.position());
22 }
23
24 #[test]
25 fn from_map16_min_read_size() {
26 let buf: &[u8] = &[0xde, 0x00, 0x00];
27 let mut cur = Cursor::new(buf);
28
29 assert_eq!(0, read_map_len(&mut cur).unwrap());
30 assert_eq!(3, cur.position());
31 }
32
33 #[test]
34 fn from_map16_max_read_size() {
35 let buf: &[u8] = &[0xde, 0xff, 0xff];
36 let mut cur = Cursor::new(buf);
37
38 assert_eq!(65535, read_map_len(&mut cur).unwrap());
39 assert_eq!(3, cur.position());
40 }
41
42 #[test]
43 fn from_map32_min_read_size() {
44 let buf: &[u8] = &[0xdf, 0x00, 0x00, 0x00, 0x00];
45 let mut cur = Cursor::new(buf);
46
47 assert_eq!(0, read_map_len(&mut cur).unwrap());
48 assert_eq!(5, cur.position());
49 }
50
51 #[test]
52 fn from_null_read_map_len() {
53 let buf: &[u8] = &[0xc0, 0x00, 0x00, 0x00, 0x00];
54 let mut cur = Cursor::new(buf);
55
56 match read_map_len(&mut cur) {
57 Err(ValueReadError::TypeMismatch(Marker::Null)) => (),
58 other => panic!("unexpected result: {other:?}"),
59 }
60 assert_eq!(1, cur.position());
61 }