-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83c97bc
commit 2a1b7ad
Showing
2 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# Usage: py.test tests | ||
|
||
import sys | ||
import os | ||
|
||
from keyvi.compiler import CompletionDictionaryCompiler | ||
|
||
root = os.path.dirname(os.path.abspath(__file__)) | ||
sys.path.append(os.path.join(root, "../")) | ||
from test_tools import tmp_dictionary | ||
|
||
|
||
def test_prefix_simple(): | ||
c = CompletionDictionaryCompiler({"memory_limit_mb": "10"}) | ||
c.Add("eric", 33) | ||
c.Add("jeff", 33) | ||
c.Add("eric bla", 233) | ||
c.Add("eric blu", 113) | ||
c.Add("eric ble", 413) | ||
c.Add("eric blx", 223) | ||
c.Add("eric bllllx", 193) | ||
c.Add("eric bxxxx", 23) | ||
c.Add("eric boox", 143) | ||
with tmp_dictionary(c, "completion.kv") as d: | ||
assert [m.matched_string for m in d.complete_prefix("eric")] == [ | ||
"eric", | ||
"eric ble", | ||
"eric bla", | ||
"eric blx", | ||
"eric bllllx", | ||
"eric blu", | ||
"eric boox", | ||
"eric bxxxx", | ||
] | ||
assert [m.matched_string for m in d.complete_prefix("eric", 2)] == [ | ||
"eric", | ||
"eric ble", | ||
] | ||
|
||
def my_filter(m): | ||
return m.matched_string.endswith("x"), 40 | ||
|
||
assert [m.matched_string for m in d.complete_prefix("eric", my_filter)] == [ | ||
"eric blx", | ||
"eric bllllx", | ||
"eric boox", | ||
] | ||
# same with lambda, not working yet: assert [m.matched_string for m in d.complete_prefix("eric", lambda m: (m.matched_string.endswith('x'), 40))] == ['eric blx', 'eric bllllx', 'eric boox'] |