Skip to content

Commit

Permalink
Scripture range parser no error on empty string (#110)
Browse files Browse the repository at this point in the history
* Fixes issue when specifying PS2 or PS3

* Check for empty string
  • Loading branch information
Enkidu93 authored Jul 16, 2024
1 parent 9a0b3fc commit 7d85f16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 4 additions & 1 deletion machine/scripture/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ def parse_selection(selection: str, versification: Versification) -> Dict[int, L
def get_chapters(
selections: Union[str, List[str]], versification: Versification = ORIGINAL_VERSIFICATION
) -> Dict[int, List[int]]:
chapters = {}
if isinstance(selections, str):
selections = selections.strip()

if len(selections) == 0:
return chapters

delimiter = ";"
if ";" in selections:
delimiter = ";"
Expand All @@ -117,7 +121,6 @@ def get_chapters(

selections = selections.split(delimiter)

chapters = {}
for selection in selections:
selection = selection.strip()

Expand Down
5 changes: 1 addition & 4 deletions tests/scripture/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_get_chapters() -> None:
test_bible[66] = test_chapters_rev
assert get_chapters("NT;-MAT3-5,17;-REV21,22") == test_bible
assert get_chapters("MAT-JHN;-MAT-LUK") == {43: []}
assert get_chapters("") == {}

with raises(ValueError):
# wrong order of chapters
Expand Down Expand Up @@ -111,10 +112,6 @@ def test_get_chapters() -> None:
# invalid book/length of book name in subtraction
get_chapters("-MAT-FLUM")

with raises(ValueError):
# empty string
get_chapters("")

with raises(ValueError):
# invalid name
get_chapters("ABC")
Expand Down

0 comments on commit 7d85f16

Please sign in to comment.