diff options
author | Darik Gamble <darik.gamble.spam@gmail.com> | 2015-11-22 16:21:08 -0500 |
---|---|---|
committer | Darik Gamble <darik.gamble.spam@gmail.com> | 2015-11-25 16:17:08 -0500 |
commit | 0f70ccad3124e109c455e9d93bd3f58498e5f72f (patch) | |
tree | 2d4b3cf39ad50ba070dfbe3c48ae774e2c83124f | |
parent | 5dde125d9399296ae91eff7267651af7e70b4063 (diff) |
Add a bunch of tests for multiple joins
-rw-r--r-- | tests/test_parseutils.py | 29 | ||||
-rw-r--r-- | tests/test_smart_completion_public_schema_only.py | 12 | ||||
-rw-r--r-- | tests/test_sqlcompletion.py | 10 |
3 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_parseutils.py b/tests/test_parseutils.py index e73cc03b..6855bae4 100644 --- a/tests/test_parseutils.py +++ b/tests/test_parseutils.py @@ -116,11 +116,40 @@ def test_join_table_schema_qualified(): assert set(tables) == set([('abc', 'def', 'x', False), ('ghi', 'jkl', 'y', False)]) + +def test_incomplete_join_clause(): + sql = '''select a.x, b.y + from abc a join bcd b + on a.id = ''' + tables = extract_tables(sql) + assert tables == ((None, 'abc', 'a', False), + (None, 'bcd', 'b', False)) + + def test_join_as_table(): tables = extract_tables('SELECT * FROM my_table AS m WHERE m.a > 5') assert tables == ((None, 'my_table', 'm', False),) +def test_multiple_joins(): + sql = '''select * from t1 + inner join t2 ON + t1.id = t2.t1_id + inner join t3 ON + t2.id = t3.''' + tables = extract_tables(sql) + assert tables == ( + (None, 't1', None, False), + (None, 't2', None, False), + (None, 't3', None, False)) + + +def test_subselect_tables(): + sql = 'SELECT * FROM (SELECT FROM abc' + tables = extract_tables(sql) + assert tables == ((None, 'abc', None, False),) + + @pytest.mark.parametrize('arg_list', ['', 'arg1', 'arg1, arg2, arg3']) def test_simple_function_as_table(arg_list): tables = extract_tables('SELECT * FROM foo({0})'.format(arg_list)) diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py index 409dabe2..b936cb96 100644 --- a/tests/test_smart_completion_public_schema_only.py +++ b/tests/test_smart_completion_public_schema_only.py @@ -292,6 +292,18 @@ def test_suggested_multiple_column_names_with_dot(completer, complete_event): Completion(text='first_name', start_position=0, display_meta='column'), Completion(text='last_name', start_position=0, display_meta='column')]) + +def test_suggest_columns_after_three_way_join(completer, complete_event): + text = '''SELECT * FROM users u1 + INNER JOIN users u2 ON u1.id = u2.id + INNER JOIN users u3 ON u2.id = u3.''' + position = len(text) + result = completer.get_completions( + Document(text=text, cursor_position=position), complete_event) + assert (Completion(text='id', start_position=0, display_meta='column') in + set(result)) + + def test_suggested_aliases_after_on(completer, complete_event): text = 'SELECT u.name, o.id FROM users u JOIN orders o ON ' position = len('SELECT u.name, o.id FROM users u JOIN orders o ON ') diff --git a/tests/test_sqlcompletion.py b/tests/test_sqlcompletion.py index c58e2472..c8f9f546 100644 --- a/tests/test_sqlcompletion.py +++ b/tests/test_sqlcompletion.py @@ -443,6 +443,16 @@ def test_join_using_suggests_common_columns(col_list): ]) +def test_suggest_columns_after_multiple_joins(): + sql = '''select * from t1 + inner join t2 ON + t1.id = t2.t1_id + inner join t3 ON + t2.id = t3.''' + suggestions = suggest_type(sql, sql) + assert Column(tables=((None, 't3', None, False),)) in set(suggestions) + + def test_2_statements_2nd_current(): suggestions = suggest_type('select * from a; select * from ', 'select * from a; select * from ') |