search_query_parser.py 913 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. # License: GPLv3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
  3. from . import BaseTest
  4. class TestSQP(BaseTest):
  5. def test_search_query_parser(self):
  6. from kitty.search_query_parser import ParseException, search
  7. locations = 'id'
  8. universal_set = {1, 2, 3, 4, 5}
  9. def get_matches(location, query, candidates):
  10. return {x for x in candidates if query == str(x)}
  11. def t(q, expected=set()):
  12. actual = search(q, locations, universal_set, get_matches)
  13. self.ae(actual, expected)
  14. t('id:1', {1})
  15. t('id:"1"', {1})
  16. t('id:1 and id:1', {1})
  17. t('id:1 or id:2', {1, 2})
  18. t('id:1 and id:2')
  19. t('not id:1', universal_set - {1})
  20. t('(id:1 or id:2) and id:1', {1})
  21. self.assertRaises(ParseException, t, '1')
  22. self.assertRaises(ParseException, t, '"id:1"')