-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathparser_ir_error_test.go
More file actions
42 lines (34 loc) · 1.34 KB
/
parser_ir_error_test.go
File metadata and controls
42 lines (34 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// parser_ir_error_test.go verifies structured error reporting from ParseSQL.
package postgresparser
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestIR_ErrorHandling checks a single syntax error includes line/column info.
func TestIR_ErrorHandling(t *testing.T) {
badSQL := `SELECT FROM WHERE broken = true`
_, err := ParseSQL(badSQL)
require.Error(t, err, "expected parse error")
perr, ok := err.(*ParseErrors)
require.True(t, ok, "expected ParseErrors type, got %T", err)
require.NotEmpty(t, perr.Errors, "expected at least one syntax error entry")
first := perr.Errors[0]
assert.Greater(t, first.Line, 0, "expected valid line number")
assert.GreaterOrEqual(t, first.Column, 0, "expected valid column number")
assert.NotEmpty(t, first.Message, "expected error message")
}
// TestIR_ErrorHandlingMultiple verifies aggregated errors still expose line info.
func TestIR_ErrorHandlingMultiple(t *testing.T) {
badSQL := `
SELECT *
FROM
UNION
SELECT`
_, err := ParseSQL(badSQL)
require.Error(t, err, "expected parse error")
perr, ok := err.(*ParseErrors)
require.True(t, ok, "expected ParseErrors type, got %T", err)
require.NotEmpty(t, perr.Errors, "expected at least one syntax error entry")
assert.Contains(t, perr.Error(), "line", "expected error message to include line information")
}