func BenchmarkInt16LE(b *testing.B) { d := enc.New(make([]uint8, 16)) b.ResetTimer() for i := 0; i < b.N; i++ { d.LE.PutInt16(-1) d.Reset() } }
func BenchmarkReset(b *testing.B) { buf := makeRndBuf() d := enc.New(buf) b.ResetTimer() for i := 0; i < b.N; i++ { d.Reset() } }
func BenchmarkPutStringDelim(b *testing.B) { buf := makeRndBuf() d := enc.New(buf) b.ResetTimer() for i := 0; i < b.N; i++ { d.PutStringDelim("Hello, 世界\x23\x10", '\x00') d.Reset() } }
func BenchmarkFill(b *testing.B) { buf := makeRndBuf() d := enc.New(buf) b.ResetTimer() for i := 0; i < b.N; i++ { d.Fill(0xff, len(buf)) d.Reset() } }
func TestPutString(t *testing.T) { buf := makeRndBuf() d := enc.New(buf) d.PutString("Hello, 世界\x23\x10\x00") if !bytes.Equal(buf, tExp) { t.Logf("act(%#v) != exp(%#v)", buf, tExp) t.Fail() } }
func TestInt64LE(t *testing.T) { buf := make([]uint8, 16) d := enc.New(buf) for _, u64 := range tU64LE { d.LE.PutInt64(int64(u64)) } if !bytes.Equal(buf, tExp) { t.Logf("act(%#v) != exp(%#v)", buf, tExp) t.Fail() } }
func TestFill(t *testing.T) { exp := []uint8{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} buf := makeRndBuf() d := enc.New(buf) d.Fill(0xff, len(buf)) if !bytes.Equal(buf, exp) { t.Logf("act(%#v) != exp(%#v)", buf, exp) t.Fail() } }
func TestRemaining(t *testing.T) { buf := makeRndBuf() d := enc.New(buf) for _, u8 := range tU8 { d.BE.PutUint8(u8) } if d.Remaining() != 0 { t.Logf("act(0x%02x) != exp(0x00)", d.Remaining()) t.Fail() } }
func TestInt32BE(t *testing.T) { buf := make([]uint8, 16) d := enc.New(buf) for _, u32 := range tU32BE { d.BE.PutInt32(int32(u32)) } if !bytes.Equal(buf, tExp) { t.Logf("act(%#v) != exp(%#v)", buf, tExp) t.Fail() } }
func TestWrite(t *testing.T) { buf := makeRndBuf() d := enc.New(buf) n, err := d.Write(tU8) if n != len(buf) { t.Logf("n_act(%#v) != n_exp(%#v)", n, len(buf)) t.Fail() } if err != nil { t.Logf("err_act(%#v) != err_exp(%#v)", err, nil) t.Fail() } if !bytes.Equal(buf, tU8) { t.Logf("act(%#v) != exp(%#v)", buf, tU8) t.Fail() } }