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

Function TestFormatErrorWithContextAt

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

Source from the content-addressed store, hash-verified

66}
67
68func TestFormatErrorWithContextAt(t *testing.T) {
69 tests := []struct {
70 name string
71 code ErrorCode
72 message string
73 location models.Location
74 sql string
75 highlightLen int
76 wantContains []string
77 }{
78 {
79 name: "simple error",
80 code: ErrCodeExpectedToken,
81 message: "expected FROM, got FORM",
82 location: models.Location{Line: 1, Column: 10},
83 sql: "SELECT * FORM users",
84 highlightLen: 4,
85 wantContains: []string{
86 "E2002",
87 "expected FROM, got FORM",
88 "line 1, column 10",
89 "^^^^",
90 },
91 },
92 {
93 name: "multi-line SQL",
94 code: ErrCodeUnexpectedToken,
95 message: "unexpected token",
96 location: models.Location{Line: 2, Column: 1},
97 sql: "SELECT *\nFORM users\nWHERE age > 18",
98 highlightLen: 4,
99 wantContains: []string{
100 "E2001",
101 "FORM users",
102 "line 2",
103 },
104 },
105 }
106
107 for _, tt := range tests {
108 t.Run(tt.name, func(t *testing.T) {
109 got := FormatErrorWithContextAt(tt.code, tt.message, tt.location, tt.sql, tt.highlightLen)
110 for _, substr := range tt.wantContains {
111 if !strings.Contains(got, substr) {
112 t.Errorf("FormatErrorWithContextAt() missing substring %q\nGot:\n%s", substr, got)
113 }
114 }
115 })
116 }
117}
118
119func TestFormatMultiLineContext(t *testing.T) {
120 tests := []struct {

Callers

nothing calls this directly

Calls 3

FormatErrorWithContextAtFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected