| 1 | package git |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestTextDiffSizes(t *testing.T) { |
| 6 | sizes := map[string]int64{"1111111": 7, "2222222": 9} |
| 7 | size := func(blob string) int64 { |
| 8 | if n, ok := sizes[blob]; ok { |
| 9 | return n |
| 10 | } |
| 11 | return -1 |
| 12 | } |
| 13 | hunk := "@@ -1 +1 @@\n-\xff\n+\x00\n" |
| 14 | for _, tc := range []struct { |
| 15 | name, header string |
| 16 | size int64 |
| 17 | }{ |
| 18 | {"a changed file has its size after the change", "diff --git a/k b/k\nindex 1111111..2222222 100644\n--- a/k\n+++ b/k\n", 9}, |
| 19 | {"a deleted file has its size before the change", "diff --git a/k b/k\ndeleted file mode 100644\nindex 1111111..0000000\n--- a/k\n+++ /dev/null\n", 7}, |
| 20 | {"a blob the repository lacks has no size", "diff --git a/k b/k\nindex 3333333..4444444 100644\n--- a/k\n+++ b/k\n", -1}, |
| 21 | {"a header without an index line has no size", "diff --git a/k b/k\n--- a/k\n+++ b/k\n", -1}, |
| 22 | } { |
| 23 | t.Run(tc.name, func(t *testing.T) { |
| 24 | want := tc.header + NotText(tc.size) + "\n" |
| 25 | if got := textDiff(tc.header+hunk, size); got != want { |
| 26 | t.Errorf("textDiff:\n got %q\nwant %q", got, want) |
| 27 | } |
| 28 | }) |
| 29 | } |
| 30 | } |