(t *testing.T)
| 238 | } |
| 239 | |
| 240 | func 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 | |
| 285 | func TestFormatErrorList(t *testing.T) { |
| 286 | tests := []struct { |
nothing calls this directly
no test coverage detected