summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDarik Gamble <darik.gamble@gmail.com>2015-03-01 16:48:46 -0500
committerDarik Gamble <darik.gamble@gmail.com>2015-03-06 08:26:41 -0500
commit2b85eaecb0512af10548a4f275c26ce8853116dd (patch)
treec94ad5d4cbbe8d2966fa3052e6b635a1a084d346 /tests
parent0e2e569711d9869236665b7660d526ce895e5020 (diff)
Better handle schema-qualified word_before_cursor
Previously, if the current word contained a period, `suggest_type` would parse text to the right of the period as `word_before_cursor`, so that characters to the left of the period were parsed as the final token. Then `suggest_based_on_last_token` would generate suggestions under the generic catch-all `elif token_v.endswith('.')`. This means that, for example, `DROP TABLE schema_name.<TAB>` and `DROP FUNCTION schema_name.<TAB>` would each suggest both tables and functions from schema_name. This commit changes this behavior to include schema qualifications as part of word_before_cursor, so that `suggest_based_on_last_token` operates on the actual preceding token, not just the schema name. This allows each token value to handle schema qualifications differently, and now `DROP TABLE schema_name.<TAB>` suggests only tables from schema_name, and the corresponding `DROP FUNCTION` command only functions.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_smart_completion_multiple_schemata.py4
-rw-r--r--tests/test_sqlcompletion.py6
2 files changed, 7 insertions, 3 deletions
diff --git a/tests/test_smart_completion_multiple_schemata.py b/tests/test_smart_completion_multiple_schemata.py
index 66653f62..6190d774 100644
--- a/tests/test_smart_completion_multiple_schemata.py
+++ b/tests/test_smart_completion_multiple_schemata.py
@@ -145,9 +145,7 @@ def test_suggested_table_names_with_schema_dot(completer, complete_event):
assert set(result) == set([
Completion(text='users', start_position=0),
Completion(text='products', start_position=0),
- Completion(text='shipments', start_position=0),
- Completion(text='func3', start_position=0),
- Completion(text='func4', start_position=0)])
+ Completion(text='shipments', start_position=0)])
def test_suggested_column_names_with_qualified_alias(completer, complete_event):
"""
diff --git a/tests/test_sqlcompletion.py b/tests/test_sqlcompletion.py
index 1e3ae66b..063bf28c 100644
--- a/tests/test_sqlcompletion.py
+++ b/tests/test_sqlcompletion.py
@@ -253,3 +253,9 @@ def test_specials_not_included_after_initial_token():
'create table foo (dt d')
assert sorted_dicts(suggestions) == sorted_dicts([{'type': 'keyword'}])
+
+
+def test_drop_schema_qualified_table_suggests_only_tables():
+ text = 'DROP TABLE schema_name.table_name'
+ suggestions = suggest_type(text, text)
+ assert suggestions == [{'type': 'table', 'schema': 'schema_name'}] \ No newline at end of file