(t *testing.T)
| 193 | } |
| 194 | |
| 195 | func TestFormatErrorSummary(t *testing.T) { |
| 196 | tests := []struct { |
| 197 | name string |
| 198 | err error |
| 199 | wantCode bool |
| 200 | contains []string |
| 201 | }{ |
| 202 | { |
| 203 | name: "structured error", |
| 204 | err: NewError(ErrCodeUnexpectedToken, "unexpected token", models.Location{Line: 5, Column: 10}), |
| 205 | wantCode: true, |
| 206 | contains: []string{ |
| 207 | "[E2001]", |
| 208 | "unexpected token", |
| 209 | "line 5, column 10", |
| 210 | }, |
| 211 | }, |
| 212 | { |
| 213 | name: "simple error", |
| 214 | err: fmt.Errorf("simple error"), |
| 215 | wantCode: false, |
| 216 | contains: []string{ |
| 217 | "Error:", |
| 218 | "simple error", |
| 219 | }, |
| 220 | }, |
| 221 | } |
| 222 | |
| 223 | for _, tt := range tests { |
| 224 | t.Run(tt.name, func(t *testing.T) { |
| 225 | got := FormatErrorSummary(tt.err) |
| 226 | |
| 227 | for _, substr := range tt.contains { |
| 228 | if !strings.Contains(got, substr) { |
| 229 | t.Errorf("FormatErrorSummary() missing substring %q\nGot: %s", substr, got) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if tt.wantCode && !strings.Contains(got, "[E") { |
| 234 | t.Errorf("FormatErrorSummary() should contain error code [E*]\nGot: %s", got) |
| 235 | } |
| 236 | }) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | func TestFormatErrorWithSuggestion(t *testing.T) { |
| 241 | tests := []struct { |
nothing calls this directly
no test coverage detected