Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new test exposing mysterious bug #8

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ fn version() {
.is_match(version));
}

#[test]
fn test_compressing_and_decompressing_small_input() {
// Input to be compressed and decompressed
let input: &[u8] = &[1, 2, 3];

let compressed = {
let mut output = vec![];
io::copy(
&mut &*input,
&mut write::Bz3Encoder::new(&mut output, 100 * KB).unwrap(),
)
.unwrap();

output
};

let decompressed = {
let mut output = vec![];
io::copy(
&mut read::Bz3Decoder::new(compressed.as_slice()).unwrap(),
Comment on lines +70 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure that this test is coherent, you can apply these diffs:

- &mut write::Bz3Encoder::new(&mut output, 100 * KB).unwrap(),
+ &mut xz2::write::XzEncoder::new(&mut output, 6),

and

- &mut read::Bz3Decoder::new(compressed.as_slice()).unwrap(),
+ &mut xz2::read::XzDecoder::new(compressed.as_slice()),

Then run this:

cargo add --dev xz2
cargo test -- test_compressing_and_decompressing_small_input

And the test will pass, I am assuming xz2 is battle-tested and is behaving correctly right here.

&mut output,
)
.unwrap();

output
};

assert_eq!(input, decompressed);
}

#[test]
fn test_chained_encoders_and_decoders_with_single_block() {
// 100kb gets shrunk down to 22kb-24kb, so it fits in a single 70kb block
Expand Down
Loading