diff options
Diffstat (limited to 'diff/diff_ext_test.go')
-rw-r--r-- | diff/diff_ext_test.go | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/diff/diff_ext_test.go b/diff/diff_ext_test.go index 5ab8c7d..460cf8a 100644 --- a/diff/diff_ext_test.go +++ b/diff/diff_ext_test.go @@ -3,9 +3,10 @@ package diff_test import ( "testing" - . "gopkg.in/check.v1" - "gopkg.in/src-d/go-git.v2/diff" + + "github.com/sergi/go-diff/diffmatchpatch" + . "gopkg.in/check.v1" ) func Test(t *testing.T) { TestingT(t) } @@ -39,7 +40,7 @@ var diffTests = [...]struct { {"a\nbbbbb\n\tccc\ndd\n\tfffffffff\n", "bbbbb\n\tccc\n\tDD\n\tffff\n"}, } -func (s *suiteCommon) TestCountLines(c *C) { +func (s *suiteCommon) TestAll(c *C) { for i, t := range diffTests { diffs := diff.Do(t.src, t.dst) src := diff.Src(diffs) @@ -48,3 +49,61 @@ func (s *suiteCommon) TestCountLines(c *C) { c.Assert(dst, Equals, t.dst, Commentf("subtest %d, src=%q, dst=%q, bad calculated dst", i, t.src, t.dst)) } } + +var doTests = [...]struct { + src, dst string + expected []diffmatchpatch.Diff +}{ + { + src: "", + dst: "", + expected: []diffmatchpatch.Diff{}, + }, + { + src: "a", + dst: "a", + expected: []diffmatchpatch.Diff{ + { + Type: 0, + Text: "a", + }, + }, + }, + { + src: "", + dst: "abc\ncba", + expected: []diffmatchpatch.Diff{ + { + Type: 1, + Text: "abc\ncba", + }, + }, + }, + { + src: "abc\ncba", + dst: "", + expected: []diffmatchpatch.Diff{ + { + Type: -1, + Text: "abc\ncba", + }, + }, + }, + { + src: "abc\nbcd\ncde", + dst: "000\nabc\n111\nBCD\n", + expected: []diffmatchpatch.Diff{ + {Type: 1, Text: "000\n"}, + {Type: 0, Text: "abc\n"}, + {Type: -1, Text: "bcd\ncde"}, + {Type: 1, Text: "111\nBCD\n"}, + }, + }, +} + +func (s *suiteCommon) TestDo(c *C) { + for i, t := range doTests { + diffs := diff.Do(t.src, t.dst) + c.Assert(diffs, DeepEquals, t.expected, Commentf("subtest %d", i)) + } +} |