fix(cli): keep normal help levels below ultra
The library reports an absolute maximum compression level of 22, but the CLI advertises levels 1 through 19 unless `--ultra` is selected. The Rust frontend used the absolute maximum for both help lines, diverging from the original C contract and failing the help golden test. Separate the normal help ceiling from the ultra ceiling and add a focused regression assertion. Test Plan: - `cargo fmt --manifest-path rust/cli/Cargo.toml -- --check` -- passed - `cargo clippy --manifest-path rust/cli/Cargo.toml --lib -- -D warnings` -- passed - CLI Rust tests -- 162 passed - `make -C tests -j2 test-cli-tests` -- all 41 passed - `git diff --check` -- passed
This commit is contained in:
+17
-2
@@ -680,7 +680,7 @@ fn program_basename(value: &OsStr) -> String {
|
||||
|
||||
#[cfg(feature = "compression")]
|
||||
fn max_c_level_for_help() -> i32 {
|
||||
unsafe { ZSTD_maxCLevel() }
|
||||
DEFAULT_MAX_CLEVEL
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "compression"))]
|
||||
@@ -688,6 +688,16 @@ const fn max_c_level_for_help() -> i32 {
|
||||
19
|
||||
}
|
||||
|
||||
#[cfg(feature = "compression")]
|
||||
fn max_c_level_for_ultra() -> i32 {
|
||||
unsafe { ZSTD_maxCLevel() }
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "compression"))]
|
||||
const fn max_c_level_for_ultra() -> i32 {
|
||||
19
|
||||
}
|
||||
|
||||
fn write_basic_usage<W: Write>(out: &mut W, program_name: &str) {
|
||||
let max_level = max_c_level_for_help();
|
||||
let _ = writeln!(
|
||||
@@ -830,7 +840,7 @@ fn write_advanced_usage<W: Write>(out: &mut W, program_name: &str) {
|
||||
let _ = writeln!(
|
||||
out,
|
||||
" --ultra Enable levels beyond 19, up to {}; requires more memory.",
|
||||
max_c_level_for_help()
|
||||
max_c_level_for_ultra()
|
||||
);
|
||||
let _ = writeln!(
|
||||
out,
|
||||
@@ -2926,6 +2936,11 @@ mod tests {
|
||||
assert_eq!(cli.compression_format, CompressionFormat::Zstd);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normal_help_ceiling_excludes_ultra_levels() {
|
||||
assert_eq!(max_c_level_for_help(), 19);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_option_selects_frame_type_and_suffix() {
|
||||
let cli = parse(&["zstd", "--format=gzip", "input"]);
|
||||
|
||||
Reference in New Issue
Block a user