# Path: pgcli/packages/sqlcompletion.py
# class SqlStatement:
#     def __init__(self, full_text, text_before_cursor):
#     def is_insert(self):
#     def get_tables(self, scope="full"):
#     def get_previous_token(self, token):
#     def get_identifier_schema(self):
#     def reduce_to_prev_keyword(self, n_skip=0):
# def suggest_type(full_text, text_before_cursor):
# def _strip_named_query(txt):
# def _find_function_body(text):
# def _statement_from_function(full_text, text_before_cursor, statement):
# def _split_multiple_statements(full_text, text_before_cursor, parsed):
# def suggest_special(text):
# def suggest_based_on_last_token(token, stmt):
# def _suggest_expression(token_v, stmt):
# def identifies(id, ref):
# def _allow_join_condition(statement):
# def _allow_join(statement):
# SPECIALS_SUGGESTION = {
#     "dT": Datatype,
#     "df": Function,
#     "dt": Table,
#     "dv": View,
#     "sf": Function,
# }


import pytest
from pgcli.packages.sqlcompletion import (
    suggest_type,
    Special,
    Database,
    Schema,
    Table,
    View,
    Function,
    Datatype,
)
    assert set(suggestions) == {Table(schema="myschema"), View(schema="myschema")}

    suggestions = suggest_type(r"\d myschema.xxx", r"\d myschema.xxx")
    assert set(suggestions) == {Table(schema="myschema"), View(schema="myschema")}


def test_df_suggests_schema_or_function():
    suggestions = suggest_type("\\df xxx", "\\df xxx")
    assert set(suggestions) == {Function(schema=None, usage="special"), Schema()}

    suggestions = suggest_type("\\df myschema.xxx", "\\df myschema.xxx")
    assert suggestions == (Function(schema="myschema", usage="special"),)


def test_leading_whitespace_ok():
    cmd = "\\dn "
    whitespace = "   "
    suggestions = suggest_type(whitespace + cmd, whitespace + cmd)
    assert suggestions == suggest_type(cmd, cmd)


def test_dT_suggests_schema_or_datatypes():
    text = "\\dT "
    suggestions = suggest_type(text, text)
    assert set(suggestions) == {Schema(), Datatype(schema=None)}


def test_schema_qualified_dT_suggests_datatypes():
    text = "\\dT foo."
    suggestions = suggest_type(text, text)

# Path: pgcli/packages/sqlcompletion.py
# class SqlStatement:
#     def __init__(self, full_text, text_before_cursor):
#     def is_insert(self):
#     def get_tables(self, scope="full"):
#     def get_previous_token(self, token):
#     def get_identifier_schema(self):
#     def reduce_to_prev_keyword(self, n_skip=0):
# def suggest_type(full_text, text_before_cursor):
# def _strip_named_query(txt):
# def _find_function_body(text):
# def _statement_from_function(full_text, text_before_cursor, statement):
# def _split_multiple_statements(full_text, text_before_cursor, parsed):
# def suggest_special(text):
# def suggest_based_on_last_token(token, stmt):
# def _suggest_expression(token_v, stmt):
# def identifies(id, ref):
# def _allow_join_condition(statement):
# def _allow_join(statement):
# SPECIALS_SUGGESTION = {
#     "dT": Datatype,
#     "df": Function,
#     "dt": Table,
#     "dv": View,
#     "sf": Function,
# }


# Path: tests/test_pgspecial.py
import pytest
from pgcli.packages.sqlcompletion import (
    suggest_type,
    Special,
    Database,
    Schema,
    Table,
    View,
    Function,
    Datatype,
)

    assert set(suggestions) == {Table(schema="myschema"), View(schema="myschema")}

    suggestions = suggest_type(r"\d myschema.xxx", r"\d myschema.xxx")
    assert set(suggestions) == {Table(schema="myschema"), View(schema="myschema")}


def test_df_suggests_schema_or_function():
    suggestions = suggest_type("\\df xxx", "\\df xxx")
    assert set(suggestions) == {Function(schema=None, usage="special"), Schema()}

    suggestions = suggest_type("\\df myschema.xxx", "\\df myschema.xxx")
    assert suggestions == (Function(schema="myschema", usage="special"),)


def test_leading_whitespace_ok():
    cmd = "\\dn "
    whitespace = "   "
    suggestions = suggest_type(whitespace + cmd, whitespace + cmd)
    assert suggestions == suggest_type(cmd, cmd)


def test_dT_suggests_schema_or_datatypes():
    text = "\\dT "
    suggestions = suggest_type(text, text)
    assert set(suggestions) == {Schema(), Datatype(schema=None)}


def test_schema_qualified_dT_suggests_datatypes():
    text = "\\dT foo."
    suggestions = suggest_type(text, text)

    assert suggestions == (Datatype(schema="foo"),)