summaryrefslogtreecommitdiffstats
path: root/tests/test_pgspecial.py
blob: eaeaf12fd03336d05f8be565033f03b4f7633beb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pytest
from pgcli.packages.sqlcompletion import (
    suggest_type,
    Special,
    Database,
    Schema,
    Table,
    View,
    Function,
    Datatype,
)


def test_slash_suggests_special():
    suggestions = suggest_type("\\", "\\")
    assert set(suggestions) == set([Special()])


def test_slash_d_suggests_special():
    suggestions = suggest_type("\\d", "\\d")
    assert set(suggestions) == set([Special()])


def test_dn_suggests_schemata():
    suggestions = suggest_type("\\dn ", "\\dn ")
    assert suggestions == (Schema(),)

    suggestions = suggest_type("\\dn xxx", "\\dn xxx")
    assert suggestions == (Schema(),)


def test_d_suggests_tables_views_and_schemas():
    suggestions = suggest_type("\d ", "\d ")
    assert set(suggestions) == set([Schema(), Table(schema=None), View(schema=None)])

    suggestions = suggest_type("\d xxx", "\d xxx")
    assert set(suggestions) == set([Schema(), Table(schema=None), View(schema=None)])


def test_d_dot_suggests_schema_qualified_tables_or_views():
    suggestions = suggest_type("\d myschema.", "\d myschema.")
    assert set(suggestions) == set([Table(schema="myschema"), View(schema="myschema")])

    suggestions = suggest_type("\d myschema.xxx", "\d myschema.xxx")
    assert set(suggestions) == set([Table(schema="myschema"), View(schema="myschema")])


def test_df_suggests_schema_or_function():
    suggestions = suggest_type("\\df xxx", "\\df xxx")
    assert set(suggestions) == set([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) == set([Schema(), Datatype(schema=None)])


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


@pytest.mark.parametrize("command", ["\\c ", "\\connect "])
def test_c_suggests_databases(command):
    suggestions = suggest_type(command, command)
    assert suggestions == (Database(),)