--- ParseDiff ---
(t *testing.T)
| 277 | // --- ParseDiff --- |
| 278 | |
| 279 | func TestParseDiff_SimpleHunk(t *testing.T) { |
| 280 | t.Parallel() |
| 281 | raw := `diff --git a/f.go b/f.go |
| 282 | index abc..def 100644 |
| 283 | --- a/f.go |
| 284 | +++ b/f.go |
| 285 | @@ -1,3 +1,4 @@ |
| 286 | context |
| 287 | -removed |
| 288 | +added1 |
| 289 | +added2` |
| 290 | parsed := ParseDiff(raw) |
| 291 | if parsed.Binary { |
| 292 | t.Error("should not be binary") |
| 293 | } |
| 294 | if len(parsed.Lines) == 0 { |
| 295 | t.Fatal("expected parsed lines") |
| 296 | } |
| 297 | // Should have: hunk header, context, removed, added1, added2 |
| 298 | types := make(map[DiffLineType]int) |
| 299 | for _, l := range parsed.Lines { |
| 300 | types[l.Type]++ |
| 301 | } |
| 302 | if types[LineHunkHeader] != 1 { |
| 303 | t.Errorf("hunk headers=%d, want 1", types[LineHunkHeader]) |
| 304 | } |
| 305 | if types[LineRemoved] != 1 { |
| 306 | t.Errorf("removed=%d, want 1", types[LineRemoved]) |
| 307 | } |
| 308 | if types[LineAdded] != 2 { |
| 309 | t.Errorf("added=%d, want 2", types[LineAdded]) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | func TestParseDiff_BinaryFile(t *testing.T) { |
| 314 | t.Parallel() |
nothing calls this directly
no test coverage detected