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

Function TestTiDBParserError

backend/plugin/parser/tidb/tidb_test.go:130–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func TestTiDBParserError(t *testing.T) {
131 tests := []struct {
132 statement string
133 expectedLine int32
134 expectedCol int32
135 expectedMsg string
136 }{
137 {
138 statement: "SELECT 𝄞𝄞hello TO world;",
139 expectedLine: 1,
140 expectedCol: 23,
141 expectedMsg: `line 1 column 23 near "TO world;" `,
142 },
143 {
144 statement: "SELECT 1;\nSELEC 5;\nSELECT 6;",
145 expectedLine: 2,
146 expectedCol: 6,
147 expectedMsg: "line 2 column 6 near \"SELEC 5;\nSELECT 6;\" ",
148 },
149 {
150 statement: "SELECT 1;\n SELEC 5;\nSELECT 6;",
151 expectedLine: 2,
152 expectedCol: 9,
153 expectedMsg: "line 2 column 9 near \"SELEC 5;\nSELECT 6;\" ",
154 },
155 }
156
157 for _, test := range tests {
158 _, err := ParseTiDB(test.statement, "", "")
159 require.Error(t, err)
160 syntaxErr, ok := err.(*base.SyntaxError)
161 require.True(t, ok)
162 require.Equal(t, test.expectedLine, syntaxErr.Position.GetLine())
163 require.Equal(t, test.expectedCol, syntaxErr.Position.GetColumn())
164 require.Equal(t, test.expectedMsg, syntaxErr.Message)
165 }
166}
167
168func TestParseTiDBForSyntaxCheckError(t *testing.T) {
169 tests := []struct {

Callers

nothing calls this directly

Calls 5

ParseTiDBFunction · 0.85
EqualMethod · 0.65
ErrorMethod · 0.45
GetLineMethod · 0.45
GetColumnMethod · 0.45

Tested by

no test coverage detected