Skip to content

Commit

Permalink
check for empty dawg
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbolz committed Nov 3, 2023
1 parent d49e871 commit dfb0580
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/test/test_tools/test_makeunicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def test_dawg_direct_simple(self):
self.assertEqual(inverse_lookup(packed, inverse, 5), b"zcatnip")
self.assertRaises(KeyError, inverse_lookup, packed, inverse, 12)

def test_forbid_empty_dawg(self):
dawg = Dawg()
self.assertRaises(ValueError, dawg.finish)

@given(char_name_db())
@example([("abc", "a"), ("abd", "b")])
@example(
Expand Down
2 changes: 2 additions & 0 deletions Tools/unicode/dawg.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def insert(self, word, value):
self.previous_word = word

def finish(self):
if not self.data:
raise ValueError("need at least one word in the dawg")
# minimize all unchecked_nodes
self._minimize(0)

Expand Down

0 comments on commit dfb0580

Please sign in to comment.