MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestCompletion

Function TestCompletion

backend/plugin/parser/plsql/completion_test.go:25–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

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