Skip to content

Commit

Permalink
Yay0 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethteck committed Dec 4, 2023
1 parent 2a23046 commit 7a62829
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/yay0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn decompress_yay0(bytes: &[u8]) -> Box<[u8]> {

// Preallocate result and index into it
let mut idx: usize = 0;
let mut ret = vec![0u8; decompressed_size as usize];
let mut ret: Vec<u8> = vec![0u8; decompressed_size as usize];

while idx < decompressed_size as usize {
// If we're out of bits, get the next mask
Expand Down Expand Up @@ -62,3 +62,29 @@ pub fn decompress_yay0(bytes: &[u8]) -> Box<[u8]> {
pub fn compress_yay0(_bytes: &[u8]) -> Box<[u8]> {
panic!("Not implemented")
}

#[cfg(test)]
mod tests {
#[test]
fn test_matching() {
let compressed_file = include_bytes!("../test_data/Yay0/1.Yay0");
let decompressed_file = include_bytes!("../test_data/Yay0/1.bin");

let decompressed: Box<[u8]> = super::decompress_yay0(compressed_file);
assert_eq!(decompressed_file, decompressed.as_ref());

// let recompressed = super::compress_yay0(decompressed_file.as_slice());
// assert_eq!(compressed_file, recompressed);
}

#[test]
#[ignore = "not yet implemented"]
fn test_cycle() {
let decompressed_file = include_bytes!("../test_data/Yay0/1.bin");

assert_eq!(
decompressed_file,
super::decompress_yay0(&super::compress_yay0(decompressed_file.as_ref())).as_ref()
);
}
}
2 changes: 2 additions & 0 deletions test_data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!*.Yay0
!*.bin
Binary file added test_data/Yay0/1.Yay0
Binary file not shown.
1 change: 1 addition & 0 deletions test_data/Yay0/1.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ASCII文字と互換性を持たせるために、ASCIIと同じ部分は1バイト=asdfasdfasdfasdfasdfasdfasdfasdfasdf

0 comments on commit 7a62829

Please sign in to comment.