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

Function TestError_FormatContext

pkg/errors/errors_test.go:171–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

169}
170
171func TestError_FormatContext(t *testing.T) {
172 tests := []struct {
173 name string
174 sql string
175 location models.Location
176 wantLine string
177 wantPos bool // Should have position indicator
178 }{
179 {
180 name: "single line SQL",
181 sql: "SELECT * FROM users",
182 location: models.Location{Line: 1, Column: 10},
183 wantLine: "SELECT * FROM users",
184 wantPos: true,
185 },
186 {
187 name: "multi-line SQL",
188 sql: `SELECT *
189FROM users
190WHERE age > 18`,
191 location: models.Location{Line: 2, Column: 6},
192 wantLine: "FROM users",
193 wantPos: true,
194 },
195 }
196
197 for _, tt := range tests {
198 t.Run(tt.name, func(t *testing.T) {
199 err := NewError(ErrCodeUnexpectedToken, "test", tt.location)
200 err.WithContext(tt.sql, 1)
201
202 output := err.formatContext()
203
204 if !strings.Contains(output, tt.wantLine) {
205 t.Errorf("formatContext() should contain line %q, got: %s", tt.wantLine, output)
206 }
207
208 if tt.wantPos && !strings.Contains(output, "^") {
209 t.Errorf("formatContext() should contain position indicator, got: %s", output)
210 }
211 })
212 }
213}
214
215func TestError_Unwrap(t *testing.T) {
216 causeErr := NewError(ErrCodeInvalidSyntax, "cause error", models.Location{})

Callers

nothing calls this directly

Calls 5

WithContextMethod · 0.95
formatContextMethod · 0.95
RunMethod · 0.80
NewErrorFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected