mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
fmt: fix panic on width argument
This commit is contained in:
parent
6ffea22b57
commit
946e1bb2d1
2 changed files with 32 additions and 1 deletions
|
@ -168,7 +168,7 @@ fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if !matches.get_flag(OPT_WIDTH) {
|
if !matches.contains_id(OPT_WIDTH) {
|
||||||
fmt_opts.width = cmp::max(
|
fmt_opts.width = cmp::max(
|
||||||
fmt_opts.goal * 100 / DEFAULT_GOAL_TO_WIDTH_RATIO,
|
fmt_opts.goal * 100 / DEFAULT_GOAL_TO_WIDTH_RATIO,
|
||||||
fmt_opts.goal + 3,
|
fmt_opts.goal + 3,
|
||||||
|
|
|
@ -43,3 +43,34 @@ fn test_fmt_width_too_big() {
|
||||||
.stderr_is("fmt: invalid width: '2501': Numerical result out of range\n");
|
.stderr_is("fmt: invalid width: '2501': Numerical result out of range\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fmt_goal() {
|
||||||
|
for param in ["-g", "--goal"] {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["one-word-per-line.txt", param, "7"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("this is\na file\nwith one\nword per\nline\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fmt_goal_too_big() {
|
||||||
|
for param in ["-g", "--goal"] {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["one-word-per-line.txt", "--width=75", param, "76"])
|
||||||
|
.fails()
|
||||||
|
.code_is(1)
|
||||||
|
.stderr_is("fmt: GOAL cannot be greater than WIDTH.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fmt_set_goal_not_contain_width() {
|
||||||
|
for param in ["-g", "--goal"] {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["one-word-per-line.txt", param, "74"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("this is a file with one word per line\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue