Repository navigation
Conversation
Merging this PR will improve performance by 32.72%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
| continue; | ||
| } | ||
|
|
||
| if tabsize_re.is_match(param.to_string_lossy().as_ref()) { |
There was a problem hiding this comment.
#396 also reports --tabsize 4 being rejected.
could you please move tabsize to option_argument/argument_value too? it would also get rid of the regex and the unwrap()
| } | ||
| Err(_) => return Err(format!("invalid width «{width_str}»")), | ||
| Ok(num) if num != 0 => num, | ||
| _ => return Err(format!("invalid width «{}»", width_str)), |
There was a problem hiding this comment.
{width_str} inline, like tabsize below?
| let mut show_c_function = false; | ||
| let tabsize_re = Regex::new(r"^--tabsize=(?<num>\d+)$").unwrap(); | ||
| let width_re = Regex::new(r"^--width=(?P<long>\d+)$").unwrap(); | ||
|
|
There was a problem hiding this comment.
please remove this empty line
| .peekable() | ||
| ) | ||
| ); | ||
| let parse = |args: &[&str]| { |
There was a problem hiding this comment.
please also add the test from the issue in tests/by-util/test_diff.rs, so the real binary is checked with -y -W 20
Allow the -W/--width and --tabsize options to accept arguments provided as separate command-line parameters. Replace the tabsize regex parsing with option_argument and argument_value to handle both attached and separate arguments. Add unit and integration tests covering separate arguments, missing arguments, and invalid tabsize values.
|
|
||
| ts.ucmd() | ||
| .args(&["-y", "-W", "20", "file1", "file2"]) | ||
| .run() |
There was a problem hiding this comment.
could you please use .fails_with_code(1) instead of .run()? so we also check the exit code
Fixes #396
This PR fixes the handling of the
-Wand--widthoptions indiffutils.Previously, only the
--width=VALUEsyntax was supported. This change reuses the existingoption_argumentandargument_valuehelpers to support all standard argument formats:-W 20-W20--width=20--width 20It also adds tests covering all supported formats, invalid values, zero width, and missing arguments.
Testing
cargo fmt --checkcargo testAll tests pass.