File: sharedbytes_test.go

package info (click to toggle)
golang-github-pingcap-kvproto 6.1.0~alpha-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,040 kB
  • sloc: sh: 111; makefile: 34
file content (30 lines) | stat: -rw-r--r-- 516 bytes parent folder | download
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")
	}
}