Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1955,8 +1955,10 @@ func diff(expected interface{}, actual interface{}) string {
e = spewConfigStringerEnabled.Sdump(expected)
a = spewConfigStringerEnabled.Sdump(actual)
default:
e = spewConfig.Sdump(expected)
a = spewConfig.Sdump(actual)
config := spewConfig
config.TrailingMapComma = true
e = config.Sdump(expected)
a = config.Sdump(actual)
}

diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
Expand Down
5 changes: 2 additions & 3 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2971,10 +2971,9 @@ Diff:
- (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
(string) (len=5) "three": (int) 3,
- (string) (len=3) "two": (int) 2,
}
`

Expand Down
4 changes: 4 additions & 0 deletions internal/spew/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ type ConfigState struct {
// be spewed to strings and sorted by those strings. This is only
// considered if SortKeys is true.
SpewKeys bool

// TrailingMapComma adds a comma after the last entry when dumping a map.
// This keeps unchanged entries identical when comparing two map dumps.
TrailingMapComma bool
}

// Config is the active configuration of the top-level functions.
Expand Down
2 changes: 1 addition & 1 deletion internal/spew/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (d *dumpState) dump(v reflect.Value) {
d.w.Write(colonSpaceBytes)
d.ignoreNextIndent = true
d.dump(d.unpackValue(v.MapIndex(key)))
if i < (numEntries - 1) {
if d.cs.TrailingMapComma || i < numEntries-1 {
d.w.Write(commaNewlineBytes)
} else {
d.w.Write(newlineBytes)
Expand Down