diff --git a/spew/internal_test.go b/spew/internal_test.go index 7a872e4..05bab97 100644 --- a/spew/internal_test.go +++ b/spew/internal_test.go @@ -26,6 +26,7 @@ import ( "bytes" "reflect" "testing" + "unsafe" ) // dummyFmtState implements a fake fmt.State to use for testing invalid @@ -79,3 +80,78 @@ func TestInvalidReflectValue(t *testing.T) { t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want) } } + +// flagRO, flagKindShift and flagKindWidth indicate various bit flags that the +// reflect package uses internally to track kind and state information. +const flagRO = 1 << 0 +const flagKindShift = 4 +const flagKindWidth = 5 + +// changeKind uses unsafe to intentionally change the kind of a reflect.Value to +// the maximum kind value which does not exist. This is needed to test the +// fallback code which punts to the standard fmt library for new types that +// might get added to the language. +func changeKind(v *reflect.Value, readOnly bool) { + rvf := (*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + + unsafe.Offsetof(reflectValue.flag))) + *rvf = *rvf | ((1<