aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/change_test.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-05-10 16:47:15 +0200
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-05-23 11:05:14 +0200
commit2f293f4a5214ccba5bdf0b82ff8b62ed39144078 (patch)
tree8942869ff31dbf3aa950c1d3cddb3a0de8ca0aa3 /plumbing/object/change_test.go
parent2ff77a8d93529cefdca922dbed89d4b1cd0ee8e5 (diff)
downloadgo-git-2f293f4a5214ccba5bdf0b82ff8b62ed39144078.tar.gz
format/diff: unified diff encoder and public API
- Added Patch interface - Added a Unified Diff encoder from Patches - Added Change method to generate Patches - Added Changes method to generate Patches - Added Tree method to generate Patches - Added Commit method to generate Patches
Diffstat (limited to 'plumbing/object/change_test.go')
-rw-r--r--plumbing/object/change_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/plumbing/object/change_test.go b/plumbing/object/change_test.go
index bfd4613..ded7ff2 100644
--- a/plumbing/object/change_test.go
+++ b/plumbing/object/change_test.go
@@ -5,6 +5,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/diff"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
"gopkg.in/src-d/go-git.v4/utils/merkletrie"
@@ -75,6 +76,12 @@ func (s *ChangeSuite) TestInsert(c *C) {
c.Assert(to.Name, Equals, name)
c.Assert(to.Blob.Hash, Equals, blob)
+ p, err := change.Patch()
+ c.Assert(err, IsNil)
+ c.Assert(len(p.FilePatches()), Equals, 1)
+ c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 1)
+ c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Add)
+
str := change.String()
c.Assert(str, Equals, "<Action: Insert, Path: examples/clone/main.go>")
}
@@ -121,6 +128,12 @@ func (s *ChangeSuite) TestDelete(c *C) {
c.Assert(from.Name, Equals, name)
c.Assert(from.Blob.Hash, Equals, blob)
+ p, err := change.Patch()
+ c.Assert(err, IsNil)
+ c.Assert(len(p.FilePatches()), Equals, 1)
+ c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 1)
+ c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Delete)
+
str := change.String()
c.Assert(str, Equals, "<Action: Delete, Path: utils/difftree/difftree.go>")
}
@@ -181,6 +194,18 @@ func (s *ChangeSuite) TestModify(c *C) {
c.Assert(to.Name, Equals, name)
c.Assert(to.Blob.Hash, Equals, toBlob)
+ p, err := change.Patch()
+ c.Assert(err, IsNil)
+ c.Assert(len(p.FilePatches()), Equals, 1)
+ c.Assert(len(p.FilePatches()[0].Chunks()), Equals, 7)
+ c.Assert(p.FilePatches()[0].Chunks()[0].Type(), Equals, diff.Equal)
+ c.Assert(p.FilePatches()[0].Chunks()[1].Type(), Equals, diff.Delete)
+ c.Assert(p.FilePatches()[0].Chunks()[2].Type(), Equals, diff.Add)
+ c.Assert(p.FilePatches()[0].Chunks()[3].Type(), Equals, diff.Equal)
+ c.Assert(p.FilePatches()[0].Chunks()[4].Type(), Equals, diff.Delete)
+ c.Assert(p.FilePatches()[0].Chunks()[5].Type(), Equals, diff.Add)
+ c.Assert(p.FilePatches()[0].Chunks()[6].Type(), Equals, diff.Equal)
+
str := change.String()
c.Assert(str, Equals, "<Action: Modify, Path: utils/difftree/difftree.go>")
}