summaryrefslogtreecommitdiff
path: root/diff_test.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2014-12-30 10:09:20 +0000
committerCarlos Martín Nieto <[email protected]>2014-12-30 10:09:20 +0000
commit42414248f9d4fb77cc4b48447364a6dcb1624607 (patch)
tree5dbc19b7a1d5d6faa8fecf4c8b6b2c4559084d4e /diff_test.go
parent74957c2ae6dc852a50de54fc788f207d8f385d67 (diff)
parentd2a9d7768bb76719ac4506715ec8037fea3609a2 (diff)
Merge pull request #150 from sqs/DiffOptions_OldPrefix_and_NewPrefix
Diff: heed DiffOptions fields OldPrefix and NewPrefix
Diffstat (limited to 'diff_test.go')
-rw-r--r--diff_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/diff_test.go b/diff_test.go
index 84d72db..7c54f4e 100644
--- a/diff_test.go
+++ b/diff_test.go
@@ -3,6 +3,7 @@ package git
import (
"errors"
"os"
+ "strings"
"testing"
)
@@ -75,6 +76,8 @@ func TestDiffTreeToTree(t *testing.T) {
callbackInvoked = true
return nil
},
+ OldPrefix: "x1/",
+ NewPrefix: "y1/",
}
diff, err := repo.DiffTreeToTree(originalTree, newTree, &opts)
@@ -90,7 +93,19 @@ func TestDiffTreeToTree(t *testing.T) {
files := make([]string, 0)
hunks := make([]DiffHunk, 0)
lines := make([]DiffLine, 0)
+ patches := make([]string, 0)
err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
+ patch, err := diff.Patch(len(patches))
+ if err != nil {
+ return nil, err
+ }
+ defer patch.Free()
+ patchStr, err := patch.String()
+ if err != nil {
+ return nil, err
+ }
+ patches = append(patches, patchStr)
+
files = append(files, file.OldFile.Path)
return func(hunk DiffHunk) (DiffForEachLineCallback, error) {
hunks = append(hunks, hunk)
@@ -131,6 +146,10 @@ func TestDiffTreeToTree(t *testing.T) {
t.Fatal("Incorrect lines in diff")
}
+ if want1, want2 := "x1/README", "y1/README"; !strings.Contains(patches[0], want1) || !strings.Contains(patches[0], want2) {
+ t.Errorf("Diff patch doesn't contain %q or %q\n\n%s", want1, want2, patches[0])
+ }
+
errTest := errors.New("test error")
err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {