internal/testutil: Describe no longer panics on private struct fields
This commit is contained in:
parent
f6b12d43fb
commit
b2504cda2d
@ -2,8 +2,9 @@ package testutil
|
||||
|
||||
import "fmt"
|
||||
import "slices"
|
||||
import "strings"
|
||||
import "reflect"
|
||||
import "strings"
|
||||
import "unicode"
|
||||
|
||||
// Snake lets you compare blocks of data where the ordering of certain parts may
|
||||
// be swapped every which way. It is designed for comparing the encoding of
|
||||
@ -141,8 +142,16 @@ func (this *describer) describe(value reflect.Value) {
|
||||
typ := value.Type()
|
||||
for index := range typ.NumField() {
|
||||
indexBuffer := [1]int { index }
|
||||
this.iprintf("%s: ", typ.Field(index).Name)
|
||||
this.describe(value.FieldByIndex(indexBuffer[:]))
|
||||
field := typ.Field(index)
|
||||
this.iprintf("%s: ", field.Name)
|
||||
for _, char := range field.Name {
|
||||
if unicode.IsUpper(char) {
|
||||
this.describe(value.FieldByIndex(indexBuffer[:]))
|
||||
} else {
|
||||
this.printf("<private>")
|
||||
}
|
||||
break
|
||||
}
|
||||
this.iprintf("\n")
|
||||
}
|
||||
this.indent -= 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user