1 // Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3 // Permission to use, copy, modify, and distribute this software for any
4 // purpose with or without fee is hereby granted, provided that the above
5 // copyright notice and this permission notice appear in all copies.
7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 // NOTE: Due to the following build constraints, this file will only be compiled
16 // when the code is not running on Google App Engine, compiled by GopherJS, and
17 // "-tags safe" is not added to the go build command line. The "disableunsafe"
18 // tag is deprecated and thus should not be used.
19 // +build !js,!appengine,!safe,!disableunsafe
22 This test file is part of the spew package rather than than the spew_test
23 package because it needs access to internals to properly test certain cases
24 which are not possible via the public interface since they should never happen.
36 // changeKind uses unsafe to intentionally change the kind of a reflect.Value to
37 // the maximum kind value which does not exist. This is needed to test the
38 // fallback code which punts to the standard fmt library for new types that
39 // might get added to the language.
40 func changeKind(v *reflect.Value, readOnly bool) {
41 rvf := (*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + offsetFlag))
42 *rvf = *rvf | ((1<<flagKindWidth - 1) << flagKindShift)
46 *rvf &= ^uintptr(flagRO)
50 // TestAddedReflectValue tests functionaly of the dump and formatter code which
51 // falls back to the standard fmt library for new types that might get added to
53 func TestAddedReflectValue(t *testing.T) {
56 // Dump using a reflect.Value that is exported.
57 v := reflect.ValueOf(int8(5))
59 buf := new(bytes.Buffer)
60 d := dumpState{w: buf, cs: &Config}
65 t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
69 // Dump using a reflect.Value that is not exported.
74 want = "(int8) <int8 Value>"
76 t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
80 // Formatter using a reflect.Value that is exported.
82 buf2 := new(dummyFmtState)
83 f := formatState{value: v, cs: &Config, fs: buf2}
88 t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
92 // Formatter using a reflect.Value that is not exported.
95 f = formatState{value: v, cs: &Config, fs: buf2}
100 t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)