Skip to content

Commit 42c233d

Browse files
committed
Supporting arrays
1 parent 7bfacb0 commit 42c233d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

diff/diff.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func diff(c config, lhs, rhs interface{}, visited *visited) (Differ, error) {
6464
}
6565

6666
switch lhsVal.Kind() {
67-
case reflect.Slice:
67+
case reflect.Slice, reflect.Array:
6868
return c.sliceFn(c, lhs, rhs, visited)
6969
case reflect.Map:
7070
return newMap(c, lhs, rhs, visited)
@@ -79,6 +79,9 @@ func areScalars(lhs, rhs reflect.Value) bool {
7979
if lhs.Kind() == reflect.Struct || rhs.Kind() == reflect.Struct {
8080
return false
8181
}
82+
if lhs.Kind() == reflect.Array || rhs.Kind() == reflect.Array {
83+
return false
84+
}
8285

8386
return lhs.Type().Comparable() && rhs.Type().Comparable()
8487
}

diff/example_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ func ExampleDiff_struct() {
4848
Foo int
4949
Bar string
5050
Baz subStruct
51+
Ban [2]int
5152

5253
priv int
5354
}
5455
type structB struct {
5556
Foo int
5657
Bar string
5758
Baz subStruct
59+
Ban [2]int
5860

5961
priv int
6062
}
@@ -66,6 +68,7 @@ func ExampleDiff_struct() {
6668
Hello: 11,
6769
World: 3.5,
6870
},
71+
Ban: [2]int{3, 5},
6972
priv: 0,
7073
}
7174
rhs := structB{
@@ -75,6 +78,7 @@ func ExampleDiff_struct() {
7578
Hello: 11,
7679
World: 3.5,
7780
},
81+
Ban: [2]int{3, 7},
7882
priv: 1,
7983
}
8084

@@ -91,6 +95,11 @@ func ExampleDiff_struct() {
9195

9296
// Output:
9397
// diff_test.structA map[
98+
// Ban: [2]int [
99+
// int 3
100+
// - int 5
101+
// + int 7
102+
// ]
94103
// Bar: string hello
95104
// Baz: diff_test.subStruct {11 3.5}
96105
// - Foo: int 42

0 commit comments

Comments
 (0)