fix(tools) diff preview for files without trailing newline

This commit is contained in:
afjcjsbx committed 2026-05-12 23:06:43 +02:00
1 parent 4a81f0e740
commit 87048499ff
2 files changed
+76 -5

No files matched your search

+37 -1
View File
@@ -26,7 +26,7 @@ func TestDiffResult_UserVisibleUnifiedDiff(t *testing.T) {
"```diff",
"--- a/tmp/example.txt",
"+++ b/tmp/example.txt",
"@@ -1,4 +1,4 @@",
"@@ -1,3 +1,3 @@",
" alpha",
"-beta",
"+beta 2",
@@ -48,6 +48,42 @@ func TestBuildUnifiedDiff_NoContentChange(t *testing.T) {
}
}
func TestBuildUnifiedDiff_PreservesTrailingNewlineRemoval(t *testing.T) {
diff, err := buildUnifiedDiff("test.txt", []byte("same\n"), []byte("same"))
if err != nil {
t.Fatalf("buildUnifiedDiff() error = %v", err)
}
for _, want := range []string{
"--- a/test.txt",
"+++ b/test.txt",
" same",
"+" + noNewlineAtEOFMarker,
} {
if !strings.Contains(diff, want) {
t.Fatalf("buildUnifiedDiff() missing %q:\n%s", want, diff)
}
}
}
func TestBuildUnifiedDiff_PreservesTrailingNewlineAddition(t *testing.T) {
diff, err := buildUnifiedDiff("test.txt", []byte("same"), []byte("same\n"))
if err != nil {
t.Fatalf("buildUnifiedDiff() error = %v", err)
}
for _, want := range []string{
"--- a/test.txt",
"+++ b/test.txt",
" same",
"-" + noNewlineAtEOFMarker,
} {
if !strings.Contains(diff, want) {
t.Fatalf("buildUnifiedDiff() missing %q:\n%s", want, diff)
}
}
}
func TestBuildUnifiedDiff_UsesNormalizedDisplayPaths(t *testing.T) {
diff, err := buildUnifiedDiff("/tmp/nested/example.txt", []byte("before\n"), []byte("after\n"))
if err != nil {