summaryrefslogtreecommitdiff
path: root/spew/dump_test.go
diff options
context:
space:
mode:
authorTim Hockin <[email protected]>2015-03-31 13:55:04 -0700
committerTim Hockin <[email protected]>2015-04-10 08:46:42 -0700
commit3e6e67c4dcea3ac2f25fd4731abc0e1deaf36216 (patch)
tree42e0d210e3ed2efe1cc4e931135d0956398de246 /spew/dump_test.go
parentfc32781af5e85e548d3f1abaf0fa3dbe8a72495c (diff)
Enable methods to sort map keys and spew itself as last resort
If enabled by flags, try to use methods to stringify map keys and sort on that. If we can't use primitive sorting and we can't use methods, we can still fall back on spew itself. If SpewKeys is enabled, use Sprintf("%#v") to generate a string and sort by that.
Diffstat (limited to 'spew/dump_test.go')
-rw-r--r--spew/dump_test.go37
1 files changed, 36 insertions, 1 deletions
diff --git a/spew/dump_test.go b/spew/dump_test.go
index 9e0e65f..3dd9089 100644
--- a/spew/dump_test.go
+++ b/spew/dump_test.go
@@ -64,9 +64,10 @@ package spew_test
import (
"bytes"
"fmt"
- "github.com/davecgh/go-spew/spew"
"testing"
"unsafe"
+
+ "github.com/davecgh/go-spew/spew"
)
// dumpTest is used to describe a test to be perfomed against the Dump method.
@@ -983,4 +984,38 @@ func TestDumpSortedKeys(t *testing.T) {
if s != expected {
t.Errorf("Sorted keys mismatch:\n %v %v", s, expected)
}
+
+ s = cfg.Sdump(map[stringer]int{"1": 1, "3": 3, "2": 2})
+ expected = `(map[spew_test.stringer]int) (len=3) {
+(spew_test.stringer) (len=1) stringer 1: (int) 1,
+(spew_test.stringer) (len=1) stringer 2: (int) 2,
+(spew_test.stringer) (len=1) stringer 3: (int) 3
+}
+`
+ if s != expected {
+ t.Errorf("Sorted keys mismatch:\n %v %v", s, expected)
+ }
+
+ s = cfg.Sdump(map[pstringer]int{pstringer("1"): 1, pstringer("3"): 3, pstringer("2"): 2})
+ expected = `(map[spew_test.pstringer]int) (len=3) {
+(spew_test.pstringer) (len=1) stringer 1: (int) 1,
+(spew_test.pstringer) (len=1) stringer 2: (int) 2,
+(spew_test.pstringer) (len=1) stringer 3: (int) 3
+}
+`
+ if s != expected {
+ t.Errorf("Sorted keys mismatch:\n %v %v", s, expected)
+ }
+
+ s = cfg.Sdump(map[customError]int{customError(1): 1, customError(3): 3, customError(2): 2})
+ expected = `(map[spew_test.customError]int) (len=3) {
+(spew_test.customError) error: 1: (int) 1,
+(spew_test.customError) error: 2: (int) 2,
+(spew_test.customError) error: 3: (int) 3
+}
+`
+ if s != expected {
+ t.Errorf("Sorted keys mismatch:\n %v %v", s, expected)
+ }
+
}