1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package diff_test
import (
"testing"
"srcd.works/go-git.v4/utils/diff"
"github.com/sergi/go-diff/diffmatchpatch"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type suiteCommon struct{}
var _ = Suite(&suiteCommon{})
var diffTests = [...]struct {
src string // the src string to diff
dst string // the dst string to diff
}{
// equal inputs
{"", ""},
{"a", "a"},
{"a\n", "a\n"},
{"a\nb", "a\nb"},
{"a\nb\n", "a\nb\n"},
{"a\nb\nc", "a\nb\nc"},
{"a\nb\nc\n", "a\nb\nc\n"},
// missing '\n'
{"", "\n"},
{"\n", ""},
{"a", "a\n"},
{"a\n", "a"},
{"a\nb", "a\nb"},
{"a\nb\n", "a\nb\n"},
{"a\nb\nc", "a\nb\nc"},
{"a\nb\nc\n", "a\nb\nc\n"},
// generic
{"a\nbbbbb\n\tccc\ndd\n\tfffffffff\n", "bbbbb\n\tccc\n\tDD\n\tffff\n"},
}
func (s *suiteCommon) TestAll(c *C) {
for i, t := range diffTests {
diffs := diff.Do(t.src, t.dst)
src := diff.Src(diffs)
dst := diff.Dst(diffs)
c.Assert(src, Equals, t.src, Commentf("subtest %d, src=%q, dst=%q, bad calculated src", i, t.src, t.dst))
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
exp []diffmatchpatch.Diff
}{
{
src: "",
dst: "",
exp: []diffmatchpatch.Diff{},
},
{
src: "a",
dst: "a",
exp: []diffmatchpatch.Diff{
{
Type: 0,
Text: "a",
},
},
},
{
src: "",
dst: "abc\ncba",
exp: []diffmatchpatch.Diff{
{
Type: 1,
Text: "abc\ncba",
},
},
},
{
src: "abc\ncba",
dst: "",
exp: []diffmatchpatch.Diff{
{
Type: -1,
Text: "abc\ncba",
},
},
},
{
src: "abc\nbcd\ncde",
dst: "000\nabc\n111\nBCD\n",
exp: []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.exp, Commentf("subtest %d", i))
}
}
|