func BenchmarkRemaining(b *testing.B) { d := dec.New(tBuf) b.ResetTimer() for i := 0; i < b.N; i++ { d.Remaining() } }
func BenchmarkInt16BE(b *testing.B) { d := dec.New(tBuf) b.ResetTimer() for i := 0; i < b.N; i++ { d.BE.Int16() d.Reset() } }
func BenchmarkString(b *testing.B) { d := dec.New(tBuf) b.ResetTimer() for i := 0; i < b.N; i++ { d.String(len(tBuf)) d.Reset() } }
func TestString(t *testing.T) { d := dec.New(tBuf) act := d.String(len(tBuf)) exp := "Hello, 世界\x23\x10\x00" if act != exp { t.Logf("act('%s') != exp('%s')", act, exp) t.Fail() } }
func TestRemaining(t *testing.T) { d := dec.New(tBuf) for i := 0; i < len(tBuf); i++ { d.BE.Uint8() } if d.Remaining() != 0 { t.Logf("act(0x%02x) != exp(0x00)", d.Remaining()) t.Fail() } }
func TestInt64BE(t *testing.T) { d := dec.New(tBuf) i := 0 for d.Remaining() > 0 { exp := tExpU64BE[i] act := uint64(d.BE.Int64()) if act != exp { t.Logf("act(0x%16x) != exp(0x%16x)", act, exp) t.Fail() } i++ } }
func TestReset(t *testing.T) { d := dec.New(tBuf) for d.Remaining() > 0 { d.BE.Uint8() } d.Reset() if d.Remaining() != len(tBuf) { t.Logf("act(0x%02x) != exp(0x%02x)", d.Remaining(), len(tBuf)) t.Fail() } }
func TestInt32LE(t *testing.T) { d := dec.New(tBuf) i := 0 for d.Remaining() > 0 { exp := tExpU32LE[i] act := uint32(d.LE.Int32()) if act != exp { t.Logf("act(0x%08x) != exp(0x%08x)", act, exp) t.Fail() } i++ } }