Beispiel #1
0
    def test_basic(self):
        p = self.Preql()
        state = p._interp.state

        assert "item" in autocomplete(state, "func d(){ [1]{")
        assert "item" in autocomplete(state, "func d(){ [1][")
        assert "item" not in autocomplete(state, "func d(){ [1]")

        res = autocomplete(state, """
        func x(param1) {
            hello = "b"
        """)
        assert "hello" in res, res.keys()

        res = autocomplete(state, """
        func x(param1) {
            hello = "b
        """)

        res = autocomplete(state, """
        func x(param1) {
            hello = [1] {item, item+2}
        """)
        assert "hello" in res, res.keys()

        res = autocomplete(state, """a = [1,2,3]{.""")
        assert res == {}

        res = autocomplete(state, """table a""")
        assert all(isinstance(v, tuple) for v in res.values())
Beispiel #2
0
    def do_complete(self, code, cursor_pos):
        context, fragment = last_word(code[:cursor_pos])

        all_vars = autocomplete(pql._interp.state, context)
        matches = [f'{k}' for k in all_vars if k.startswith(fragment)]

        return {
            'status': 'ok',
            'matches': matches,
            'cursor_start': cursor_pos - len(fragment),
            'cursor_end': cursor_pos,
            'metadata': {},
        }
Beispiel #3
0
def progressive_test(state, s, test_partial=False):
    total = 1
    start = time.time()

    s,d = _parse_autocomplete_requirements(s)
    for i in range(1, len(s)):
        ps = s[:i]
        if i in d or test_partial:
            names = autocomplete(state, ps)
            total += 1
            if i in d:
                # if d[i] not in names:
                #     breakpoint()
                #     names = autocomplete(state, ps)

                assert d[i] in names, (i, d[i])

    duration = time.time() - start
    test_log.info(f"Total {total} autocompletions in {duration:.2f} seconds, or {1000*duration/total:.2f} ms per autocomplete")