| 128 | } |
| 129 | |
| 130 | func 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 | |
| 168 | func TestParseTiDBForSyntaxCheckError(t *testing.T) { |
| 169 | tests := []struct { |