package hexutil import ( "bytes" "testing" ) func TestDecode(t *testing.T) { want := []byte{0x45, 0x00, 0x00, 0x3c} for _, in := range []string{ "4500003c", "45 00 00 3c", "45:00:00:3C", "45-00-00-3c", "0x45, 0x00, 0x00, 0x3c", `\x45\x00\x00\x3c`, "4500\n003c\n", " 45\t00 00\r\n3c ", } { got, err := Decode(in) if err != nil { t.Errorf("Decode(%q): %v", in, err) continue } if !bytes.Equal(got, want) { t.Errorf("Decode(%q) = %x, want %x", in, got, want) } } } func TestDecodeEmpty(t *testing.T) { got, err := Decode(" \n ") if err != nil || len(got) != 0 { t.Errorf("Decode(blank) = %x, %v", got, err) } } func TestDecodeErrors(t *testing.T) { for _, in := range []string{"450", "45 0g", "45 00 zz"} { if _, err := Decode(in); err == nil { t.Errorf("Decode(%q): expected error", in) } } }