diff options
author | Joakim Koljonen <koljonen@outlook.com> | 2016-09-12 23:28:38 +0200 |
---|---|---|
committer | Joakim Koljonen <koljonen@outlook.com> | 2016-09-12 23:48:22 +0200 |
commit | 514b594909cfef367a33c8c18439bced9c833270 (patch) | |
tree | caab2a4d8cb55cde498d8673ae7c680541b5ce08 | |
parent | f76a7b0a585ec91e8010f806d69f64374960bcc0 (diff) |
Fix crash bug with leading parenthesis
-rw-r--r-- | pgcli/packages/sqlcompletion.py | 2 | ||||
-rw-r--r-- | tests/test_sqlcompletion.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/pgcli/packages/sqlcompletion.py b/pgcli/packages/sqlcompletion.py index 5fe37067..94edb3a8 100644 --- a/pgcli/packages/sqlcompletion.py +++ b/pgcli/packages/sqlcompletion.py @@ -335,7 +335,7 @@ def suggest_based_on_last_token(token, stmt): if last_word(stmt.text_before_cursor, 'all_punctuations').startswith('('): return (Keyword(),) - prev_prev_tok = p.token_prev(p.token_index(prev_tok))[1] + prev_prev_tok = prev_tok and p.token_prev(p.token_index(prev_tok))[1] if prev_prev_tok and prev_prev_tok.normalized == 'INTO': return (Column(table_refs=stmt.get_tables('insert')),) # We're probably in a function argument list diff --git a/tests/test_sqlcompletion.py b/tests/test_sqlcompletion.py index d9fffef5..68c9e3de 100644 --- a/tests/test_sqlcompletion.py +++ b/tests/test_sqlcompletion.py @@ -716,6 +716,14 @@ def test_select_suggests_fields_from_function(): @pytest.mark.parametrize('sql', [ + '(', +]) +def test_leading_parenthesis(sql): + # No assertion for now; just make sure it doesn't crash + suggest_type(sql, sql) + + +@pytest.mark.parametrize('sql', [ 'select * from "', 'select * from "foo', ]) |