diff options
author | Owen Stephens <owen@owenstephens.co.uk> | 2017-04-23 12:13:06 +0100 |
---|---|---|
committer | Owen Stephens <owen@owenstephens.co.uk> | 2017-04-26 01:10:57 +0100 |
commit | 3d560baf6c84070da60fb0552722bb86db78a90e (patch) | |
tree | 98d7992c9aa263a5b1df050d93d5f2619cd30779 /tests | |
parent | 66cd634de462c685cd11d08b56e39289dbdd109e (diff) |
Suggest columns for `ORDER BY` and `DISTINCT` (fixes #685)
Having typed an alias name in an `ORDER BY` or (`SELECT`) `DISTINCT`
clause, the alias was not taken account of, and the completion simply
listed all columns. This change fixes that, and makes the autocompletion
behave the same as in `SELECT` and `WHERE` clauses.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_sqlcompletion.py | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/tests/test_sqlcompletion.py b/tests/test_sqlcompletion.py index a2928df4..c4a7da11 100644 --- a/tests/test_sqlcompletion.py +++ b/tests/test_sqlcompletion.py @@ -4,8 +4,9 @@ from pgcli.packages.sqlcompletion import ( from pgcli.packages.parseutils.tables import TableReference import pytest -# Returns the expected select-clause suggestions for a single-table select def cols_etc(table, schema=None, alias=None, is_function=False, parent=None): + """Returns the expected select-clause suggestions for a single-table + select.""" return set([ Column(table_refs=(TableReference(schema, table, alias, is_function),), qualifiable=True), @@ -213,9 +214,62 @@ def test_truncate_suggests_qualified_tables(): ]) def test_distinct_suggests_cols(text): suggestions = suggest_type(text, text) - assert suggestions ==(Column(table_refs=(), qualifiable=True),) + assert set(suggestions) == set([ + Column(table_refs=(), local_tables=(), qualifiable=True), + Function(schema=None), + Keyword() + ]) +@pytest.mark.parametrize('text, text_before', [ + ( + 'SELECT DISTINCT FROM tbl x JOIN tbl1 y', + 'SELECT DISTINCT' + ), + ( + 'SELECT * FROM tbl x JOIN tbl1 y ORDER BY ', + 'SELECT * FROM tbl x JOIN tbl1 y ORDER BY ' + ) +]) +def test_distinct_and_order_by_suggestions_with_aliases(text, text_before): + suggestions = suggest_type(text, text_before) + assert set(suggestions) == set([ + Column( + table_refs=( + TableReference(None, 'tbl', 'x', False), + TableReference(None, 'tbl1', 'y', False), + ), + local_tables=(), + qualifiable=True + ), + Function(schema=None), + Keyword() + ]) + + +@pytest.mark.parametrize('text, text_before', [ + ( + 'SELECT DISTINCT x. FROM tbl x JOIN tbl1 y', + 'SELECT DISTINCT x.' + ), + ( + 'SELECT * FROM tbl x JOIN tbl1 y ORDER BY x.', + 'SELECT * FROM tbl x JOIN tbl1 y ORDER BY x.' + ) +]) +def test_distinct_and_order_by_suggestions_with_alias_given(text, text_before): + suggestions = suggest_type(text, text_before) + assert set(suggestions) == set([ + Column( + table_refs=(TableReference(None, 'tbl', 'x', False),), + local_tables=(), + qualifiable=False + ), + Table(schema='x'), + View(schema='x'), + Function(schema='x'), + ]) + def test_col_comma_suggests_cols(): suggestions = suggest_type('SELECT a, b, FROM tbl', 'SELECT a, b,') assert set(suggestions) == set([ |