summaryrefslogtreecommitdiff
path: root/spew/dump_test.go
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2013-01-20 12:02:36 -0600
committerDave Collins <[email protected]>2013-01-20 12:02:36 -0600
commit5c8d842977941cdb1663827b8c6a93046e211bbb (patch)
tree2da421934d0d0c93e15c5d1a195945c5f472437b /spew/dump_test.go
parent1c16a20c214d354cf84ca9646c73fc78b0620f7e (diff)
Add tests for maps with multiple entries.
Previously, the tests did not include maps with more than a single entry since the iteration order is randomized and the tests only accepted a single valid expected value. This commit modifies the tests to accept multiple valid expected values and adds tests for a multi-entry map to both Dump and Formatter.
Diffstat (limited to 'spew/dump_test.go')
-rw-r--r--spew/dump_test.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/spew/dump_test.go b/spew/dump_test.go
index 06e796c..f3c033b 100644
--- a/spew/dump_test.go
+++ b/spew/dump_test.go
@@ -94,8 +94,8 @@ type indirCir3 struct {
// dumpTest is used to describe a test to be perfomed against the Dump method.
type dumpTest struct {
- in interface{}
- want string
+ in interface{}
+ wants []string
}
// dumpTests houses all of the tests to be performed against the Dump method.
@@ -103,8 +103,8 @@ var dumpTests = make([]dumpTest, 0)
// addDumpTest is a helper method to append the passed input and desired result
// to dumpTests
-func addDumpTest(in interface{}, want string) {
- test := dumpTest{in, want}
+func addDumpTest(in interface{}, wants ...string) {
+ test := dumpTest{in, wants}
dumpTests = append(dumpTests, test)
}
@@ -448,7 +448,7 @@ func addNilInterfaceDumpTests() {
func addMapDumpTests() {
// Map with string keys and int vals.
- v := map[string]int{"one": 1}
+ v := map[string]int{"one": 1, "two": 2}
nv := (*map[string]int)(nil)
pv := &v
vAddr := fmt.Sprintf("%p", pv)
@@ -456,10 +456,15 @@ func addMapDumpTests() {
vt := "map[string]int"
vt1 := "string"
vt2 := "int"
- vs := "{\n (" + vt1 + ") \"one\": (" + vt2 + ") 1\n}"
- addDumpTest(v, "("+vt+") "+vs+"\n")
- addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
- addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
+ vs := "{\n (" + vt1 + ") \"one\": (" + vt2 + ") 1,\n (" + vt1 +
+ ") \"two\": (" + vt2 + ") 2\n}"
+ vs2 := "{\n (" + vt1 + ") \"two\": (" + vt2 + ") 2,\n (" + vt1 +
+ ") \"one\": (" + vt2 + ") 1\n}"
+ addDumpTest(v, "("+vt+") "+vs+"\n", "("+vt+") "+vs2+"\n")
+ addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n",
+ "(*"+vt+")("+vAddr+")("+vs2+")\n")
+ addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n",
+ "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs2+")\n")
addDumpTest(nv, "(*"+vt+")(<nil>)\n")
// Map with custom formatter type on pointer receiver only keys and vals.
@@ -768,8 +773,8 @@ func TestDump(t *testing.T) {
buf := new(bytes.Buffer)
spew.Fdump(buf, test.in)
s := buf.String()
- if test.want != s {
- t.Errorf("Dump #%d\n got: %s want: %s", i, s, test.want)
+ if testFailed(s, test.wants) {
+ t.Errorf("Dump #%d\n got: %s %s", i, s, stringizeWants(test.wants))
continue
}
}