2023-08-21 08:49:27 +00:00
|
|
|
// This file is part of the uutils coreutils package.
|
|
|
|
//
|
|
|
|
// For the full copyright and license information, please view the LICENSE
|
|
|
|
// file that was distributed with this source code.
|
2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2020-05-05 21:15:50 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2020-05-05 21:15:50 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fmt() {
|
2023-04-20 13:22:26 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("one-word-per-line.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("this is a file with one word per line\n");
|
2020-05-05 21:15:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-04-20 13:22:26 +00:00
|
|
|
fn test_fmt_quick() {
|
|
|
|
for param in ["-q", "--quick"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["one-word-per-line.txt", param])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("this is a file with one word per line\n");
|
|
|
|
}
|
2020-05-05 21:15:50 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 21:41:05 +00:00
|
|
|
#[test]
|
2023-04-20 13:22:26 +00:00
|
|
|
fn test_fmt_width() {
|
|
|
|
for param in ["-w", "--width"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["one-word-per-line.txt", param, "10"])
|
|
|
|
.succeeds()
|
2024-03-19 05:23:45 +00:00
|
|
|
.stdout_is("this is a\nfile with\none word\nper line\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_small_width() {
|
|
|
|
for width in ["0", "1", "2", "3"] {
|
|
|
|
for param in ["-w", "--width"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[param, width, "one-word-per-line.txt"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("this\nis\na\nfile\nwith\none\nword\nper\nline\n");
|
|
|
|
}
|
2023-04-20 13:22:26 +00:00
|
|
|
}
|
2021-01-24 21:41:05 +00:00
|
|
|
}
|
2023-04-20 13:22:26 +00:00
|
|
|
|
2021-05-05 21:12:17 +00:00
|
|
|
#[test]
|
2023-04-20 13:22:26 +00:00
|
|
|
fn test_fmt_width_too_big() {
|
|
|
|
for param in ["-w", "--width"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["one-word-per-line.txt", param, "2501"])
|
|
|
|
.fails()
|
|
|
|
.code_is(1)
|
|
|
|
.stderr_is("fmt: invalid width: '2501': Numerical result out of range\n");
|
|
|
|
}
|
2020-05-05 21:15:50 +00:00
|
|
|
}
|
2023-08-14 13:44:55 +00:00
|
|
|
|
2023-09-28 08:50:56 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fmt_invalid_width() {
|
|
|
|
for param in ["-w", "--width"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["one-word-per-line.txt", param, "invalid"])
|
|
|
|
.fails()
|
|
|
|
.code_is(1)
|
|
|
|
.stderr_contains("invalid value 'invalid'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 15:43:32 +00:00
|
|
|
#[ignore]
|
2023-08-14 13:44:55 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fmt_goal() {
|
|
|
|
for param in ["-g", "--goal"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["one-word-per-line.txt", param, "7"])
|
|
|
|
.succeeds()
|
2023-08-14 15:43:32 +00:00
|
|
|
.stdout_is("this is a\nfile with one\nword per line\n");
|
2023-08-14 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 09:26:11 +00:00
|
|
|
#[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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-28 08:50:56 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fmt_invalid_goal() {
|
|
|
|
for param in ["-g", "--goal"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["one-word-per-line.txt", param, "invalid"])
|
|
|
|
.fails()
|
|
|
|
.code_is(1)
|
|
|
|
.stderr_contains("invalid value 'invalid'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 13:44:55 +00:00
|
|
|
#[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");
|
|
|
|
}
|
|
|
|
}
|