package highlight import "testing" // Git C-quotes non-ASCII names and appends a TAB to names with a space. func TestParseDiffQuotedPathsAndBatchedBinarySizes(t *testing.T) { raw := "diff --git \"a/b \\303\\274.bin\" \"b/b \\303\\274.bin\"\n" + "new file mode 100644\n" + "index 0000000..88768ef\n" + "Binary files /dev/null and \"b/b \\303\\274.bin\" differ\n" + "diff --git a/x.bin b/x.bin\n" + "index 1111111..2222222 100644\n" + "Binary files a/x.bin and b/x.bin differ\n" + "diff --git \"a/d/\\303\\244 \\303\\266.txt\" \"b/d/\\303\\244 \\303\\266.txt\"\n" + "new file mode 100644\n" + "index 0000000..587be6b\n" + "--- /dev/null\n" + "+++ \"b/d/\\303\\244 \\303\\266.txt\"\t\n" + "@@ -0,0 +1 @@\n" + "+x\n" + "diff --git a/sp ace.txt \"b/r\\303\\251 name.txt\"\n" + "similarity index 100%\n" + "rename from sp ace.txt\n" + "rename to \"r\\303\\251 name.txt\"\n" calls := 0 files := parseDiff(raw, func(shas []string) map[string]int64 { calls++ return map[string]int64{"88768ef": 5, "1111111": 7, "2222222": 9} }) if calls != 1 { t.Fatalf("blobSizes called %d times", calls) } if len(files) != 4 { t.Fatalf("got %d files", len(files)) } if f := files[0]; f.NewPath != "b ü.bin" || !f.IsBinary || f.BinaryOldSize != 0 || f.BinaryNewSize != 5 || !f.hasNewSize { t.Fatalf("added binary: %+v", f) } if f := files[1]; f.BinaryOldSize != 7 || f.BinaryNewSize != 9 { t.Fatalf("modified binary: %+v", f) } if f := files[2]; f.NewPath != "d/ä ö.txt" || f.Added != 1 { t.Fatalf("text file: %+v", f) } if f := files[3]; f.OldPath != "sp ace.txt" || f.NewPath != "ré name.txt" || f.Status != StatusRenamed { t.Fatalf("rename: %+v", f) } }