Skip to content

Commit 5339ce5

Browse files
committed
Added missing test for GetUnifiedDiffString.
This indirectly covers WriteUnifiedDiff as well.
1 parent c781559 commit 5339ce5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

difflib/difflib_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,22 @@ func TestDifferQFormat(t *testing.T) {
558558
t.Fatal("Differ QFormat() failure:", out)
559559
}
560560
}
561+
562+
func TestGetUnifiedDiffString(t *testing.T) {
563+
A := "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\n"
564+
B := "one\ntwo\nthr33\nfour\nfive\nsix\nseven\neight\nnine\nten\n"
565+
// Build diff
566+
diff := UnifiedDiff{A: SplitLines(A),
567+
FromFile: "file", FromDate: "then",
568+
B: SplitLines(B),
569+
ToFile: "tile", ToDate: "now", Eol: "", Context: 1}
570+
// Run test
571+
diffStr, err := GetUnifiedDiffString(diff)
572+
if err != nil {
573+
t.Fatal("GetUnifiedDiffString error:", err)
574+
}
575+
exp := "--- file\tthen\n+++ tile\tnow\n@@ -2,3 +2,3 @@\n two\n-three\n+thr33\n four\n"
576+
if diffStr != exp {
577+
t.Fatal("GetUnifiedDiffString failure:", diffStr)
578+
}
579+
}

0 commit comments

Comments
 (0)