Debian Codegraph @

internal/spew/internal_test.go

raw
1 /*
2 * Copyright (c) 2013-2016 Dave Collins <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 /*
18 This test file is part of the spew package rather than than the spew_test
19 package because it needs access to internals to properly test certain cases
20 which are not possible via the public interface since they should never happen.
21 */
22
23 package spew
24
25 import (
26 "reflect"
27 "strings"
28 "testing"
29 )
30
31 // TestInvalidReflectValue ensures the dump and formatter code handles an
32 // invalid reflect value properly. This needs access to internal state since it
33 // should never happen in real code and therefore can't be tested via the public
34 // API.
35 func TestInvalidReflectValue(t *testing.T) {
36 // Dump invalid reflect value.
37 v := new(reflect.Value)
38 var buf strings.Builder
39 d := dumpState{w: &buf, cs: &Config}
40 d.dump(*v)
41 s := buf.String()
42 want := "<invalid>"
43 if s != want {
44 t.Errorf("InvalidReflectValue\n got: %s want: %s", s, want)
45 }
46 }