2022-04-12 16:56:25 +03:00
|
|
|
#!/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):
|
2022-04-12 17:01:56 +03:00
|
|
|
from kitty.search_query_parser import search, ParseException
|
2022-04-12 16:56:25 +03:00
|
|
|
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)}
|
|
|
|
|
2022-04-12 17:01:56 +03:00
|
|
|
def t(q, expected=set()):
|
2022-04-12 16:56:25 +03:00
|
|
|
actual = search(q, locations, universal_set, get_matches)
|
|
|
|
self.ae(actual, expected)
|
|
|
|
|
|
|
|
t('id:1', {1})
|
2022-04-12 17:01:56 +03:00
|
|
|
t('id:"1"', {1})
|
2022-04-12 16:56:25 +03:00
|
|
|
t('id:1 and id:1', {1})
|
|
|
|
t('id:1 or id:2', {1, 2})
|
2022-04-12 17:01:56 +03:00
|
|
|
t('id:1 and id:2')
|
2022-04-12 16:56:25 +03:00
|
|
|
t('not id:1', universal_set - {1})
|
|
|
|
t('(id:1 or id:2) and id:1', {1})
|
2022-04-12 17:01:56 +03:00
|
|
|
self.assertRaises(ParseException, t, '1')
|
|
|
|
self.assertRaises(ParseException, t, '"id:1"')
|