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

Function TestError_WithContext

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

Source from the content-addressed store, hash-verified

80}
81
82func TestError_WithContext(t *testing.T) {
83 sql := "SELECT * FORM users"
84 location := models.Location{Line: 1, Column: 10}
85
86 err := NewError(ErrCodeExpectedToken, "expected FROM, got FORM", location)
87 err.WithContext(sql, 4) // Highlight "FORM" (4 characters)
88
89 output := err.Error()
90
91 // Should contain the SQL line
92 if !strings.Contains(output, sql) {
93 t.Errorf("Error output should contain SQL line, got: %s", output)
94 }
95
96 // Should contain position indicator
97 if !strings.Contains(output, "^") {
98 t.Errorf("Error output should contain position indicator (^), got: %s", output)
99 }
100
101 // Should highlight the correct length
102 if !strings.Contains(output, "^^^^") {
103 t.Errorf("Error output should highlight 4 characters (^^^^), got: %s", output)
104 }
105}
106
107func TestError_WithHint(t *testing.T) {
108 err := NewError(ErrCodeUnexpectedToken, "unexpected token", models.Location{Line: 1, Column: 5})

Callers

nothing calls this directly

Calls 4

WithContextMethod · 0.95
ErrorMethod · 0.95
NewErrorFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected