MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestCompletion

Function TestCompletion

backend/plugin/parser/pg/completion_test.go:24–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestCompletion(t *testing.T) {
25 tests := []candidatesTest{}
26
27 const (
28 record = false
29 )
30 var (
31 filepath = "test-data/test_completion.yaml"
32 )
33
34 a := require.New(t)
35 yamlFile, err := os.Open(filepath)
36 a.NoError(err)
37
38 byteValue, err := io.ReadAll(yamlFile)
39 a.NoError(yamlFile.Close())
40 a.NoError(err)
41 a.NoError(yaml.Unmarshal(byteValue, &tests))
42
43 for i, t := range tests {
44 text, caretOffset := catchCaret(t.Input)
45 result, err := base.Completion(context.Background(), storepb.Engine_POSTGRES, base.CompletionContext{
46 Scene: base.SceneTypeAll,
47 DefaultDatabase: "db",
48 Metadata: getMetadataForTest,
49 ListDatabaseNames: listDatbaseNamesForTest,
50 }, text, 1, caretOffset)
51 a.NoError(err)
52 var filteredResult []base.Candidate
53 for _, r := range result {
54 switch r.Type {
55 case base.CandidateTypeKeyword, base.CandidateTypeFunction:
56 continue
57 default:
58 filteredResult = append(filteredResult, r)
59 }
60 }
61 slices.SortFunc(filteredResult, func(x, y base.Candidate) int {
62 if x.Type != y.Type {
63 if x.Type < y.Type {
64 return -1
65 }
66 return 1
67 }
68 if x.Text != y.Text {
69 if x.Text < y.Text {
70 return -1
71 }
72 return 1
73 }
74 if x.Definition < y.Definition {
75 return -1
76 } else if x.Definition > y.Definition {
77 return 1
78 }
79 return 0
80 })
81

Callers

nothing calls this directly

Calls 7

CompletionFunction · 0.92
RecordFunction · 0.92
UnmarshalMethod · 0.80
catchCaretFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected