diff --git a/_assertauto/TestConfig/ByteserHexReflectValue.json b/_assertauto/TestConfig/ByteserHexReflectValue.json new file mode 100644 index 0000000..bae98f3 --- /dev/null +++ b/_assertauto/TestConfig/ByteserHexReflectValue.json @@ -0,0 +1,10 @@ +{ + "entries": [ + { + "equal": "(reflect.Value) => (int) 123" + }, + { + "equal": 0 + } + ] +} diff --git a/_assertauto/TestConfig/StringerReflectValue.json b/_assertauto/TestConfig/StringerReflectValue.json new file mode 100644 index 0000000..bae98f3 --- /dev/null +++ b/_assertauto/TestConfig/StringerReflectValue.json @@ -0,0 +1,10 @@ +{ + "entries": [ + { + "equal": "(reflect.Value) => (int) 123" + }, + { + "equal": 0 + } + ] +} diff --git a/pretty.go b/pretty.go index f25a3a6..e70d1b5 100644 --- a/pretty.go +++ b/pretty.go @@ -713,6 +713,9 @@ func writeByteserHex(c *Config, w io.Writer, st *State, v reflect.Value, maxLen if v.Kind() == reflect.Pointer && v.IsNil() { return false } + if v.Type() == typeReflectValue { + return false + } br := v.Interface().(byteser) //nolint:forcetypeassert // Checked above. b := br.Bytes() writeArrowWrappedString(w, ".Bytes() ") @@ -764,6 +767,9 @@ func writeStringer(w io.Writer, v reflect.Value, maxLen int) bool { if v.Kind() == reflect.Pointer && v.IsNil() { return false } + if v.Type() == typeReflectValue { + return false + } sr := v.Interface().(fmt.Stringer) //nolint:forcetypeassert // Checked above. s := sr.String() writeArrowWrappedString(w, ".String() ") diff --git a/pretty_test.go b/pretty_test.go index e1b21fd..9c9b23f 100644 --- a/pretty_test.go +++ b/pretty_test.go @@ -445,6 +445,16 @@ var testCases = []testCase{ c.ValueWriters = []ValueWriter{NewByteserHexValueWriter(0)} }, }, + { + name: "ByteserHexReflectValue", + value: reflect.ValueOf(123), + configure: func(c *Config) { + c.ValueWriters = []ValueWriter{ + NewByteserHexValueWriter(0), + NewReflectValueValueWriter(), + } + }, + }, { name: "Error", value: &testError{}, @@ -494,6 +504,16 @@ var testCases = []testCase{ c.ValueWriters = []ValueWriter{NewStringerValueWriter(0)} }, }, + { + name: "StringerReflectValue", + value: reflect.ValueOf(123), + configure: func(c *Config) { + c.ValueWriters = []ValueWriter{ + NewStringerValueWriter(0), + NewReflectValueValueWriter(), + } + }, + }, { name: "FilterMatch", value: &testStringer{s: "test"},