From 48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc Mon Sep 17 00:00:00 2001 From: Alberto Cortés Date: Fri, 27 Nov 2015 12:39:34 +0100 Subject: fix PR#7 comments --- diff/diff_ext_test.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'diff') 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)) + } +} -- cgit