From 5c8d842977941cdb1663827b8c6a93046e211bbb Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 20 Jan 2013 12:02:36 -0600 Subject: Add tests for maps with multiple entries. Previously, the tests did not include maps with more than a single entry since the iteration order is randomized and the tests only accepted a single valid expected value. This commit modifies the tests to accept multiple valid expected values and adds tests for a multi-entry map to both Dump and Formatter. --- spew/spew_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'spew/spew_test.go') diff --git a/spew/spew_test.go b/spew/spew_test.go index d2d620e..406edc1 100644 --- a/spew/spew_test.go +++ b/spew/spew_test.go @@ -25,6 +25,31 @@ import ( "testing" ) +// stringizeWants converts a slice of wanted test output into a format suitable +// for an test error message. +func stringizeWants(wants []string) string { + s := "" + for i, want := range wants { + if i > 0 { + s += fmt.Sprintf("want%d: %s", i+1, want) + } else { + s += "want: " + want + } + } + return s +} + +// testFailed returns whether or not a test failed by checking if the result +// of the test is in the slice of wanted strings. +func testFailed(result string, wants []string) bool { + for _, want := range wants { + if result == want { + return false + } + } + return true +} + // spewFunc is used to identify which public function of the spew package or // ConfigState a test applies to. type spewFunc int -- cgit v1.2.3