refactor: Overhaul impl Arbitrary for FileOptions
This commit is contained in:
parent
845c3ec91f
commit
447f9c6e4f
1 changed files with 8 additions and 22 deletions
26
src/write.rs
26
src/write.rs
|
@ -246,7 +246,11 @@ impl<'a> arbitrary::Arbitrary<'a> for FileOptions<'a, ExtendedFileOptions> {
|
||||||
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
|
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||||
let mut options = FullFileOptions {
|
let mut options = FullFileOptions {
|
||||||
compression_method: CompressionMethod::arbitrary(u)?,
|
compression_method: CompressionMethod::arbitrary(u)?,
|
||||||
compression_level: None,
|
compression_level: if bool::arbitrary(u)? {
|
||||||
|
Some(u.int_in_range(0..=24)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
last_modified_time: DateTime::arbitrary(u)?,
|
last_modified_time: DateTime::arbitrary(u)?,
|
||||||
permissions: Option::<u32>::arbitrary(u)?,
|
permissions: Option::<u32>::arbitrary(u)?,
|
||||||
large_file: bool::arbitrary(u)?,
|
large_file: bool::arbitrary(u)?,
|
||||||
|
@ -256,28 +260,10 @@ impl<'a> arbitrary::Arbitrary<'a> for FileOptions<'a, ExtendedFileOptions> {
|
||||||
zopfli_buffer_size: None,
|
zopfli_buffer_size: None,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match options.compression_method {
|
|
||||||
#[cfg(feature = "deflate-zopfli")]
|
#[cfg(feature = "deflate-zopfli")]
|
||||||
CompressionMethod::Deflated => {
|
if options.compression_method == CompressionMethod::Deflated && bool::arbitrary(u)? {
|
||||||
if bool::arbitrary(u)? {
|
|
||||||
let level = u.int_in_range(0..=24)?;
|
|
||||||
options.compression_level = Some(level);
|
|
||||||
if level > Compression::best().level().try_into().unwrap() {
|
|
||||||
options.zopfli_buffer_size = Some(1 << u.int_in_range(9..=30)?);
|
options.zopfli_buffer_size = Some(1 << u.int_in_range(9..=30)?);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
Stored => {
|
|
||||||
if bool::arbitrary(u)? {
|
|
||||||
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(
|
||||||
|
|
Loading…
Add table
Reference in a new issue