mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
fmt: show error if goal > default width
This commit is contained in:
parent
45bdca9f16
commit
3ad226cf54
2 changed files with 14 additions and 0 deletions
|
@ -101,6 +101,9 @@ impl FmtOptions {
|
||||||
(w, g)
|
(w, g)
|
||||||
}
|
}
|
||||||
(None, Some(&g)) => {
|
(None, Some(&g)) => {
|
||||||
|
if g > DEFAULT_WIDTH {
|
||||||
|
return Err(USimpleError::new(1, "GOAL cannot be greater than WIDTH."));
|
||||||
|
}
|
||||||
let w = (g * 100 / DEFAULT_GOAL_TO_WIDTH_RATIO).max(g + 3);
|
let w = (g * 100 / DEFAULT_GOAL_TO_WIDTH_RATIO).max(g + 3);
|
||||||
(w, g)
|
(w, g)
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,17 @@ fn test_fmt_goal_too_big() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fmt_goal_bigger_than_default_width_of_75() {
|
||||||
|
for param in ["-g", "--goal"] {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["one-word-per-line.txt", param, "76"])
|
||||||
|
.fails()
|
||||||
|
.code_is(1)
|
||||||
|
.stderr_is("fmt: GOAL cannot be greater than WIDTH.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fmt_invalid_goal() {
|
fn test_fmt_invalid_goal() {
|
||||||
for param in ["-g", "--goal"] {
|
for param in ["-g", "--goal"] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue