File: search_query_parser.py

package info (click to toggle)
kitty 0.44.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,540 kB
  • sloc: ansic: 84,052; python: 57,643; objc: 5,365; sh: 1,319; xml: 364; makefile: 144; javascript: 78
file content (30 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/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 ParseException, 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=set()):
            actual = search(q, locations, universal_set, get_matches)
            self.ae(actual, expected)

        t('id:1', {1})
        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')
        t('not id:1', universal_set - {1})
        t('(id:1 or id:2) and id:1', {1})
        self.assertRaises(ParseException, t, '1')
        self.assertRaises(ParseException, t, '"id:1"')