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

Function TestCompletion

backend/plugin/parser/tsql/completion_test.go:37–107  ·  view source on GitHub ↗

TestCompletion tests the Transact-SQL auto-completion, all the test cases are stored in the file. - Description: The description of the test case. - Input: The input statement with the caret position marked by "|". - Want: The expected completion candidates. Our Test suite will determine the car

(t *testing.T)

Source from the content-addressed store, hash-verified

35// Our Test suite will determine the caret position - line(0-based) and column(1-based) by the position of the "|", actually,
36// this caret position is as same as the position in the monaco-editor(LSP?).
37func TestCompletion(t *testing.T) {
38 tests := []candidatesTest{}
39
40 const (
41 record = false
42 )
43 var (
44 filepath = "test-data/test_completion.yaml"
45 )
46
47 a := require.New(t)
48 yamlFile, err := os.Open(filepath)
49 a.NoError(err)
50
51 byteValue, err := io.ReadAll(yamlFile)
52 a.NoError(yamlFile.Close())
53 a.NoError(err)
54 a.NoError(yaml.Unmarshal(byteValue, &tests))
55
56 for i, t := range tests {
57 statement, caretLine, caretPosition := getCaretPosition(t.Input)
58 getter, lister := buildMockDatabaseMetadataGetterLister()
59 results, err := Completion(context.Background(), base.CompletionContext{
60 Scene: base.SceneTypeAll,
61 DefaultDatabase: "Company",
62 Metadata: getter,
63 ListDatabaseNames: lister,
64 }, statement, caretLine, caretPosition)
65 a.NoErrorf(err, "Case %02d: %s", i, t.Description)
66 var filteredResult []base.Candidate
67 for _, r := range results {
68 switch r.Type {
69 case base.CandidateTypeKeyword, base.CandidateTypeFunction:
70 continue
71 default:
72 filteredResult = append(filteredResult, r)
73 }
74 }
75 slices.SortFunc(filteredResult, func(a, b base.Candidate) int {
76 if a.Type != b.Type {
77 if a.Type < b.Type {
78 return -1
79 }
80 return 1
81 }
82 if a.Text != b.Text {
83 if a.Text < b.Text {
84 return -1
85 }
86 return 1
87 }
88 if a.Definition < b.Definition {
89 return -1
90 }
91 if a.Definition > b.Definition {
92 return 1
93 }
94 return 0

Callers

nothing calls this directly

Calls 7

RecordFunction · 0.92
UnmarshalMethod · 0.80
getCaretPositionFunction · 0.70
CompletionFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected