File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -36,3 +36,30 @@ pub fn read_compact_size<R: Read>(reader: &mut R) -> Result<u64, io::Error> {
3636 _ => panic ! ( "unexpected large offset" ) ,
3737 }
3838}
39+
40+ #[ cfg( test) ]
41+ mod tests {
42+ use crate :: { read_compact_size, write_compact_size} ;
43+
44+ #[ test]
45+ fn deser_roundtrip ( ) {
46+ let mut buf = Vec :: new ( ) ;
47+ let less: u8 = 0xFB ;
48+ write_compact_size ( less as u64 , & mut buf) . unwrap ( ) ;
49+ let read_cs = read_compact_size ( & mut buf. as_slice ( ) ) . unwrap ( ) ;
50+ let cast_less = read_cs as u8 ;
51+ assert_eq ! ( less, cast_less) ;
52+ let mut buf = Vec :: new ( ) ;
53+ let median: u16 = 0xFFF ;
54+ write_compact_size ( median as u64 , & mut buf) . unwrap ( ) ;
55+ let read_cs = read_compact_size ( & mut buf. as_slice ( ) ) . unwrap ( ) ;
56+ let cast_median = read_cs as u16 ;
57+ assert_eq ! ( median, cast_median) ;
58+ let mut buf = Vec :: new ( ) ;
59+ let more: u32 = 0xFFFFF ;
60+ write_compact_size ( more as u64 , & mut buf) . unwrap ( ) ;
61+ let read_cs = read_compact_size ( & mut buf. as_slice ( ) ) . unwrap ( ) ;
62+ let cast_more = read_cs as u32 ;
63+ assert_eq ! ( more, cast_more) ;
64+ }
65+ }
You can’t perform that action at this time.
0 commit comments