diff options
| author | Dave Collins <[email protected]> | 2013-01-20 15:27:57 -0600 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2013-01-20 15:27:57 -0600 |
| commit | 3ad8c5b5ee3022c33dbe6689a1f82e5169f6e1e8 (patch) | |
| tree | 1a9753761305ab7769b4d67f57f9084902aa3b09 /spew/format_test.go | |
| parent | eba42209a79e61d85602324c3afefe02a29d2afc (diff) | |
Add tests for sub-interfaces.
Diffstat (limited to 'spew/format_test.go')
| -rw-r--r-- | spew/format_test.go | 25 |
1 files changed, 23 insertions, 2 deletions
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+")"+"<nil>") } -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+")"+"<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() { @@ -1335,7 +1356,7 @@ func TestFormatter(t *testing.T) { addArrayFormatterTests() addSliceFormatterTests() addStringFormatterTests() - addNilInterfaceFormatterTests() + addInterfaceFormatterTests() addMapFormatterTests() addStructFormatterTests() addUintptrFormatterTests() |
