1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
package sharedbytes
import (
"bytes"
"testing"
)
func TestShardBytes(t *testing.T) {
var sb SharedBytes
sb = []byte("abc")
x, err := sb.Marshal()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(x, []byte("abc")) {
t.Fatal("marshal failed")
}
x = make([]byte, 3)
sb.MarshalTo(x)
if !bytes.Equal(x, []byte("abc")) {
t.Fatal("marshal failed")
}
sb = nil
if err := sb.Unmarshal([]byte("abc")); err != nil {
t.Fatal(err)
}
if !bytes.Equal(sb, []byte("abc")) {
t.Fatal("unmarshal failed")
}
}
|