Skip to content
Closed
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
8 changes: 8 additions & 0 deletions strings/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ def split(string: str, separator: str = " ") -> list:

>>> split(";abbb;;c;", separator=';')
['', 'abbb', '', 'c', '']

>>> split("a--b--c", separator="--")
Traceback (most recent call last):
...
ValueError: separator must be a single character
"""

if len(separator) != 1:
raise ValueError("separator must be a single character")

split_words = []

last_index = 0
Expand Down
12 changes: 12 additions & 0 deletions tests/test_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doctests are good enough. We do not need any tests added here.


from strings.split import split


def test_split_rejects_multi_character_separator():
with pytest.raises(ValueError, match="separator must be a single character"):
split("a--b--c", separator="--")


def test_split_supports_single_character_separator():
assert split("a--b--c", separator="-") == ["a", "", "b", "", "c"]
Loading