diff --git a/spew/dump_test.go b/spew/dump_test.go index 0d282c2..abe0a28 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 interfaces - Standard string - Nil interface +- Sub-interface - 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 @@ -402,7 +403,7 @@ func addStringDumpTests() { addDumpTest(nv, "(*"+vt+")()\n") } -func addNilInterfaceDumpTests() { +func addInterfaceDumpTests() { // Nil interface. var v interface{} nv := (*interface{})(nil) @@ -415,6 +416,17 @@ func addNilInterfaceDumpTests() { addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") addDumpTest(nv, "(*"+vt+")()\n") + + // Sub-interface. + v2 := interface{}(uint16(65535)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") } func addMapDumpTests() { @@ -760,7 +772,7 @@ func TestDump(t *testing.T) { addArrayDumpTests() addSliceDumpTests() addStringDumpTests() - addNilInterfaceDumpTests() + addInterfaceDumpTests() addMapDumpTests() addStructDumpTests() addUintptrDumpTests() diff --git a/spew/format_test.go b/spew/format_test.go index cbc3bd7..d5b43b5 100644 --- a/spew/format_test.go +++ b/spew/format_test.go @@ -31,6 +31,7 @@ base test element are also tested to ensure proper indirection across all types. - Slice containing interfaces - Standard string - Nil interface +- Sub-interface - 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 @@ -681,7 +682,7 @@ func addStringFormatterTests() { addFormatterTest("%#+v", nv, "(*"+vt+")"+"") } -func addNilInterfaceFormatterTests() { +func addInterfaceFormatterTests() { // Nil interface. var v interface{} nv := (*interface{})(nil) @@ -706,6 +707,26 @@ func addNilInterfaceFormatterTests() { addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Sub-interface. + v2 := interface{}(uint16(65535)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) } func addMapFormatterTests() { @@ -1335,7 +1356,7 @@ func TestFormatter(t *testing.T) { addArrayFormatterTests() addSliceFormatterTests() addStringFormatterTests() - addNilInterfaceFormatterTests() + addInterfaceFormatterTests() addMapFormatterTests() addStructFormatterTests() addUintptrFormatterTests()