Commits

Mirth Hickford committed 429b1d2

Document has_keys_with_prefix in readme

Comments (0)

Files changed (2)

     >>> trie.prefixes(u'foobarz')
     [u'foo', u'foobar']
 
+Test whether some key begins with a given prefix::
+
+    >>> trie.has_keys_with_prefix(u'fo')
+    True
+    >>> trie.has_keys_with_prefix(u'go')
+    False
+
 Find all keys from this trie that starts with a given prefix::
 
     >> trie.keys(u'fo')
 ----------------------
 
 * Mikhail Korobov <kmike84@gmail.com>
+* `Matt Hickford <https://github.com/matt-hickford>`_
 
 This module is based on `marisa-trie`_ C++ library by
 Susumu Yata & contributors.

tests/test_trie.py

         assert trie.keys(prefix) == list(trie.iterkeys(prefix))
 
 def test_has_keys_with_prefix():
-    keys = ['foo', 'f', 'foobar', 'bar']
-    trie = marisa_trie.Trie(keys)
-    assert trie.has_keys_with_prefix('f')
-    assert trie.has_keys_with_prefix('foobar')
-    assert not trie.has_keys_with_prefix('la')
+    empty_trie = marisa_trie.Trie()
+    assert empty_trie.has_keys_with_prefix('') == False
+    assert empty_trie.has_keys_with_prefix('ab') == False
+
+    fruit_trie = marisa_trie.Trie(['apple', 'pear', 'peach'])
+    assert fruit_trie.has_keys_with_prefix('') == True
+    assert fruit_trie.has_keys_with_prefix('a') == True
+    assert fruit_trie.has_keys_with_prefix('pe') == True
+    assert fruit_trie.has_keys_with_prefix('x') == False
+
 
 def test_invalid_file():
     try: