Debian Codegraph @

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

raw
1 use super::Cursor;
2
3 use rmp::decode::*;
4 use rmp::Marker;
5
6 #[test]
7 fn from_empty_array_read_size() {
8 let buf: &[u8] = &[0x90];
9 let mut cur = Cursor::new(buf);
10
11 assert_eq!(0, read_array_len(&mut cur).unwrap());
12 assert_eq!(1, cur.position());
13 }
14
15 #[test]
16 fn from_fixarray_max_read_size() {
17 let buf: &[u8] = &[
18 0x9f,
19 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e
20 ];
21 let mut cur = Cursor::new(buf);
22
23 assert_eq!(15, read_array_len(&mut cur).unwrap());
24 assert_eq!(1, cur.position());
25 }
26
27 #[test]
28 fn from_array16_min_read_size() {
29 let buf: &[u8] = &[0xdc, 0x00, 0x10];
30 let mut cur = Cursor::new(buf);
31
32 assert_eq!(16, read_array_len(&mut cur).unwrap());
33 assert_eq!(3, cur.position());
34 }
35
36 #[test]
37 fn from_array16_max_read_size() {
38 let buf: &[u8] = &[0xdc, 0xff, 0xff];
39 let mut cur = Cursor::new(buf);
40
41 assert_eq!(65535, read_array_len(&mut cur).unwrap());
42 assert_eq!(3, cur.position());
43 }
44
45 #[test]
46 fn from_array16_unexpected_eof_read_size() {
47 let buf: &[u8] = &[0xdc, 0xff];
48 let mut cur = Cursor::new(buf);
49
50 read_array_len(&mut cur).err().unwrap();
51 assert!(cur.position() >= 1);
52 }
53
54 #[test]
55 fn from_array32_min_read_size() {
56 let buf: &[u8] = &[0xdd, 0x00, 0x00, 0x00, 0x00];
57 let mut cur = Cursor::new(buf);
58
59 assert_eq!(0, read_array_len(&mut cur).unwrap());
60 assert_eq!(5, cur.position());
61 }
62
63 #[test]
64 fn from_array32_max_read_size() {
65 let buf: &[u8] = &[0xdd, 0xff, 0xff, 0xff, 0xff];
66 let mut cur = Cursor::new(buf);
67
68 assert_eq!(4294967295, read_array_len(&mut cur).unwrap());
69 assert_eq!(5, cur.position());
70 }
71
72 #[test]
73 fn from_array32_unexpected_eof_read_size() {
74 let buf: &[u8] = &[0xdd, 0xff, 0xff, 0xff];
75 let mut cur = Cursor::new(buf);
76
77 read_array_len(&mut cur).err().unwrap();
78 assert!(cur.position() >= 1);
79 }
80
81 #[test]
82 fn from_null_read_array_len() {
83 let buf: &[u8] = &[0xc0];
84 let mut cur = Cursor::new(buf);
85
86 match read_array_len(&mut cur) {
87 Err(ValueReadError::TypeMismatch(Marker::Null)) => (),
88 other => panic!("unexpected result: {other:?}"),
89 }
90 assert_eq!(1, cur.position());
91 }