From 6e9663d0e05f8ceb41fe1f08c93febd2185959d2 Mon Sep 17 00:00:00 2001 From: Khushleen Kaur Date: Mon, 12 Oct 2026 22:55:19 +0530 Subject: [PATCH] fix: handle whitespace correctly in word count --- fixit/wordcount.py | 3 ++- tests/test_wordcount.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fixit/wordcount.py b/fixit/wordcount.py index dca0f03..48730d1 100644 --- a/fixit/wordcount.py +++ b/fixit/wordcount.py @@ -1,9 +1,10 @@ +import re """Word, line and character counting.""" def count_words(text: str) -> int: """Return the number of words in text.""" - return len(text.split(" ")) + return len(re.split(r'\s+',text.strip())) def count_lines(text: str) -> int: diff --git a/tests/test_wordcount.py b/tests/test_wordcount.py index 5e3a2f9..d6a9607 100644 --- a/tests/test_wordcount.py +++ b/tests/test_wordcount.py @@ -6,7 +6,6 @@ def test_count_words_simple(): assert count_words("hello world") == 2 -@pytest.mark.xfail(reason="Known bug: multiple spaces are counted as words") def test_count_words_extra_spaces(): assert count_words("hello world") == 2