summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2013-09-09 20:42:50 -0500
committerDave Collins <[email protected]>2013-09-09 20:43:39 -0500
commit8f603f64f931c41a1b91b27f6a595fc542557579 (patch)
tree15eb0845cf5240f419d13bc8c494f0750ecb7de3
parent7ea732c827c17c2e5cf8655aac42e3abe058ef17 (diff)
Add tests for nil slice change.
This commit adds tests for the nil slice change.
-rw-r--r--spew/dump_test.go14
-rw-r--r--spew/format_test.go26
2 files changed, 40 insertions, 0 deletions
diff --git a/spew/dump_test.go b/spew/dump_test.go
index b15517c..3a50650 100644
--- a/spew/dump_test.go
+++ b/spew/dump_test.go
@@ -31,6 +31,7 @@ base test element are also tested to ensure proper indirection across all types.
- Slice containing type with custom formatter on pointer receiver only
- Slice containing interfaces
- Slice containing bytes
+- Nil slice
- Standard string
- Nil interface
- Sub-interface
@@ -439,6 +440,19 @@ func addSliceDumpTests() {
addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
+
+ // Nil slice.
+ v5 := []int(nil)
+ nv5 := (*[]int)(nil)
+ pv5 := &v5
+ v5Addr := fmt.Sprintf("%p", pv5)
+ pv5Addr := fmt.Sprintf("%p", &pv5)
+ v5t := "[]int"
+ v5s := "<nil>"
+ addDumpTest(v5, "("+v5t+") "+v5s+"\n")
+ addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n")
+ addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n")
+ addDumpTest(nv5, "(*"+v5t+")(<nil>)\n")
}
func addStringDumpTests() {
diff --git a/spew/format_test.go b/spew/format_test.go
index c6436fc..b151513 100644
--- a/spew/format_test.go
+++ b/spew/format_test.go
@@ -29,6 +29,7 @@ base test element are also tested to ensure proper indirection across all types.
- Slice containing standard float32 values
- Slice containing type with custom formatter on pointer receiver only
- Slice containing interfaces
+- Nil slice
- Standard string
- Nil interface
- Sub-interface
@@ -657,6 +658,31 @@ func addSliceFormatterTests() {
addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2)
addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2)
addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")
+
+ // Nil slice.
+ var v4 []int
+ nv4 := (*[]int)(nil)
+ pv4 := &v4
+ v4Addr := fmt.Sprintf("%p", pv4)
+ pv4Addr := fmt.Sprintf("%p", &pv4)
+ v4t := "[]int"
+ v4s := "<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+")"+v4s)
+ addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s)
+ addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s)
+ addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")
+ addFormatterTest("%#+v", v4, "("+v4t+")"+v4s)
+ addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s)
+ addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s)
+ addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")
}
func addStringFormatterTests() {