Browse Source

Add error tests

master
Blink The Things 3 years ago
parent
commit
a0f867aadc
1 changed files with 37 additions and 0 deletions
  1. +37
    -0
      modhex_test.go

+ 37
- 0
modhex_test.go View File

@ -87,3 +87,40 @@ func TestDecodeString(t *testing.T) {
}
}
}
type errTest struct {
in string
out string
err error
}
var errTests = []errTest{
{"", "", nil},
{"c", "", ErrLength},
{"zteff", "", InvalidByteError('z')},
{"dtefz", "\x2d\x34", InvalidByteError('z')},
{"ecebe", "01", ErrLength},
{"cq", "", InvalidByteError('q')},
{"ccqq", "\x00", InvalidByteError('q')},
{"c\x01", "", InvalidByteError('\x01')},
{"vvuut", "\xff\xee", ErrLength},
}
func TestDecodeErr(t *testing.T) {
for i, test := range errTests {
out := make([]byte, len(test.in)+10)
n, err := Decode(out, []byte(test.in))
if string(out[:n]) != test.out || err != test.err {
t.Errorf("#%d: Decode(%q) = %q, %v, want %q, %v", i, test.in, string(out[:n]), err, test.out, test.err)
}
}
}
func TestDecodeStringErr(t *testing.T) {
for i, test := range errTests {
out, err := DecodeString(test.in)
if string(out) != test.out || err != test.err {
t.Errorf("#%d: DecodeString(%q) = %q, %v, want %q, %v", i, test.in, out, err, test.out, test.err)
}
}
}

Loading…
Cancel
Save