Add tests for sub-interfaces.

This commit is contained in:
Dave Collins 2013-01-20 15:27:57 -06:00
parent eba42209a7
commit 3ad8c5b5ee
2 changed files with 37 additions and 4 deletions

View File

@ -31,6 +31,7 @@ base test element are also tested to ensure proper indirection across all types.
- Slice containing interfaces - Slice containing interfaces
- Standard string - Standard string
- Nil interface - Nil interface
- Sub-interface
- Map with string keys and int vals - Map with string keys and int vals
- Map with custom formatter type on pointer receiver only keys and vals - Map with custom formatter type on pointer receiver only keys and vals
- Map with interface keys and values - Map with interface keys and values
@ -402,7 +403,7 @@ func addStringDumpTests() {
addDumpTest(nv, "(*"+vt+")(<nil>)\n") addDumpTest(nv, "(*"+vt+")(<nil>)\n")
} }
func addNilInterfaceDumpTests() { func addInterfaceDumpTests() {
// Nil interface. // Nil interface.
var v interface{} var v interface{}
nv := (*interface{})(nil) nv := (*interface{})(nil)
@ -415,6 +416,17 @@ func addNilInterfaceDumpTests() {
addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
addDumpTest(nv, "(*"+vt+")(<nil>)\n") addDumpTest(nv, "(*"+vt+")(<nil>)\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() { func addMapDumpTests() {
@ -760,7 +772,7 @@ func TestDump(t *testing.T) {
addArrayDumpTests() addArrayDumpTests()
addSliceDumpTests() addSliceDumpTests()
addStringDumpTests() addStringDumpTests()
addNilInterfaceDumpTests() addInterfaceDumpTests()
addMapDumpTests() addMapDumpTests()
addStructDumpTests() addStructDumpTests()
addUintptrDumpTests() addUintptrDumpTests()

View File

@ -31,6 +31,7 @@ base test element are also tested to ensure proper indirection across all types.
- Slice containing interfaces - Slice containing interfaces
- Standard string - Standard string
- Nil interface - Nil interface
- Sub-interface
- Map with string keys and int vals - Map with string keys and int vals
- Map with custom formatter type on pointer receiver only keys and vals - Map with custom formatter type on pointer receiver only keys and vals
- Map with interface keys and values - Map with interface keys and values
@ -681,7 +682,7 @@ func addStringFormatterTests() {
addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>") addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")
} }
func addNilInterfaceFormatterTests() { func addInterfaceFormatterTests() {
// Nil interface. // Nil interface.
var v interface{} var v interface{}
nv := (*interface{})(nil) nv := (*interface{})(nil)
@ -706,6 +707,26 @@ func addNilInterfaceFormatterTests() {
addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)
addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)
addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>") addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")
// 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() { func addMapFormatterTests() {
@ -1335,7 +1356,7 @@ func TestFormatter(t *testing.T) {
addArrayFormatterTests() addArrayFormatterTests()
addSliceFormatterTests() addSliceFormatterTests()
addStringFormatterTests() addStringFormatterTests()
addNilInterfaceFormatterTests() addInterfaceFormatterTests()
addMapFormatterTests() addMapFormatterTests()
addStructFormatterTests() addStructFormatterTests()
addUintptrFormatterTests() addUintptrFormatterTests()