diff --git a/fixit/wordcount.py b/fixit/wordcount.py index 7f87b2c..d7d5881 100644 --- a/fixit/wordcount.py +++ b/fixit/wordcount.py @@ -12,7 +12,7 @@ def count_words(text: str) -> int: count_words("hello world") returns 2. count_words("one two three") returns 3. """ - return len(re.split(r'\s+', text.strip())) + return len(text.split()) def count_lines(text: str) -> int: @@ -22,7 +22,7 @@ def count_lines(text: str) -> int: count_lines("hello\nworld") returns 2. count_lines("hello") returns 1. """ - return len(text.split("\n")) + return len(text.splitlines()) def count_chars(text: str) -> int: diff --git a/tests/test_textutils.py b/tests/test_textutils.py index 9ebd1a7..1d86d07 100644 --- a/tests/test_textutils.py +++ b/tests/test_textutils.py @@ -1,4 +1,3 @@ -import pytest from fixit.textutils import is_palindrome, reverse_words, slugify @@ -6,7 +5,6 @@ def test_simple_palindrome(): assert is_palindrome("level") -@pytest.mark.xfail(reason="Known bug: case-sensitive") def test_palindrome_ignores_case(): assert is_palindrome("Level") diff --git a/tests/test_wordcount.py b/tests/test_wordcount.py index 5db75ec..6a7afa0 100644 --- a/tests/test_wordcount.py +++ b/tests/test_wordcount.py @@ -10,16 +10,22 @@ def test_count_words_extra_spaces(): assert count_words("hello world") == 2 -@pytest.mark.xfail(reason="Known bug: empty string returns 1") def test_count_words_empty(): assert count_words("") == 0 -@pytest.mark.xfail(reason="Known bug: trailing newline adds a phantom line") def test_count_lines_trailing_newline(): assert count_lines("a\nb\n") == 2 +def test_count_lines_empty(): + assert count_lines("") == 0 + + +def test_count_words_whitespace_only(): + assert count_words(" \t\n ") == 0 + + def test_count_chars(): assert count_chars("abc") == 3