From 52b73b888364d0867563df5506f6433830deffb4 Mon Sep 17 00:00:00 2001 From: Flamur Berisha - Flamxi Date: Tue, 21 Oct 2025 15:00:13 +0200 Subject: [PATCH 1/3] Hotfix of the word counter flag help message --- text/wc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/wc.rs b/text/wc.rs index 807b15fd..69b08cc7 100644 --- a/text/wc.rs +++ b/text/wc.rs @@ -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, From 31e6eb8d92d0c158989959d6a8b4278441b3b4a1 Mon Sep 17 00:00:00 2001 From: Flamur Berisha - Flamxi Date: Tue, 21 Oct 2025 15:05:11 +0200 Subject: [PATCH 2/3] Enhance of the wc tool results, include file name in output Filename will be included in output even in the case of one file input, previosuly that print was inlcuded only in the case of multiple input files traditional 'wc' tool prints the filename in both scenarios --- text/wc.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/text/wc.rs b/text/wc.rs index 69b08cc7..cd4e91fd 100644 --- a/text/wc.rs +++ b/text/wc.rs @@ -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 From 7208dd5b314daeda3786ab2780e83fd9c81dd26b Mon Sep 17 00:00:00 2001 From: Flamur Berisha - Flamxi Date: Tue, 21 Oct 2025 15:11:40 +0200 Subject: [PATCH 3/3] Adapting unit tests to include the input name --- text/tests/wc/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/text/tests/wc/mod.rs b/text/tests/wc/mod.rs index 0b8a20e1..e29eceec 100644 --- a/text/tests/wc/mod.rs +++ b/text/tests/wc/mod.rs @@ -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"); }