diff options
author | Joe Tsai <joetsai@digital-static.net> | 2017-09-28 10:41:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-28 10:41:56 -0700 |
commit | e25c8746f136c5d3731dba1f807b1e50106b3b55 (patch) | |
tree | 4da5833c5a97bb767e4adf2a9ecdd367cb2e5e7e /cmp/compare_test.go | |
parent | f46009a0a1e3526b07f548b2f80f73a4d2d32716 (diff) | |
download | go-cmp-e25c8746f136c5d3731dba1f807b1e50106b3b55.tar.gz |
Change diff.Difference to always return an edit-script (#45)
Rather than performing the heuristic for whether two slices are
"too different" in the diff package, just return the full edit-script
and move the heuristic logic into the cmp package.
The main adjustment to the heuristic is that we only print the
full slice if it is composed of a slice of primitive types (e.g., []byte)
and the difference between the two slices is sufficiently great enough.
Fixes #44
Diffstat (limited to 'cmp/compare_test.go')
-rw-r--r-- | cmp/compare_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cmp/compare_test.go b/cmp/compare_test.go index c60262c..c26ac3f 100644 --- a/cmp/compare_test.go +++ b/cmp/compare_test.go @@ -84,6 +84,37 @@ func TestDiff(t *testing.T) { func comparerTests() []test { const label = "Comparer" + type tarHeader struct { + Name string + Mode int64 + Uid int + Gid int + Size int64 + ModTime time.Time + Typeflag byte + Linkname string + Uname string + Gname string + Devmajor int64 + Devminor int64 + AccessTime time.Time + ChangeTime time.Time + Xattrs map[string]string + } + + makeTarHeaders := func(tf byte) (hs []tarHeader) { + for i := 0; i < 5; i++ { + hs = append(hs, tarHeader{ + Name: fmt.Sprintf("some/dummy/test/file%d", i), + Mode: 0664, Uid: i * 1000, Gid: i * 1000, Size: 1 << uint(i), + ModTime: now.Add(time.Duration(i) * time.Hour), + Uname: "user", Gname: "group", + Typeflag: tf, + }) + } + return hs + } + return []test{{ label: label, x: 1, @@ -301,6 +332,26 @@ root: +: <non-existent>`, }, { label: label, + x: makeTarHeaders('0'), + y: makeTarHeaders('\x00'), + wantDiff: ` +{[]cmp_test.tarHeader}[0].Typeflag: + -: 0x30 + +: 0x00 +{[]cmp_test.tarHeader}[1].Typeflag: + -: 0x30 + +: 0x00 +{[]cmp_test.tarHeader}[2].Typeflag: + -: 0x30 + +: 0x00 +{[]cmp_test.tarHeader}[3].Typeflag: + -: 0x30 + +: 0x00 +{[]cmp_test.tarHeader}[4].Typeflag: + -: 0x30 + +: 0x00`, + }, { + label: label, x: make([]int, 1000), y: make([]int, 1000), opts: []cmp.Option{ |