Debian Codegraph @

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

raw
1 use super::Cursor;
2
3 use rmp::decode::*;
4
5 #[test]
6 fn from_fixext1_read_fixext1() {
7 let buf: &[u8] = &[0xd4, 0x01, 0x02];
8 let mut cur = Cursor::new(buf);
9
10 assert_eq!((1, 2), read_fixext1(&mut cur).unwrap());
11 assert_eq!(3, cur.position());
12 }
13
14 #[test]
15 fn from_fixext2_read_fixext2() {
16 let buf = [0xd5, 0x01, 0x00, 0x02];
17 let mut cur = Cursor::new(&buf[..]);
18
19 assert_eq!((1, [0x00, 0x02]), read_fixext2(&mut cur).unwrap());
20 assert_eq!(4, cur.position());
21 }
22
23 #[test]
24 fn from_fixext4_read_fixext4() {
25 let buf = [0xd6, 0x01, 0x00, 0x00, 0x00, 0x02];
26 let mut cur = Cursor::new(&buf[..]);
27
28 assert_eq!((1, [0x00, 0x00, 0x00, 0x02]), read_fixext4(&mut cur).unwrap());
29 assert_eq!(6, cur.position());
30 }
31
32 #[test]
33 fn from_fixext8_read_fixext8() {
34 let buf = [0xd7, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];
35 let mut cur = Cursor::new(&buf[..]);
36
37 assert_eq!((1, [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]),
38 read_fixext8(&mut cur).unwrap());
39 assert_eq!(10, cur.position());
40 }
41
42 #[test]
43 fn from_fixext16_read_fixext16() {
44 let buf = [
45 0xd8,
46 0x01,
47 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
48 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
49 ];
50 let mut cur = Cursor::new(&buf[..]);
51
52 assert_eq!((1, [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
53 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]),
54 read_fixext16(&mut cur).unwrap());
55 assert_eq!(18, cur.position());
56 }
57
58 #[test]
59 fn from_fixext1_read_ext_meta() {
60 let buf: &[u8] = &[0xd4, 0x01];
61 let mut cur = Cursor::new(buf);
62
63 assert_eq!(ExtMeta { typeid: 1, size: 1 }, read_ext_meta(&mut cur).unwrap());
64 assert_eq!(2, cur.position());
65 }
66
67 #[test]
68 fn from_fixext2_read_ext_meta() {
69 let buf: &[u8] = &[0xd5, 0x01];
70 let mut cur = Cursor::new(buf);
71
72 assert_eq!(ExtMeta { typeid: 1, size: 2 }, read_ext_meta(&mut cur).unwrap());
73 assert_eq!(2, cur.position());
74 }
75
76 #[test]
77 fn from_fixext4_read_ext_meta() {
78 let buf: &[u8] = &[0xd6, 0x01];
79 let mut cur = Cursor::new(buf);
80
81 assert_eq!(ExtMeta { typeid: 1, size: 4 }, read_ext_meta(&mut cur).unwrap());
82 assert_eq!(2, cur.position());
83 }
84
85 #[test]
86 fn from_fixext8_read_ext_meta() {
87 let buf: &[u8] = &[0xd7, 0x01];
88 let mut cur = Cursor::new(buf);
89
90 assert_eq!(ExtMeta { typeid: 1, size: 8 }, read_ext_meta(&mut cur).unwrap());
91 assert_eq!(2, cur.position());
92 }
93
94 #[test]
95 fn from_fixext16_read_ext_meta() {
96 let buf: &[u8] = &[0xd8, 0x01];
97 let mut cur = Cursor::new(buf);
98
99 assert_eq!(ExtMeta { typeid: 1, size: 16 }, read_ext_meta(&mut cur).unwrap());
100 assert_eq!(2, cur.position());
101 }
102
103 #[test]
104 fn from_ext8_read_ext_meta() {
105 let buf: &[u8] = &[0xc7, 0xff, 0x01];
106 let mut cur = Cursor::new(buf);
107
108 assert_eq!(ExtMeta { typeid: 1, size: 255 }, read_ext_meta(&mut cur).unwrap());
109 assert_eq!(3, cur.position());
110 }
111
112 #[test]
113 fn from_ext16_read_ext_meta() {
114 let buf: &[u8] = &[0xc8, 0xff, 0xff, 0x01];
115 let mut cur = Cursor::new(buf);
116
117 assert_eq!(ExtMeta { typeid: 1, size: 65535 }, read_ext_meta(&mut cur).unwrap());
118 assert_eq!(4, cur.position());
119 }
120
121 #[test]
122 fn from_ext32_read_ext_meta() {
123 let buf: &[u8] = &[0xc9, 0xff, 0xff, 0xff, 0xff, 0x01];
124 let mut cur = Cursor::new(buf);
125
126 assert_eq!(ExtMeta { typeid: 1, size: 4294967295 }, read_ext_meta(&mut cur).unwrap());
127 assert_eq!(6, cur.position());
128 }