Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions text/tests/wc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ fn wc_test(args: &[&str], test_data: &str, expected_output: &str) {

#[test]
fn wc_empty() {
wc_test(&["-c"], "", "0\n");
wc_test(&["-l"], "", "0\n");
wc_test(&["-w"], "", "0\n");
wc_test(&["-c"], "", "0 (stdin)\n");
wc_test(&["-l"], "", "0 (stdin)\n");
wc_test(&["-w"], "", "0 (stdin)\n");
}

#[test]
fn wc_one() {
wc_test(&["-c"], "x", "1\n");
wc_test(&["-l"], "x", "0\n");
wc_test(&["-w"], "x", "1\n");
wc_test(&["-c"], "x", "1 (stdin)\n");
wc_test(&["-l"], "x", "0 (stdin)\n");
wc_test(&["-w"], "x", "1 (stdin)\n");
}

#[test]
fn wc_two() {
wc_test(&["-c"], "x y\n", "4\n");
wc_test(&["-l"], "x y\n", "1\n");
wc_test(&["-w"], "x y\n", "2\n");
wc_test(&["-c"], "x y\n", "4 (stdin)\n");
wc_test(&["-l"], "x y\n", "1 (stdin)\n");
wc_test(&["-w"], "x y\n", "2 (stdin)\n");
}
16 changes: 6 additions & 10 deletions text/wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Args {
#[arg(short = 'm', long)]
chars: bool,

/// Count number of lines in each file
/// Count number of words in each file
#[arg(short, long)]
words: bool,

Expand Down Expand Up @@ -106,15 +106,11 @@ fn build_display_str(args: &Args, count: &CountInfo, filename: &OsStr) -> String
output.push_str(&numstr);
}

let multi_file = args.files.len() > 1;
if multi_file {
output.push(' ');

if filename.is_empty() {
output.push_str("(stdin)");
} else {
output.push_str(filename.to_string_lossy().as_ref());
}
output.push(' ');
if filename.is_empty() {
output.push_str("(stdin)");
} else {
output.push_str(filename.to_string_lossy().as_ref());
}

output
Expand Down