Bug fixes and refactors for Arbitrary impl

This commit is contained in:
Chris Hennick 2023-05-27 17:04:27 -07:00
parent 3414e0d6fb
commit f46a0055ad
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74

View file

@ -167,16 +167,27 @@ impl arbitrary::Arbitrary<'_> for FileOptions {
#[cfg(feature = "deflate-zopfli")] #[cfg(feature = "deflate-zopfli")]
zopfli_buffer_size: None, zopfli_buffer_size: None,
}; };
if options.compression_method == Deflated { match options.compression_method {
options.compression_level = Some(u.int_in_range(0..=265)?); Deflated => {
if options.compression_level > Compression::best().level() { if bool::arbitrary(u)? {
let level = u.int_in_range(0..=265)?;
options.compression_level = Some(level);
if level > Compression::best().level() {
options.zopfli_buffer_size = Some(1 << u.int_in_range(9..=30)?); options.zopfli_buffer_size = Some(1 << u.int_in_range(9..=30)?);
} }
} else if options.compression_method != Stored { }
options.compression_level = Some(u.int_in_range(0..=10)?); },
} else if bool::arbitrary(u)? { Stored => {
if bool::arbitrary(u)? {
options.compression_level = Some(1); options.compression_level = Some(1);
} }
},
_ => {
if bool::arbitrary(u)? {
options.compression_level = Some(u.int_in_range(0..=10)?);
}
}
}
u.arbitrary_loop(Some(0), Some((u16::MAX / 4) as u32), |u| { u.arbitrary_loop(Some(0), Some((u16::MAX / 4) as u32), |u| {
options options
.add_extra_data( .add_extra_data(