Sort map keys before diffing maps

pull/171/head
Ernesto Jiménez 2015-11-11 20:33:49 +01:00
parent e7a1d8890c
commit 67106a5111
2 changed files with 19 additions and 2 deletions

View File

@ -961,6 +961,7 @@ func diff(expected interface{}, actual interface{}) string {
return ""
}
spew.Config.SortKeys = true
e := spew.Sdump(expected)
a := spew.Sdump(actual)

View File

@ -1055,12 +1055,28 @@ Diff:
)
Equal(t, expected, actual)
// output for maps cannot be equally tested since order is random
expected = `
Diff:
--- Expected
+++ Actual
@@ -1,6 +1,6 @@
(map[string]int) (len=4) {
- (string) (len=4) "four": (int) 4,
+ (string) (len=4) "five": (int) 5,
(string) (len=3) "one": (int) 1,
- (string) (len=5) "three": (int) 3,
- (string) (len=3) "two": (int) 2
+ (string) (len=5) "seven": (int) 7,
+ (string) (len=5) "three": (int) 3
}
`
actual = diff(
map[string]int{"one": 1, "two": 2, "three": 3, "four": 4},
map[string]int{"one": 1, "three": 3, "five": 5, "seven": 7},
)
NotZero(t, len(actual))
Equal(t, expected, actual)
}
func TestDiffEmptyCases(t *testing.T) {