diff options
| author | Dave Collins <[email protected]> | 2013-01-20 22:24:52 -0600 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2013-01-20 22:24:52 -0600 |
| commit | 3b5249e43ec83523352aa525755535deff059be7 (patch) | |
| tree | 0cfdf5f6a8b46e040d95a6cd320f7e89b033821c /spew/internal_test.go | |
| parent | 23b797ffdfc118c96d3479162fb131ac1891c4eb (diff) | |
Consolidate tests for invalid reflect values.
Diffstat (limited to 'spew/internal_test.go')
| -rw-r--r-- | spew/internal_test.go | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/spew/internal_test.go b/spew/internal_test.go index 8e6e54d..7a872e4 100644 --- a/spew/internal_test.go +++ b/spew/internal_test.go @@ -36,6 +36,9 @@ type dummyFmtState struct { } func (dfs *dummyFmtState) Flag(f int) bool { + if f == int('+') { + return true + } return false } @@ -47,10 +50,14 @@ func (dfs *dummyFmtState) Width() (int, bool) { return 0, false } -// TestDumpInvalidReflectValue ensures the dump code handles an invalid reflect -// value properly. This needs access to internal state since it should never -// happen in real code and therefore can't be tested via the public API. -func TestDumpInvalidReflectValue(t *testing.T) { +// TestInvalidReflectValue ensures the dump and formatter code handles an +// invalid reflect value properly. This needs access to internal state since it +// should never happen in real code and therefore can't be tested via the public +// API. +func TestInvalidReflectValue(t *testing.T) { + i := 1 + + // Dump invalid reflect value. v := new(reflect.Value) buf := new(bytes.Buffer) d := dumpState{w: buf, cs: &Config} @@ -58,22 +65,17 @@ func TestDumpInvalidReflectValue(t *testing.T) { s := buf.String() want := "<invalid>" if s != want { - t.Errorf("DumpInvalidReflectValue\n got: %s want: %s", s, want) + t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want) } -} + i++ -// TestFormatterInvalidReflectValue ensures the formatter code handles an -// invalid reflect value properly. This needs access to internal state since it -// should never happen in real code and therefore can't be tested via the public -// API. -func TestFormatterInvalidReflectValue(t *testing.T) { - v := new(reflect.Value) - buf := new(dummyFmtState) - f := formatState{value: *v, cs: &Config, fs: buf} + // Formatter invalid reflect value. + buf2 := new(dummyFmtState) + f := formatState{value: *v, cs: &Config, fs: buf2} f.format(*v) - s := buf.String() - want := "<invalid>" + s = buf2.String() + want = "<invalid>" if s != want { - t.Errorf("FormatterInvalidReflectValue\n got: %s want: %s", s, want) + t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want) } } |
