2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2021-08-25 14:39:00 +00:00
|
|
|
// spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars
|
2021-05-30 05:10:54 +00:00
|
|
|
|
2021-04-10 20:19:53 +00:00
|
|
|
#[test]
|
|
|
|
fn test_count_bytes_large_stdin() {
|
|
|
|
for &n in &[
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
42,
|
|
|
|
16 * 1024 - 7,
|
|
|
|
16 * 1024 - 1,
|
|
|
|
16 * 1024,
|
|
|
|
16 * 1024 + 1,
|
|
|
|
16 * 1024 + 3,
|
|
|
|
32 * 1024,
|
|
|
|
64 * 1024,
|
|
|
|
80 * 1024,
|
|
|
|
96 * 1024,
|
|
|
|
112 * 1024,
|
|
|
|
128 * 1024,
|
|
|
|
] {
|
|
|
|
let data = vec_of_size(n);
|
|
|
|
let expected = format!("{}\n", n);
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c"])
|
|
|
|
.pipe_in(data)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is_bytes(&expected.as_bytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_default() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.pipe_in_fixture("lorem_ipsum.txt")
|
|
|
|
.run()
|
2021-05-07 19:07:17 +00:00
|
|
|
.stdout_is(" 13 109 772\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 13:42:55 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_explicit() {
|
|
|
|
new_ucmd!()
|
|
|
|
.pipe_in_fixture("lorem_ipsum.txt")
|
|
|
|
.arg("-")
|
|
|
|
.run()
|
2021-05-07 19:07:17 +00:00
|
|
|
.stdout_is(" 13 109 772 -\n");
|
2021-05-09 13:42:55 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 12:36:49 +00:00
|
|
|
#[test]
|
|
|
|
fn test_utf8() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-lwmcL"])
|
|
|
|
.pipe_in_fixture("UTF_8_test.txt")
|
|
|
|
.run()
|
2021-08-25 12:40:17 +00:00
|
|
|
.stdout_is(" 303 2119 22457 23025 79\n");
|
2021-08-25 11:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_utf8_extra() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-lwmcL")
|
|
|
|
.pipe_in_fixture("UTF_8_weirdchars.txt")
|
|
|
|
.run()
|
2021-08-25 12:40:17 +00:00
|
|
|
.stdout_is(" 25 87 442 513 48\n");
|
2021-02-16 12:36:49 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 20:54:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_line_len_regression() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-L"])
|
|
|
|
.pipe_in("\n123456")
|
|
|
|
.run()
|
2021-03-30 18:53:02 +00:00
|
|
|
.stdout_is("6\n");
|
2021-02-08 20:54:48 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_only_bytes() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c"])
|
|
|
|
.pipe_in_fixture("lorem_ipsum.txt")
|
|
|
|
.run()
|
2021-03-30 18:53:02 +00:00
|
|
|
.stdout_is("772\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_all_counts() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "-m", "-l", "-L", "-w"])
|
2016-08-13 21:59:21 +00:00
|
|
|
.pipe_in_fixture("alice_in_wonderland.txt")
|
|
|
|
.run()
|
2021-05-07 19:07:17 +00:00
|
|
|
.stdout_is(" 5 57 302 302 66\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_default() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.arg("moby_dick.txt")
|
|
|
|
.run()
|
2021-05-06 00:59:37 +00:00
|
|
|
.stdout_is(" 18 204 1115 moby_dick.txt\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_only_lines() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-l", "moby_dick.txt"])
|
|
|
|
.run()
|
2021-03-30 18:53:02 +00:00
|
|
|
.stdout_is("18 moby_dick.txt\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_all_counts() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-c", "-l", "-L", "-m", "-w", "alice_in_wonderland.txt"])
|
|
|
|
.run()
|
2021-05-06 00:59:37 +00:00
|
|
|
.stdout_is(" 5 57 302 302 66 alice_in_wonderland.txt\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_default() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&[
|
|
|
|
"lorem_ipsum.txt",
|
|
|
|
"moby_dick.txt",
|
|
|
|
"alice_in_wonderland.txt",
|
|
|
|
])
|
|
|
|
.run()
|
2016-08-13 21:59:21 +00:00
|
|
|
.stdout_is(
|
2021-05-06 00:59:37 +00:00
|
|
|
" 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 5 57 302 \
|
|
|
|
alice_in_wonderland.txt\n 36 370 2189 total\n",
|
2020-04-13 18:36:03 +00:00
|
|
|
);
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2021-05-04 00:52:32 +00:00
|
|
|
|
|
|
|
/// Test for an empty file.
|
|
|
|
#[test]
|
|
|
|
fn test_file_empty() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-clmwL", "emptyfile.txt"])
|
|
|
|
.run()
|
2021-05-06 00:59:37 +00:00
|
|
|
.stdout_is("0 0 0 0 0 emptyfile.txt\n");
|
2021-05-04 00:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Test for an file containing a single non-whitespace character
|
|
|
|
/// *without* a trailing newline.
|
|
|
|
#[test]
|
|
|
|
fn test_file_single_line_no_trailing_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-clmwL", "notrailingnewline.txt"])
|
|
|
|
.run()
|
2021-05-06 00:59:37 +00:00
|
|
|
.stdout_is("1 1 2 2 1 notrailingnewline.txt\n");
|
2021-05-04 00:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Test for a file that has 100 empty lines (that is, the contents of
|
|
|
|
/// the file are the newline character repeated one hundred times).
|
|
|
|
#[test]
|
|
|
|
fn test_file_many_empty_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-clmwL", "manyemptylines.txt"])
|
|
|
|
.run()
|
2021-05-06 00:59:37 +00:00
|
|
|
.stdout_is("100 0 100 100 0 manyemptylines.txt\n");
|
2021-05-04 00:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Test for a file that has one long line comprising only spaces.
|
|
|
|
#[test]
|
|
|
|
fn test_file_one_long_line_only_spaces() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-clmwL", "onelongemptyline.txt"])
|
|
|
|
.run()
|
2021-05-06 00:59:37 +00:00
|
|
|
.stdout_is(" 1 0 10001 10001 10000 onelongemptyline.txt\n");
|
2021-05-04 00:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Test for a file that has one long line comprising a single "word".
|
|
|
|
#[test]
|
|
|
|
fn test_file_one_long_word() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-clmwL", "onelongword.txt"])
|
|
|
|
.run()
|
2021-05-06 00:59:37 +00:00
|
|
|
.stdout_is(" 1 1 10001 10001 10000 onelongword.txt\n");
|
2021-05-04 00:52:32 +00:00
|
|
|
}
|
2021-05-15 14:32:03 +00:00
|
|
|
|
2021-05-07 19:07:17 +00:00
|
|
|
/// Test that the number of bytes in the file dictate the display width.
|
|
|
|
///
|
|
|
|
/// The width in digits of any count is the width in digits of the
|
|
|
|
/// number of bytes in the file, regardless of whether the number of
|
|
|
|
/// bytes are displayed.
|
|
|
|
#[test]
|
|
|
|
fn test_file_bytes_dictate_width() {
|
|
|
|
// This file has 10,001 bytes. Five digits are required to
|
|
|
|
// represent that. Even though the number of lines is 1 and the
|
|
|
|
// number of words is 0, each of those counts is formatted with
|
|
|
|
// five characters, filled with whitespace.
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-lw", "onelongemptyline.txt"])
|
|
|
|
.run()
|
|
|
|
.stdout_is(" 1 0 onelongemptyline.txt\n");
|
|
|
|
|
|
|
|
// This file has zero bytes. Only one digit is required to
|
|
|
|
// represent that.
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-lw", "emptyfile.txt"])
|
|
|
|
.run()
|
|
|
|
.stdout_is("0 0 emptyfile.txt\n");
|
|
|
|
}
|
|
|
|
|
2021-05-15 14:32:03 +00:00
|
|
|
/// Test that getting counts from a directory is an error.
|
|
|
|
#[test]
|
|
|
|
fn test_read_from_directory_error() {
|
|
|
|
// TODO To match GNU `wc`, the `stdout` should be:
|
|
|
|
//
|
|
|
|
// " 0 0 0 .\n"
|
|
|
|
//
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["."])
|
|
|
|
.fails()
|
2021-08-25 12:26:03 +00:00
|
|
|
.stderr_contains(".: Is a directory")
|
2021-08-25 13:29:08 +00:00
|
|
|
.stdout_is(" 0 0 0 .\n");
|
2021-05-15 14:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Test that getting counts from nonexistent file is an error.
|
|
|
|
#[test]
|
|
|
|
fn test_read_from_nonexistent_file() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["bogusfile"])
|
|
|
|
.fails()
|
2021-08-25 12:26:03 +00:00
|
|
|
.stderr_contains("bogusfile: No such file or directory");
|
2021-05-15 14:32:03 +00:00
|
|
|
}
|