compact binary serialization format with built-in compression
at trunk 1.5 kB view raw
1mod tags; 2 3use std::io::Cursor; 4 5use hateno::{CompressionMethod, reader::Reader, writer::Writer}; 6use insta::assert_debug_snapshot; 7 8#[test] 9fn test_read_hello_world() { 10 let mut reader = Reader::new(Cursor::new(tags::HELLO_WORLD_BYTES)).unwrap(); 11 12 assert_debug_snapshot!(reader.file_header()); 13 14 let hello_world = reader.read_tag().unwrap(); 15 16 assert_debug_snapshot!(hello_world); 17} 18 19#[test] 20fn test_write_hello_world() { 21 let bytes: Vec<u8> = { 22 let mut writer = 23 Writer::new(Vec::new(), CompressionMethod::None).unwrap(); 24 writer.write_tag(&tags::hello_world()).unwrap(); 25 writer.finish().unwrap() 26 }; 27 28 assert_eq!(tags::HELLO_WORLD_BYTES, bytes.as_slice()) 29} 30 31#[inline(always)] 32fn test_round_trip_bt(compression: CompressionMethod) { 33 let bytes: Vec<u8> = { 34 let mut writer = Writer::new(Vec::new(), compression).unwrap(); 35 writer.write_tag(&tags::bigtest()).unwrap(); 36 writer.finish().unwrap() 37 }; 38 let read_tag = Reader::new(Cursor::new(bytes)).unwrap().read_tag().unwrap(); 39 40 assert_eq!(tags::bigtest(), read_tag, "compression: {:?}", compression); 41} 42 43#[test] 44fn test_wr_round_trip_bt_none() { 45 test_round_trip_bt(CompressionMethod::None); 46} 47 48#[test] 49fn test_wr_round_trip_bt_gzip() { 50 test_round_trip_bt(CompressionMethod::Gzip); 51} 52 53#[test] 54fn test_wr_round_trip_bt_zlib() { 55 test_round_trip_bt(CompressionMethod::Zlib); 56} 57 58#[test] 59fn test_wr_round_trip_bt_lz4() { 60 test_round_trip_bt(CompressionMethod::Lz4); 61}