(t *testing.T)
| 397 | } |
| 398 | |
| 399 | func TestExtractPositionFromError(t *testing.T) { |
| 400 | content := "SELECT *\nFROM users\nWHERE id = 1" |
| 401 | |
| 402 | tests := []struct { |
| 403 | name string |
| 404 | errMsg string |
| 405 | expectedLine int |
| 406 | expectedChar int |
| 407 | }{ |
| 408 | { |
| 409 | name: "line and column pattern", |
| 410 | errMsg: "syntax error at line 2, column 5", |
| 411 | expectedLine: 1, // 0-based |
| 412 | expectedChar: 4, // 0-based |
| 413 | }, |
| 414 | { |
| 415 | name: "line only pattern", |
| 416 | errMsg: "unexpected token at line 3", |
| 417 | expectedLine: 2, // 0-based |
| 418 | expectedChar: 0, |
| 419 | }, |
| 420 | { |
| 421 | name: "bracket pattern", |
| 422 | errMsg: "parse error [2:10]", |
| 423 | expectedLine: 1, |
| 424 | expectedChar: 9, |
| 425 | }, |
| 426 | { |
| 427 | name: "position pattern", |
| 428 | errMsg: "error at position 15", |
| 429 | expectedLine: 1, // "SELECT *\n" = 9 chars, so position 15 is line 1, col 6 |
| 430 | expectedChar: 6, |
| 431 | }, |
| 432 | { |
| 433 | name: "no position info", |
| 434 | errMsg: "some error without position", |
| 435 | expectedLine: 0, |
| 436 | expectedChar: 0, |
| 437 | }, |
| 438 | } |
| 439 | |
| 440 | for _, tt := range tests { |
| 441 | t.Run(tt.name, func(t *testing.T) { |
| 442 | line, char := extractPositionFromError(tt.errMsg, content, 0) |
| 443 | if line != tt.expectedLine { |
| 444 | t.Errorf("line = %d, want %d", line, tt.expectedLine) |
| 445 | } |
| 446 | if char != tt.expectedChar { |
| 447 | t.Errorf("char = %d, want %d", char, tt.expectedChar) |
| 448 | } |
| 449 | }) |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | func TestOffsetToLineColumn(t *testing.T) { |
| 454 | content := "SELECT *\nFROM users\nWHERE id = 1" |
nothing calls this directly
no test coverage detected