(t *testing.T)
| 169 | } |
| 170 | |
| 171 | func 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 * |
| 189 | FROM users |
| 190 | WHERE 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 | |
| 215 | func TestError_Unwrap(t *testing.T) { |
| 216 | causeErr := NewError(ErrCodeInvalidSyntax, "cause error", models.Location{}) |
nothing calls this directly
no test coverage detected