diff options
| author | Shulhan <ms@kilabit.info> | 2019-02-06 17:00:48 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-02-06 17:00:48 +0700 |
| commit | 5ce95fe490f66bde5b805abac7fe2786166b482b (patch) | |
| tree | df953b621ebacc481fea4eed1b54f962b6ed9258 /lib/bytes/bytes_test.go | |
| parent | 90fc696b6ac2e8e1c1ebb06fb518a3502f5749f2 (diff) | |
| download | pakakeh.go-5ce95fe490f66bde5b805abac7fe2786166b482b.tar.xz | |
lib/bytes: add function to convert hexadecimal into byte
Diffstat (limited to 'lib/bytes/bytes_test.go')
| -rw-r--r-- | lib/bytes/bytes_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/bytes/bytes_test.go b/lib/bytes/bytes_test.go index 3b79aced..2e1b3a24 100644 --- a/lib/bytes/bytes_test.go +++ b/lib/bytes/bytes_test.go @@ -164,6 +164,52 @@ func TestIsTokenAt(t *testing.T) { } } +func TestReadHexByte(t *testing.T) { + cases := []struct { + in []byte + exp byte + expOK bool + }{{ + in: []byte{}, + }, { + in: []byte("x0"), + }, { + in: []byte("0x"), + }, { + in: []byte("00"), + expOK: true, + }, { + in: []byte("01"), + exp: 1, + expOK: true, + }, { + in: []byte("10"), + exp: 16, + expOK: true, + }, { + in: []byte("1A"), + exp: 26, + expOK: true, + }, { + in: []byte("1a"), + exp: 26, + expOK: true, + }, { + in: []byte("a1"), + exp: 161, + expOK: true, + }} + + for _, c := range cases { + t.Log(c.in) + + got, ok := ReadHexByte(c.in, 0) + + test.Assert(t, "b", c.exp, got, true) + test.Assert(t, "ok", c.expOK, ok, true) + } +} + func TestSkipAfterToken(t *testing.T) { line := []byte(`abc \def ghi`) |
