Skip to content
Merged
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
4 changes: 2 additions & 2 deletions fixit/wordcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_textutils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import pytest
from fixit.textutils import is_palindrome, reverse_words, slugify


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")

Expand Down
10 changes: 8 additions & 2 deletions tests/test_wordcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down