diff_test.go
| 1 | package highlight |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // Git C-quotes non-ASCII names and appends a TAB to names with a space. |
| 6 | func TestParseDiffQuotedPathsAndBatchedBinarySizes(t *testing.T) { |
| 7 | raw := "diff --git \"a/b \\303\\274.bin\" \"b/b \\303\\274.bin\"\n" + |
| 8 | "new file mode 100644\n" + |
| 9 | "index 0000000..88768ef\n" + |
| 10 | "Binary files /dev/null and \"b/b \\303\\274.bin\" differ\n" + |
| 11 | "diff --git a/x.bin b/x.bin\n" + |
| 12 | "index 1111111..2222222 100644\n" + |
| 13 | "Binary files a/x.bin and b/x.bin differ\n" + |
| 14 | "diff --git \"a/d/\\303\\244 \\303\\266.txt\" \"b/d/\\303\\244 \\303\\266.txt\"\n" + |
| 15 | "new file mode 100644\n" + |
| 16 | "index 0000000..587be6b\n" + |
| 17 | "--- /dev/null\n" + |
| 18 | "+++ \"b/d/\\303\\244 \\303\\266.txt\"\t\n" + |
| 19 | "@@ -0,0 +1 @@\n" + |
| 20 | "+x\n" + |
| 21 | "diff --git a/sp ace.txt \"b/r\\303\\251 name.txt\"\n" + |
| 22 | "similarity index 100%\n" + |
| 23 | "rename from sp ace.txt\n" + |
| 24 | "rename to \"r\\303\\251 name.txt\"\n" |
| 25 | calls := 0 |
| 26 | files := parseDiff(raw, func(shas []string) map[string]int64 { |
| 27 | calls++ |
| 28 | return map[string]int64{"88768ef": 5, "1111111": 7, "2222222": 9} |
| 29 | }) |
| 30 | if calls != 1 { |
| 31 | t.Fatalf("blobSizes called %d times", calls) |
| 32 | } |
| 33 | if len(files) != 4 { |
| 34 | t.Fatalf("got %d files", len(files)) |
| 35 | } |
| 36 | if f := files[0]; f.NewPath != "b ü.bin" || !f.IsBinary || f.BinaryOldSize != 0 || f.BinaryNewSize != 5 || !f.hasNewSize { |
| 37 | t.Fatalf("added binary: %+v", f) |
| 38 | } |
| 39 | if f := files[1]; f.BinaryOldSize != 7 || f.BinaryNewSize != 9 { |
| 40 | t.Fatalf("modified binary: %+v", f) |
| 41 | } |
| 42 | if f := files[2]; f.NewPath != "d/ä ö.txt" || f.Added != 1 { |
| 43 | t.Fatalf("text file: %+v", f) |
| 44 | } |
| 45 | if f := files[3]; f.OldPath != "sp ace.txt" || f.NewPath != "ré name.txt" || f.Status != StatusRenamed { |
| 46 | t.Fatalf("rename: %+v", f) |
| 47 | } |
| 48 | } |
| 49 |