diff options
| author | Patrick Mezard <[email protected]> | 2013-10-27 23:44:49 +0100 |
|---|---|---|
| committer | Patrick Mezard <[email protected]> | 2013-10-27 23:44:49 +0100 |
| commit | 1fdf49f1b9ce7ab182b1b38bbc847b9807f66f3a (patch) | |
| tree | 3bdd47a30426d70c79c8b9c66f16e42a620eff00 /spew/format_test.go | |
| parent | 1fe9f5ca4b46a8247ae5939097f5cfc5d8370729 (diff) | |
config: add SortKeys option to sort native map keys before display
If ConfigState.SortKeys is true, then dump and format will sort map keys
before displaying them. Only native types (bool, ints, uint, uintptr,
string) are supported, other slices are left unchanged.
The motivation is to have more diffable output, mostly for test purpose.
Diffstat (limited to 'spew/format_test.go')
| -rw-r--r-- | spew/format_test.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/spew/format_test.go b/spew/format_test.go index b151513..80c5ef9 100644 --- a/spew/format_test.go +++ b/spew/format_test.go @@ -1472,3 +1472,12 @@ func TestFormatter(t *testing.T) { } } } + +func TestPrintSortedKeys(t *testing.T) { + cfg := spew.ConfigState{SortKeys: true} + s := cfg.Sprint(map[int]string{1: "1", 3: "3", 2: "2"}) + expected := "map[1:1 2:2 3:3]" + if s != expected { + t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) + } +} |
