internal/testutil: Add functions to dump printable chars
This commit is contained in:
parent
70fb106b48
commit
7bebc8c5eb
@ -97,6 +97,32 @@ func (sn Snake) String() string {
|
|||||||
return out.String()
|
return out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sn Snake) CharsString() string {
|
||||||
|
if len(sn) == 0 || len(sn[0]) == 0 || len(sn[0][0]) == 0 {
|
||||||
|
return "EMPTY"
|
||||||
|
}
|
||||||
|
|
||||||
|
out := strings.Builder { }
|
||||||
|
for index, sector := range sn {
|
||||||
|
if index > 0 { out.WriteString(" : ") }
|
||||||
|
out.WriteRune('[')
|
||||||
|
for index, variation := range sector {
|
||||||
|
if index > 0 { out.WriteString(" / ") }
|
||||||
|
for _, byt := range variation {
|
||||||
|
run := rune(byt)
|
||||||
|
if unicode.IsPrint(run) && run < 0x7F {
|
||||||
|
out.WriteRune(run)
|
||||||
|
} else {
|
||||||
|
out.WriteRune('.')
|
||||||
|
}
|
||||||
|
out.WriteRune(' ')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.WriteRune(']')
|
||||||
|
}
|
||||||
|
return out.String()
|
||||||
|
}
|
||||||
|
|
||||||
// HexBytes formats bytes into a hexadecimal string.
|
// HexBytes formats bytes into a hexadecimal string.
|
||||||
func HexBytes(data []byte) string {
|
func HexBytes(data []byte) string {
|
||||||
if len(data) == 0 { return "EMPTY" }
|
if len(data) == 0 { return "EMPTY" }
|
||||||