1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 03:36:18 +00:00

Merge pull request #3304 from ackerleytng/main

wc: compute number widths using total file sizes
This commit is contained in:
Sylvestre Ledru 2022-03-30 09:52:21 +02:00 committed by GitHub
commit 1e6b248a77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 118 deletions

View file

@ -181,7 +181,8 @@ fn test_file_one_long_word() {
.stdout_is(" 1 1 10001 10001 10000 onelongword.txt\n");
}
/// Test that the number of bytes in the file dictate the display width.
/// Test that the total size of all the files in the input dictates
/// 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
@ -203,6 +204,27 @@ fn test_file_bytes_dictate_width() {
.args(&["-lw", "emptyfile.txt"])
.run()
.stdout_is("0 0 emptyfile.txt\n");
// lorem_ipsum.txt contains 772 bytes, and alice_in_wonderland.txt contains
// 302 bytes. The total is 1074 bytes, which has a width of 4
new_ucmd!()
.args(&["-lwc", "alice_in_wonderland.txt", "lorem_ipsum.txt"])
.run()
.stdout_is(
" 5 57 302 alice_in_wonderland.txt\n 13 109 772 \
lorem_ipsum.txt\n 18 166 1074 total\n",
);
// . is a directory, so minimum_width should get set to 7
#[cfg(not(windows))]
const STDOUT: &str = " 0 0 0 emptyfile.txt\n 0 0 0 \
.\n 0 0 0 total\n";
#[cfg(windows)]
const STDOUT: &str = " 0 0 0 emptyfile.txt\n 0 0 0 total\n";
new_ucmd!()
.args(&["-lwc", "emptyfile.txt", "."])
.run()
.stdout_is(STDOUT);
}
/// Test that getting counts from a directory is an error.