MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestFormatErrorWithSuggestion

Function TestFormatErrorWithSuggestion

pkg/errors/formatter_test.go:240–283  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

238}
239
240func TestFormatErrorWithSuggestion(t *testing.T) {
241 tests := []struct {
242 name string
243 code ErrorCode
244 message string
245 location models.Location
246 sql string
247 suggestion string
248 wantHint bool
249 }{
250 {
251 name: "custom suggestion",
252 code: ErrCodeExpectedToken,
253 message: "expected FROM",
254 location: models.Location{Line: 1, Column: 10},
255 sql: "SELECT * FORM users",
256 suggestion: "Use FROM instead of FORM",
257 wantHint: true,
258 },
259 {
260 name: "auto-generated suggestion",
261 code: ErrCodeUnterminatedString,
262 message: "unterminated string",
263 location: models.Location{Line: 1, Column: 30},
264 sql: "SELECT * FROM users WHERE name = 'John",
265 suggestion: "",
266 wantHint: true,
267 },
268 }
269
270 for _, tt := range tests {
271 t.Run(tt.name, func(t *testing.T) {
272 got := FormatErrorWithSuggestion(tt.code, tt.message, tt.location, tt.sql, 1, tt.suggestion)
273
274 if tt.wantHint && !strings.Contains(got, "Hint:") {
275 t.Errorf("FormatErrorWithSuggestion() should contain hint\nGot:\n%s", got)
276 }
277
278 if tt.suggestion != "" && !strings.Contains(got, tt.suggestion) {
279 t.Errorf("FormatErrorWithSuggestion() should contain custom suggestion\nGot:\n%s", got)
280 }
281 })
282 }
283}
284
285func TestFormatErrorList(t *testing.T) {
286 tests := []struct {

Callers

nothing calls this directly

Calls 3

RunMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected