Skip to content

Commit

Permalink
Fix regex to validate a referance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Llewellynvdm committed Dec 11, 2023
1 parent 8e28a9f commit 37ab058
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="getbible",
version="1.1.0",
version="1.1.1",
author="Llewellyn van der Merwe",
author_email="[email protected]",
description="A Python package to retrieving Bible references with ease.",
Expand Down
2 changes: 1 addition & 1 deletion src/getbible/getbible_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BookReference:
class GetBibleReference:
def __init__(self):
self.__get_book = GetBibleBookNumber()
self.__pattern = re.compile(r'^[\w\s,:-]{1,50}$', re.UNICODE)
self.__pattern = re.compile(r'[\w\s,:-]{1,50}', re.UNICODE)
self.__cache = {}
self.__cache_limit = 5000

Expand Down
12 changes: 11 additions & 1 deletion tests/test_getbible_book_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def test_valid_1_john(self):
actual_result = self.get_book.number('1 John', 'kjv')
self.assertEqual(actual_result, expected_result, "Failed to find '1 John' in 'kjv' translation")

def test_valid_genesis(self):
expected_result = 1
actual_result = self.get_book.number('בְּרֵאשִׁית', 'codex')
self.assertEqual(actual_result, expected_result, "Failed to find 'בְּרֵאשִׁית' in 'codex' translation")

def test_valid_1_samuel(self):
expected_result = 9
actual_result = self.get_book.number("שמא",'aleppo')
self.assertEqual(actual_result, expected_result, "Failed to find 'שמא' in 'aleppo' translation")

def test_valid_1_peter_ch(self):
expected_result = 60
actual_result = self.get_book.number('彼得前书', 'cns')
Expand All @@ -47,7 +57,7 @@ def test_valid_first_john(self):
actual_result = self.get_book.number('First John', 'kjv')
self.assertEqual(actual_result, expected_result, "Failed to find 'First John' in 'kjv' translation")

def test_valid_1_john(self):
def test_valid_one_john(self):
expected_result = 62
actual_result = self.get_book.number('62', 'kjv')
self.assertEqual(actual_result, expected_result, "Failed to find '62' in 'kjv' translation")
Expand Down
28 changes: 19 additions & 9 deletions tests/test_getbible_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,35 @@ def setUp(self):
self.get = GetBibleReference()

def test_valid_reference(self):
expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='Gen 1:2-7')
actual_result = self.get.ref('Gen 1:2-7', 'kjv')
expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='Gen 1:2-7')
self.assertEqual(actual_result, expected_result, "Failed to find 'Gen 1:2-7' book reference.")

def test_valid_genesis_hebrew(self):
actual_result = self.get.ref('בְּרֵאשִׁית 1:23-30', 'codex')
expected_result = BookReference(book=1, chapter=1, verses=[23, 24, 25, 26, 27, 28, 29, 30], reference='בְּרֵאשִׁית 1:23-30')
self.assertEqual(actual_result, expected_result, "Failed to find 'בְּרֵאשִׁית 1:23-30' in 'codex' translation")

def test_valid_reference_ch(self):
expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='创世记1:2-7')
actual_result = self.get.ref('创世记1:2-7', 'cns')
expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='创世记1:2-7')
self.assertEqual(actual_result, expected_result, "Failed to find '创世记1:2-7' book reference")

def test_valid_reference_missing_verse_ch(self):
expected_result = BookReference(book=1, chapter=1, verses=[2], reference='创记 1:2-')
actual_result = self.get.ref('创记 1:2-', 'cus')
expected_result = BookReference(book=1, chapter=1, verses=[2], reference='创记 1:2-')
self.assertEqual(actual_result, expected_result, "Failed to find '创记 1:2-' book reference")

def test_valid_reference_missing_verse__ch(self):
expected_result = BookReference(book=1, chapter=1, verses=[5], reference='创记 1:-5')
actual_result = self.get.ref('创记 1:-5', 'cus')
expected_result = BookReference(book=1, chapter=1, verses=[5], reference='创记 1:-5')
self.assertEqual(actual_result, expected_result, "Failed to find '创记 1:-5' book reference")

def test_valid_revelation_arabic(self):
actual_result = self.get.ref('رؤ 22:19')
expected_result = BookReference(book=66, chapter=22, verses=[19], reference='رؤ 22:19')
self.assertEqual(actual_result, expected_result, "Failed to find 'رؤ 22:19' in 'arabicsv' translation")

def test_valid_reference_ch_no_trans(self):
actual_result = self.get.ref('创世记')
expected_result = BookReference(book=1, chapter=1, verses=[1], reference='创世记')
Expand All @@ -38,8 +48,8 @@ def test_valid_reference_ch_no__trans(self):
self.assertEqual(actual_result, expected_result, "Failed to find '创记 1:1' book reference")

def test_valid_1_john(self):
expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1 John')
actual_result = self.get.ref('1 John', 'kjv')
expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1 John')
self.assertEqual(actual_result, expected_result, "Failed to find '1 John 1:1' book reference")

def test_valid_1_peter_ch(self):
Expand All @@ -48,18 +58,18 @@ def test_valid_1_peter_ch(self):
self.assertEqual(actual_result, expected_result, "Failed to find '彼得前书 1:1' book reference")

def test_valid_first_john(self):
expected_result = BookReference(book=62, chapter=3, verses=[16, 19, 20, 21], reference='First John 3:16,19-21')
actual_result = self.get.ref('First John 3:16,19-21', 'kjv')
expected_result = BookReference(book=62, chapter=3, verses=[16, 19, 20, 21], reference='First John 3:16,19-21')
self.assertEqual(actual_result, expected_result, "Failed to find 'First John 1:2-7' book reference.")

def test_valid_mismatch_nospace_call(self):
expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1Jn')
actual_result = self.get.ref('1Jn', 'aov')
expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1Jn')
self.assertEqual(actual_result, expected_result, "Failed to find '1Jn 1:1' book reference.")

def test_valid_mismatch_call(self):
expected_result = BookReference(book=62, chapter=5, verses=[1], reference='1 John 5')
actual_result = self.get.ref('1 John 5', 'aov')
expected_result = BookReference(book=62, chapter=5, verses=[1], reference='1 John 5')
self.assertEqual(actual_result, expected_result, "Failed to find '1 John 5:1' book reference.")

def test_invalid_reference(self):
Expand All @@ -69,8 +79,8 @@ def test_invalid_reference(self):
self.assertEqual(str(actual.exception), expected_exception)

def test_nonexistent_translation(self):
expected_result = BookReference(book=1, chapter=1, verses=[1], reference='Gen')
actual_result = self.get.ref('Gen', 'nonexistent')
expected_result = BookReference(book=1, chapter=1, verses=[1], reference='Gen')
self.assertEqual(actual_result, expected_result, "Failed to find 'Gen 1:1' book reference.")


Expand Down

0 comments on commit 37ab058

Please sign in to comment.