1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

fmt: value of minlength should not be negative

closes #6354
This commit is contained in:
ahmadabd 2024-05-05 14:17:52 +03:30 committed by Ben Wiederhake
parent f9b4fada14
commit a3d05e5945
2 changed files with 11 additions and 1 deletions

View file

@ -239,7 +239,7 @@ fn find_kp_breakpoints<'a, T: Iterator<Item = &'a WordInfo<'a>>>(
let mut next_active_breaks = vec![];
let stretch = args.opts.width - args.opts.goal;
let minlength = args.opts.goal - stretch;
let minlength = args.opts.goal.max(stretch + 1) - stretch;
let mut new_linebreaks = vec![];
let mut is_sentence_start = false;
let mut least_demerits = 0;

View file

@ -156,6 +156,16 @@ fn test_fmt_too_big_goal_sometimes_okay() {
.stdout_is("this is a\nfile with one\nword per line\n");
}
#[test]
fn test_fmt_goal_too_small_to_check_negative_minlength() {
for param in ["-g", "--goal"] {
new_ucmd!()
.args(&["one-word-per-line.txt", "--width=75", param, "10"])
.succeeds()
.stdout_is("this is a file with one word per line\n");
}
}
#[test]
fn test_fmt_non_existent_file() {
new_ucmd!()