mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 20:15:27 +00:00
option level tests
This commit is contained in:
parent
b8b9c5042f
commit
e92b9ff723
@ -60,7 +60,7 @@ pub enum Subcommand {
|
|||||||
#[arg(required = true, value_hint = ValueHint::FilePath)]
|
#[arg(required = true, value_hint = ValueHint::FilePath)]
|
||||||
output: PathBuf,
|
output: PathBuf,
|
||||||
|
|
||||||
/// Compression raw level as each algo has
|
/// Compression level, applied to all formats
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
level: Option<i16>,
|
level: Option<i16>,
|
||||||
},
|
},
|
||||||
|
@ -57,7 +57,7 @@ pub fn compress_files(
|
|||||||
Lz4 => Box::new(lzzzz::lz4f::WriteCompressor::new(
|
Lz4 => Box::new(lzzzz::lz4f::WriteCompressor::new(
|
||||||
encoder,
|
encoder,
|
||||||
lzzzz::lz4f::PreferencesBuilder::new()
|
lzzzz::lz4f::PreferencesBuilder::new()
|
||||||
.compression_level(level.map_or(0, |l| (l as i32).clamp(1, lzzzz::lz4f::CLEVEL_MAX)))
|
.compression_level(level.map_or(1, |l| (l as i32).clamp(1, lzzzz::lz4f::CLEVEL_MAX)))
|
||||||
.build(),
|
.build(),
|
||||||
)?),
|
)?),
|
||||||
Lzma => Box::new(xz2::write::XzEncoder::new(
|
Lzma => Box::new(xz2::write::XzEncoder::new(
|
||||||
@ -71,16 +71,18 @@ pub fn compress_files(
|
|||||||
))
|
))
|
||||||
.from_writer(encoder),
|
.from_writer(encoder),
|
||||||
),
|
),
|
||||||
Zstd => Box::new(
|
Zstd => {
|
||||||
zstd::stream::write::Encoder::new(
|
let zstd_encoder = zstd::stream::write::Encoder::new(
|
||||||
encoder,
|
encoder,
|
||||||
level.map_or(0, |l| {
|
level.map_or(zstd::DEFAULT_COMPRESSION_LEVEL, |l| {
|
||||||
(l as i32).clamp(zstd::zstd_safe::min_c_level(), zstd::zstd_safe::max_c_level())
|
(l as i32).clamp(zstd::zstd_safe::min_c_level(), zstd::zstd_safe::max_c_level())
|
||||||
}),
|
}),
|
||||||
)
|
);
|
||||||
.unwrap()
|
// Safety:
|
||||||
.auto_finish(),
|
// Encoder::new() can only fail if `level` is invalid, but Default::default()
|
||||||
),
|
// is guaranteed to be valid
|
||||||
|
Box::new(zstd_encoder.unwrap().auto_finish())
|
||||||
|
}
|
||||||
Tar | Zip => unreachable!(),
|
Tar | Zip => unreachable!(),
|
||||||
};
|
};
|
||||||
Ok(encoder)
|
Ok(encoder)
|
||||||
|
@ -103,7 +103,7 @@ fn single_empty_file(ext: Extension, #[any(size_range(0..8).lift())] exts: Vec<F
|
|||||||
fn single_file(
|
fn single_file(
|
||||||
ext: Extension,
|
ext: Extension,
|
||||||
#[any(size_range(0..8).lift())] exts: Vec<FileExtension>,
|
#[any(size_range(0..8).lift())] exts: Vec<FileExtension>,
|
||||||
#[strategy(0i16..30)] level: i16,
|
#[strategy(proptest::option::of(0i16..30))] level: Option<i16>,
|
||||||
) {
|
) {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let dir = dir.path();
|
let dir = dir.path();
|
||||||
@ -113,7 +113,11 @@ fn single_file(
|
|||||||
let archive = &dir.join(format!("file.{}", merge_extensions(ext, exts)));
|
let archive = &dir.join(format!("file.{}", merge_extensions(ext, exts)));
|
||||||
let after = &dir.join("after");
|
let after = &dir.join("after");
|
||||||
fs::write(before_file, []).unwrap();
|
fs::write(before_file, []).unwrap();
|
||||||
|
if let Some(level) = level {
|
||||||
ouch!("-A", "c", "-l", level.to_string(), before_file, archive);
|
ouch!("-A", "c", "-l", level.to_string(), before_file, archive);
|
||||||
|
} else {
|
||||||
|
ouch!("-A", "c", before_file, archive);
|
||||||
|
}
|
||||||
ouch!("-A", "d", archive, "-d", after);
|
ouch!("-A", "d", archive, "-d", after);
|
||||||
assert_same_directory(before, after, false);
|
assert_same_directory(before, after, false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user