package format import "testing" func TestDiff(t *testing.T) { tests := []struct { name string text string want string }{ {"zero", "--- old\r\n+++ new\r\n", ""}, {"plus", "--- old\r\n+++ new\r\n+test\r\n", "+test
\n"}, {"minus", "--- old\r\n+++ new\r\n-test\r\n", "-test
\n"}, {"hunk", "--- old\r\n+++ new\r\n@@ -0,0 +0,0 @@\r\n", "@@ -0,0 +0,0 @@
\n"}, {"text", "--- old\r\n+++ new\r\n test\r\n", " test
\n"}, {"plus indent", "--- old\r\n+++ new\r\n+ test\r\n", "+  test
\n"}, {"minus indent", "--- old\r\n+++ new\r\n- test\r\n", "-  test
\n"}, {"text indent", "--- old\r\n+++ new\r\n test\r\n", "   test
\n"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := Diff(tt.text) if got != tt.want { t.Errorf("Diff(\"%s\") = %s; want %s", tt.text, got, tt.want) } }) } }