diff --git a/src/yaz0.rs b/src/yaz0.rs index f1a1046..5a8d4b8 100644 --- a/src/yaz0.rs +++ b/src/yaz0.rs @@ -130,8 +130,8 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> { if cur_layout_bit == 0 { cur_layout_bit = 0x80; index_cur_layout_byte = index_out_ptr; + output.push(0); index_out_ptr += 1; - output[index_cur_layout_byte] = 0; } group_size = new_size; @@ -178,27 +178,51 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> { #[cfg(test)] mod tests { - #[test] - fn test_matching_decompression() { - let compressed_file = include_bytes!("../test_data/small.txt.Yaz0"); - let decompressed_file = include_bytes!("../test_data/small.txt"); + use core::panic; + use rstest::rstest; + use std::{ + fs::File, + io::{BufReader, Read}, + path::PathBuf, + }; + + pub fn read_test_file(path: PathBuf) -> Vec { + let file = match File::open(path) { + Ok(file) => file, + Err(_error) => { + panic!("Failed to open file"); + } + }; + + let mut buf_reader = BufReader::new(file); + let mut buffer = Vec::new(); + + let _ = buf_reader.read_to_end(&mut buffer); + + buffer + } + + #[rstest] + fn test_matching_decompression(#[files("test_data/*.Yaz0")] path: PathBuf) { + let compressed_file = &read_test_file(path.clone()); + let decompressed_file = &read_test_file(path.with_extension("")); let decompressed: Box<[u8]> = super::decompress_yaz0(compressed_file); assert_eq!(decompressed_file, decompressed.as_ref()); } - #[test] - fn test_matching_compression() { - let compressed_file = include_bytes!("../test_data/small.txt.Yaz0"); - let decompressed_file = include_bytes!("../test_data/small.txt"); + #[rstest] + fn test_matching_compression(#[files("test_data/*.Yaz0")] path: PathBuf) { + let compressed_file = &read_test_file(path.clone()); + let decompressed_file = &read_test_file(path.with_extension("")); let compressed = super::compress_yaz0(decompressed_file.as_slice()); assert_eq!(compressed_file, compressed.as_ref()); } - #[test] - fn test_cycle_decompressed() { - let decompressed_file = include_bytes!("../test_data/small.txt"); + #[rstest] + fn test_cycle_decompressed(#[files("test_data/*.Yaz0")] path: PathBuf) { + let decompressed_file = &read_test_file(path.with_extension("")); assert_eq!( decompressed_file, @@ -206,9 +230,9 @@ mod tests { ); } - #[test] - fn test_cycle_compressed() { - let compressed_file = include_bytes!("../test_data/small.txt.Yaz0"); + #[rstest] + fn test_cycle_compressed(#[files("test_data/*.Yaz0")] path: PathBuf) { + let compressed_file = &read_test_file(path); assert_eq!( compressed_file, diff --git a/test_data/dirt.png.Yaz0 b/test_data/dirt.png.Yaz0 new file mode 100644 index 0000000..7981ac3 Binary files /dev/null and b/test_data/dirt.png.Yaz0 differ diff --git a/test_data/dirt.png.bin.Yaz0 b/test_data/dirt.png.bin.Yaz0 new file mode 100644 index 0000000..19097fe Binary files /dev/null and b/test_data/dirt.png.bin.Yaz0 differ diff --git a/test_data/ground.png.Yaz0 b/test_data/ground.png.Yaz0 new file mode 100644 index 0000000..a3b0440 Binary files /dev/null and b/test_data/ground.png.Yaz0 differ diff --git a/test_data/ground.png.bin.Yaz0 b/test_data/ground.png.bin.Yaz0 new file mode 100644 index 0000000..b5da8fb Binary files /dev/null and b/test_data/ground.png.bin.Yaz0 differ diff --git a/test_data/mips_gist_wiseguy_yaz0.bin b/test_data/mips_gist_wiseguy_yaz0.bin new file mode 100755 index 0000000..77c8bc3 Binary files /dev/null and b/test_data/mips_gist_wiseguy_yaz0.bin differ diff --git a/test_data/mips_gist_wiseguy_yaz0.bin.Yay0 b/test_data/mips_gist_wiseguy_yaz0.bin.Yay0 new file mode 100644 index 0000000..ac800bd Binary files /dev/null and b/test_data/mips_gist_wiseguy_yaz0.bin.Yay0 differ diff --git a/test_data/mips_gist_wiseguy_yaz0.bin.Yaz0 b/test_data/mips_gist_wiseguy_yaz0.bin.Yaz0 new file mode 100644 index 0000000..8d19c6f Binary files /dev/null and b/test_data/mips_gist_wiseguy_yaz0.bin.Yaz0 differ diff --git a/test_data/stones.png.Yaz0 b/test_data/stones.png.Yaz0 new file mode 100644 index 0000000..6d3e7ad Binary files /dev/null and b/test_data/stones.png.Yaz0 differ diff --git a/test_data/stones.png.bin.Yaz0 b/test_data/stones.png.bin.Yaz0 new file mode 100644 index 0000000..c04e47c Binary files /dev/null and b/test_data/stones.png.bin.Yaz0 differ diff --git a/test_data/tile.png.Yaz0 b/test_data/tile.png.Yaz0 new file mode 100644 index 0000000..3e4ca84 Binary files /dev/null and b/test_data/tile.png.Yaz0 differ diff --git a/test_data/tile.png.bin.Yaz0 b/test_data/tile.png.bin.Yaz0 new file mode 100644 index 0000000..379f0ef Binary files /dev/null and b/test_data/tile.png.bin.Yaz0 differ diff --git a/test_data/x86-64_rabbitizer.bin b/test_data/x86-64_rabbitizer.bin new file mode 100644 index 0000000..f45ae40 Binary files /dev/null and b/test_data/x86-64_rabbitizer.bin differ diff --git a/test_data/x86-64_rabbitizer.bin.Yay0 b/test_data/x86-64_rabbitizer.bin.Yay0 new file mode 100644 index 0000000..a1821dc Binary files /dev/null and b/test_data/x86-64_rabbitizer.bin.Yay0 differ diff --git a/test_data/x86-64_rabbitizer.bin.Yaz0 b/test_data/x86-64_rabbitizer.bin.Yaz0 new file mode 100644 index 0000000..0c4fa20 Binary files /dev/null and b/test_data/x86-64_rabbitizer.bin.Yaz0 differ