internal/testutil: Snake.String and HexBytes return "EMPTY" when input is empty

This commit is contained in:
Sasha Koshka 2025-06-29 11:06:58 -04:00
parent 8f8cd91b5d
commit dcf923b1f3

View File

@ -64,6 +64,10 @@ func (sn Snake) Check(data []byte) (ok bool, n int) {
}
func (sn Snake) String() 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(" : ") }
@ -81,6 +85,7 @@ func (sn Snake) String() string {
// HexBytes formats bytes into a hexadecimal string.
func HexBytes(data []byte) string {
if len(data) == 0 { return "EMPTY" }
out := strings.Builder { }
for _, byt := range data {
fmt.Fprintf(&out, "%02x", byt)