vendor: Mega update all dependencies
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
59
vendor/github.com/d4l3k/messagediff/example/atom_test.go
generated
vendored
59
vendor/github.com/d4l3k/messagediff/example/atom_test.go
generated
vendored
@@ -1,59 +0,0 @@
|
||||
package examples
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/d4l3k/messagediff"
|
||||
"golang.org/x/net/html"
|
||||
"golang.org/x/net/html/atom"
|
||||
)
|
||||
|
||||
func ExampleAtom() {
|
||||
got := data2()
|
||||
want := data1()
|
||||
diff, equal := messagediff.PrettyDiff(want, got)
|
||||
fmt.Printf("%v %s", equal, diff)
|
||||
// Output: false modified: [0].FirstChild.NextSibling.Attr = " baz"
|
||||
}
|
||||
|
||||
func data1() []*html.Node {
|
||||
n := &html.Node{
|
||||
Type: html.ElementNode, Data: atom.Span.String(),
|
||||
Attr: []html.Attribute{
|
||||
{Key: atom.Class.String(), Val: "foo"},
|
||||
},
|
||||
}
|
||||
n.AppendChild(
|
||||
&html.Node{
|
||||
Type: html.ElementNode, Data: atom.Span.String(),
|
||||
Attr: []html.Attribute{
|
||||
{Key: atom.Class.String(), Val: "bar"},
|
||||
},
|
||||
},
|
||||
)
|
||||
n.AppendChild(&html.Node{
|
||||
Type: html.TextNode, Data: "baz",
|
||||
})
|
||||
return []*html.Node{n}
|
||||
}
|
||||
|
||||
func data2() []*html.Node {
|
||||
n := &html.Node{
|
||||
Type: html.ElementNode, Data: atom.Span.String(),
|
||||
Attr: []html.Attribute{
|
||||
{Key: atom.Class.String(), Val: "foo"},
|
||||
},
|
||||
}
|
||||
n.AppendChild(
|
||||
&html.Node{
|
||||
Type: html.ElementNode, Data: atom.Span.String(),
|
||||
Attr: []html.Attribute{
|
||||
{Key: atom.Class.String(), Val: "bar"},
|
||||
},
|
||||
},
|
||||
)
|
||||
n.AppendChild(&html.Node{
|
||||
Type: html.TextNode, Data: " baz",
|
||||
})
|
||||
return []*html.Node{n}
|
||||
}
|
||||
29
vendor/github.com/d4l3k/messagediff/messagediff.go
generated
vendored
29
vendor/github.com/d4l3k/messagediff/messagediff.go
generated
vendored
@@ -41,20 +41,25 @@ func newDiff() *Diff {
|
||||
}
|
||||
|
||||
func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
// The array underlying `path` could be modified in subsequent
|
||||
// calls. Make sure we have a local copy.
|
||||
localPath := make(Path, len(path))
|
||||
copy(localPath, path)
|
||||
|
||||
// Validity checks. Should only trigger if nil is one of the original arguments.
|
||||
if !aVal.IsValid() && !bVal.IsValid() {
|
||||
return true
|
||||
}
|
||||
if !bVal.IsValid() {
|
||||
d.Modified[&path] = nil
|
||||
d.Modified[&localPath] = nil
|
||||
return false
|
||||
} else if !aVal.IsValid() {
|
||||
d.Modified[&path] = bVal.Interface()
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
return false
|
||||
}
|
||||
|
||||
if aVal.Type() != bVal.Type() {
|
||||
d.Modified[&path] = bVal.Interface()
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
return false
|
||||
}
|
||||
kind := aVal.Kind()
|
||||
@@ -96,7 +101,7 @@ func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
return true
|
||||
}
|
||||
if aVal.IsNil() || bVal.IsNil() {
|
||||
d.Modified[&path] = bVal.Interface()
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -106,20 +111,20 @@ func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
aLen := aVal.Len()
|
||||
bLen := bVal.Len()
|
||||
for i := 0; i < min(aLen, bLen); i++ {
|
||||
localPath := append(path, SliceIndex(i))
|
||||
localPath := append(localPath, SliceIndex(i))
|
||||
if eq := d.diff(aVal.Index(i), bVal.Index(i), localPath); !eq {
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
if aLen > bLen {
|
||||
for i := bLen; i < aLen; i++ {
|
||||
localPath := append(path, SliceIndex(i))
|
||||
localPath := append(localPath, SliceIndex(i))
|
||||
d.Removed[&localPath] = aVal.Index(i).Interface()
|
||||
equal = false
|
||||
}
|
||||
} else if aLen < bLen {
|
||||
for i := aLen; i < bLen; i++ {
|
||||
localPath := append(path, SliceIndex(i))
|
||||
localPath := append(localPath, SliceIndex(i))
|
||||
d.Added[&localPath] = bVal.Index(i).Interface()
|
||||
equal = false
|
||||
}
|
||||
@@ -128,7 +133,7 @@ func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
for _, key := range aVal.MapKeys() {
|
||||
aI := aVal.MapIndex(key)
|
||||
bI := bVal.MapIndex(key)
|
||||
localPath := append(path, MapKey{key.Interface()})
|
||||
localPath := append(localPath, MapKey{key.Interface()})
|
||||
if !bI.IsValid() {
|
||||
d.Removed[&localPath] = aI.Interface()
|
||||
equal = false
|
||||
@@ -140,7 +145,7 @@ func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
aI := aVal.MapIndex(key)
|
||||
if !aI.IsValid() {
|
||||
bI := bVal.MapIndex(key)
|
||||
localPath := append(path, MapKey{key.Interface()})
|
||||
localPath := append(localPath, MapKey{key.Interface()})
|
||||
d.Added[&localPath] = bI.Interface()
|
||||
equal = false
|
||||
}
|
||||
@@ -150,7 +155,7 @@ func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
index := []int{i}
|
||||
field := typ.FieldByIndex(index)
|
||||
localPath := append(path, StructField(field.Name))
|
||||
localPath := append(localPath, StructField(field.Name))
|
||||
aI := unsafeReflectValue(aVal.FieldByIndex(index))
|
||||
bI := unsafeReflectValue(bVal.FieldByIndex(index))
|
||||
if eq := d.diff(aI, bI, localPath); !eq {
|
||||
@@ -158,12 +163,12 @@ func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
}
|
||||
}
|
||||
case reflect.Ptr:
|
||||
equal = d.diff(aVal.Elem(), bVal.Elem(), path)
|
||||
equal = d.diff(aVal.Elem(), bVal.Elem(), localPath)
|
||||
default:
|
||||
if reflect.DeepEqual(aVal.Interface(), bVal.Interface()) {
|
||||
equal = true
|
||||
} else {
|
||||
d.Modified[&path] = bVal.Interface()
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
|
||||
164
vendor/github.com/d4l3k/messagediff/messagediff_test.go
generated
vendored
164
vendor/github.com/d4l3k/messagediff/messagediff_test.go
generated
vendored
@@ -1,164 +0,0 @@
|
||||
package messagediff
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type testStruct struct {
|
||||
A, b int
|
||||
C []int
|
||||
D [3]int
|
||||
}
|
||||
|
||||
type RecursiveStruct struct {
|
||||
Key int
|
||||
Child *RecursiveStruct
|
||||
}
|
||||
|
||||
func newRecursiveStruct(key int) *RecursiveStruct {
|
||||
a := &RecursiveStruct{
|
||||
Key: key,
|
||||
}
|
||||
b := &RecursiveStruct{
|
||||
Key: key,
|
||||
Child: a,
|
||||
}
|
||||
a.Child = b
|
||||
return a
|
||||
}
|
||||
|
||||
type testCase struct {
|
||||
a, b interface{}
|
||||
diff string
|
||||
equal bool
|
||||
}
|
||||
|
||||
func checkTestCases(t *testing.T, testData []testCase) {
|
||||
for i, td := range testData {
|
||||
diff, equal := PrettyDiff(td.a, td.b)
|
||||
if diff != td.diff {
|
||||
t.Errorf("%d. PrettyDiff(%#v, %#v) diff = %#v; not %#v", i, td.a, td.b, diff, td.diff)
|
||||
}
|
||||
if equal != td.equal {
|
||||
t.Errorf("%d. PrettyDiff(%#v, %#v) equal = %#v; not %#v", i, td.a, td.b, equal, td.equal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrettyDiff(t *testing.T) {
|
||||
testData := []testCase{
|
||||
{
|
||||
true,
|
||||
false,
|
||||
"modified: = false\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
true,
|
||||
0,
|
||||
"modified: = 0\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
[]int{0, 1, 2},
|
||||
[]int{0, 1, 2, 3},
|
||||
"added: [3] = 3\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
[]int{0, 1, 2, 3},
|
||||
[]int{0, 1, 2},
|
||||
"removed: [3] = 3\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
[]int{0},
|
||||
[]int{1},
|
||||
"modified: [0] = 1\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
&[]int{0},
|
||||
&[]int{1},
|
||||
"modified: [0] = 1\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
map[string]int{"a": 1, "b": 2},
|
||||
map[string]int{"b": 4, "c": 3},
|
||||
"added: [\"c\"] = 3\nmodified: [\"b\"] = 4\nremoved: [\"a\"] = 1\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
testStruct{1, 2, []int{1}, [3]int{4, 5, 6}},
|
||||
testStruct{1, 3, []int{1, 2}, [3]int{4, 5, 6}},
|
||||
"added: .C[1] = 2\nmodified: .b = 3\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
nil,
|
||||
nil,
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
&struct{}{},
|
||||
nil,
|
||||
"modified: = <nil>\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
nil,
|
||||
&struct{}{},
|
||||
"modified: = &struct {}{}\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
time.Time{},
|
||||
time.Time{},
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
time.Time{},
|
||||
"modified: .loc = (*time.Location)(nil)\nmodified: .sec = 0\n",
|
||||
false,
|
||||
},
|
||||
}
|
||||
checkTestCases(t, testData)
|
||||
}
|
||||
|
||||
func TestPrettyDiffRecursive(t *testing.T) {
|
||||
testData := []testCase{
|
||||
{
|
||||
newRecursiveStruct(1),
|
||||
newRecursiveStruct(1),
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
newRecursiveStruct(1),
|
||||
newRecursiveStruct(2),
|
||||
"modified: .Child.Key = 2\nmodified: .Key = 2\n",
|
||||
false,
|
||||
},
|
||||
}
|
||||
checkTestCases(t, testData)
|
||||
}
|
||||
|
||||
func TestPathString(t *testing.T) {
|
||||
testData := []struct {
|
||||
in Path
|
||||
want string
|
||||
}{{
|
||||
Path{StructField("test"), SliceIndex(1), MapKey{"blue"}, MapKey{12.3}},
|
||||
".test[1][\"blue\"][12.3]",
|
||||
}}
|
||||
for i, td := range testData {
|
||||
if out := td.in.String(); out != td.want {
|
||||
t.Errorf("%d. %#v.String() = %#v; not %#v", i, td.in, out, td.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user