mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 10:12:17 +02:00
Create a search query parser
This commit is contained in:
27
kitty_tests/search_query_parser.py
Normal file
27
kitty_tests/search_query_parser.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPLv3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
class TestSQP(BaseTest):
|
||||
|
||||
def test_search_query_parser(self):
|
||||
from kitty.search_query_parser import search
|
||||
locations = 'id'
|
||||
universal_set = {1, 2, 3, 4, 5}
|
||||
|
||||
def get_matches(location, query, candidates):
|
||||
return {x for x in candidates if query == str(x)}
|
||||
|
||||
def t(q, expected):
|
||||
actual = search(q, locations, universal_set, get_matches)
|
||||
self.ae(actual, expected)
|
||||
|
||||
t('id:1', {1})
|
||||
t('id:1 and id:1', {1})
|
||||
t('id:1 or id:2', {1, 2})
|
||||
t('id:1 and id:2', set())
|
||||
t('not id:1', universal_set - {1})
|
||||
t('(id:1 or id:2) and id:1', {1})
|
||||
Reference in New Issue
Block a user