diff --git a/src/tally/__init__.py b/src/tally/__init__.py index 37248b7..719fdb5 100644 --- a/src/tally/__init__.py +++ b/src/tally/__init__.py @@ -33,3 +33,8 @@ def summary(text): word_label = "word" if words == 1 else "words" character_label = "character" if characters == 1 else "characters" return f"{words} {word_label}, {characters} {character_label}" + + +def line_count(text): + """Return how many lines *text* holds.""" + return len(text.split("\n")) diff --git a/tests/test_tally.py b/tests/test_tally.py index a209af6..35b9797 100644 --- a/tests/test_tally.py +++ b/tests/test_tally.py @@ -34,5 +34,10 @@ def test_summary_uses_singulars(self): self.assertEqual(tally.summary("a"), "1 word, 1 character") +class LineCountTests(unittest.TestCase): + def test_counts_lines(self): + self.assertEqual(tally.line_count("one\ntwo"), 2) + + if __name__ == "__main__": unittest.main()