summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2013-03-27 22:44:40 -0500
committerDave Collins <[email protected]>2013-03-27 22:50:10 -0500
commit3bcb0679afb9eb38768baf9e19de234d8480f6aa (patch)
tree41feb6984e0f77ea524ed7444f4a5b881a590237
parent173295b96ea124eed74b2d172c109a1fc8043b37 (diff)
Add tests for packed nil interfaces.
This commit adds tests for nil interfaces packed inside maps and slices to test the recently added fix for issue #12.
-rw-r--r--spew/dump_test.go22
-rw-r--r--spew/format_test.go36
2 files changed, 53 insertions, 5 deletions
diff --git a/spew/dump_test.go b/spew/dump_test.go
index 4a999cb..b15517c 100644
--- a/spew/dump_test.go
+++ b/spew/dump_test.go
@@ -37,6 +37,7 @@ base test element are also tested to ensure proper indirection across all types.
- Map with string keys and int vals
- Map with custom formatter type on pointer receiver only keys and vals
- Map with interface keys and values
+- Map with nil interface value
- Struct with primitives
- Struct that contains another struct
- Struct that contains custom type with Stringer pointer interface via both
@@ -398,7 +399,7 @@ func addSliceDumpTests() {
addDumpTest(nv2, "(*[]"+v2t+")(<nil>)\n")
// Slice containing interfaces.
- v3 := []interface{}{"one", int(2), uint(3)}
+ v3 := []interface{}{"one", int(2), uint(3), nil}
nv3 := (*[]interface{})(nil)
pv3 := &v3
v3Addr := fmt.Sprintf("%p", pv3)
@@ -407,8 +408,9 @@ func addSliceDumpTests() {
v3t2 := "string"
v3t3 := "int"
v3t4 := "uint"
+ v3t5 := "interface {}"
v3s := "{\n (" + v3t2 + ") \"one\",\n (" + v3t3 + ") 2,\n (" + v3t4 +
- ") 3\n}"
+ ") 3,\n (" + v3t5 + ") <nil>\n}"
addDumpTest(v3, "("+v3t+") "+v3s+"\n")
addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
@@ -530,6 +532,22 @@ func addMapDumpTests() {
addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
+
+ // Map with nil interface value.
+ v4 := map[string]interface{}{"nil": nil}
+ nv4 := (*map[string]interface{})(nil)
+ pv4 := &v4
+ v4Addr := fmt.Sprintf("%p", pv4)
+ pv4Addr := fmt.Sprintf("%p", &pv4)
+ v4t := "map[string]interface {}"
+ v4t1 := "string"
+ v4t2 := "interface {}"
+ v4s := "{\n (" + v4t1 + ") \"nil\": (" + v4t2 + ") <nil>\n}"
+ addDumpTest(v4, "("+v4t+") "+v4s+"\n")
+ addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
+ addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
+ addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
+
}
func addStructDumpTests() {
diff --git a/spew/format_test.go b/spew/format_test.go
index 36c27cb..c6436fc 100644
--- a/spew/format_test.go
+++ b/spew/format_test.go
@@ -35,6 +35,7 @@ base test element are also tested to ensure proper indirection across all types.
- Map with string keys and int vals
- Map with custom formatter type on pointer receiver only keys and vals
- Map with interface keys and values
+- Map with nil interface value
- Struct with primitives
- Struct that contains another struct
- Struct that contains custom type with Stringer pointer interface via both
@@ -627,7 +628,7 @@ func addSliceFormatterTests() {
addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")
// Slice containing interfaces.
- v3 := []interface{}{"one", int(2), uint(3)}
+ v3 := []interface{}{"one", int(2), uint(3), nil}
nv3 := (*[]interface{})(nil)
pv3 := &v3
v3Addr := fmt.Sprintf("%p", pv3)
@@ -636,8 +637,10 @@ func addSliceFormatterTests() {
v3t2 := "string"
v3t3 := "int"
v3t4 := "uint"
- v3s := "[one 2 3]"
- v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3]"
+ v3t5 := "interface {}"
+ v3s := "[one 2 3 <nil>]"
+ v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3 (" + v3t5 +
+ ")<nil>]"
addFormatterTest("%v", v3, v3s)
addFormatterTest("%v", pv3, "<*>"+v3s)
addFormatterTest("%v", &pv3, "<**>"+v3s)
@@ -812,6 +815,33 @@ func addMapFormatterTests() {
addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2)
addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2)
addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")
+
+ // Map with nil interface value
+ v4 := map[string]interface{}{"nil": nil}
+ nv4 := (*map[string]interface{})(nil)
+ pv4 := &v4
+ v4Addr := fmt.Sprintf("%p", pv4)
+ pv4Addr := fmt.Sprintf("%p", &pv4)
+ v4t := "map[string]interface {}"
+ v4t1 := "interface {}"
+ v4s := "map[nil:<nil>]"
+ v4s2 := "map[nil:(" + v4t1 + ")<nil>]"
+ addFormatterTest("%v", v4, v4s)
+ addFormatterTest("%v", pv4, "<*>"+v4s)
+ addFormatterTest("%v", &pv4, "<**>"+v4s)
+ addFormatterTest("%+v", nv4, "<nil>")
+ addFormatterTest("%+v", v4, v4s)
+ addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s)
+ addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s)
+ addFormatterTest("%+v", nv4, "<nil>")
+ addFormatterTest("%#v", v4, "("+v4t+")"+v4s2)
+ addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s2)
+ addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s2)
+ addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")
+ addFormatterTest("%#+v", v4, "("+v4t+")"+v4s2)
+ addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s2)
+ addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s2)
+ addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")
}
func addStructFormatterTests() {