diff options
| author | Dave Collins <[email protected]> | 2013-01-20 17:53:55 -0600 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2013-01-20 17:53:55 -0600 |
| commit | 44d9c97c1ac1c523122fc4f0db8c0c364a3d1d45 (patch) | |
| tree | 9e77d88379f16a44f23e4c7ab0c1f7175d609a24 | |
| parent | 6024e0c79eec3c66cc3e1807fc6169800d3c53ea (diff) | |
Add tests for disable method options.
This commit adds tests for the DisableMethods and DisablePointerMethods
options. All combinations of method options and Stringer interface
invocation for both pointer receivers and non-pointer receivers are
tested.
| -rw-r--r-- | spew/common_test.go | 9 | ||||
| -rw-r--r-- | spew/spew_test.go | 16 |
2 files changed, 25 insertions, 0 deletions
diff --git a/spew/common_test.go b/spew/common_test.go index f0119e6..4b786e6 100644 --- a/spew/common_test.go +++ b/spew/common_test.go @@ -20,6 +20,15 @@ import ( "fmt" ) +// custom type to test Stinger interface on non-pointer receiver. +type stringer string + +// String implements the Stringer interface for testing invocation of custom +// stringers on types with non-pointer receivers. +func (s stringer) String() string { + return "stringer " + string(s) +} + // custom type to test Stinger interface on pointer receiver. type pstringer string diff --git a/spew/spew_test.go b/spew/spew_test.go index e6677dc..a8cf33e 100644 --- a/spew/spew_test.go +++ b/spew/spew_test.go @@ -25,7 +25,15 @@ import ( "testing" ) +// Config states with various settings. var scsDefault = spew.NewDefaultConfig() +var scsNoMethods = &spew.ConfigState{Indent: " ", DisableMethods: true} +var scsNoPmethods = &spew.ConfigState{Indent: " ", DisablePointerMethods: true} + +// Variables for tests on types which implement Stringer interface with and +// without a pointer receiver. +var ts = stringer("test") +var tps = pstringer("test") // spewFunc is used to identify which public function of the spew package or // ConfigState a test applies to. @@ -101,6 +109,14 @@ var spewTests = []spewTest{ {scsDefault, fFprintln, "", float64(6.28), "6.28\n"}, {scsDefault, fPrint, "", true, "true"}, {scsDefault, fPrintln, "", false, "false\n"}, + {scsNoMethods, fCSFprint, "", ts, "test"}, + {scsNoMethods, fCSFprint, "", &ts, "<*>test"}, + {scsNoMethods, fCSFprint, "", tps, "test"}, + {scsNoMethods, fCSFprint, "", &tps, "<*>test"}, + {scsNoPmethods, fCSFprint, "", ts, "stringer test"}, + {scsNoPmethods, fCSFprint, "", &ts, "<*>stringer test"}, + {scsNoPmethods, fCSFprint, "", tps, "test"}, + {scsNoPmethods, fCSFprint, "", &tps, "<*>stringer test"}, } // redirStdout is a helper function to return the standard output from f as a |
