This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodec_test.go
More file actions
51 lines (47 loc) · 1.65 KB
/
codec_test.go
File metadata and controls
51 lines (47 loc) · 1.65 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"testing"
)
func TestEncodeBytes(t *testing.T) {
a := EncodeBytes([]byte("aaa"))
b := EncodeBytes([]byte("bbb"))
newA := []byte{97, 97, 97, 0, 0, 0, 0, 0, 250}
newB := []byte{98, 98, 98, 0, 0, 0, 0, 0, 250}
if string(a) != string(newA) || string(b) != string(newB) {
t.Fatalf("error EncodeBytes")
}
}
func TestEncodeIntToCmpUint(t *testing.T) {
if EncodeIntToCmpUint(1) != 9223372036854775809 {
t.Fatalf("error EncodeIntToCmpUint")
}
}
func TestEncodeInt(t *testing.T) {
byteA := []byte{97, 97, 97, 128, 0, 0, 0, 0, 0, 0, 1}
byteB := []byte{97, 97, 97, 128, 0, 0, 0, 0, 0, 0, 2}
if string(EncodeInt([]byte("aaa"), 1)) != string(byteA) || string(EncodeInt([]byte("aaa"), 2)) != string(byteB) {
t.Fatalf("error EncodeInt")
}
}
func TestGenTableRecordPrefix(t *testing.T) {
if GenTableRecordPrefix(1) != "7480000000000000FF015F720000000000FA" {
t.Fatalf("error GenTableRecordPrefix, expect 7480000000000000FF015F720000000000FA but get %s", GenTableRecordPrefix(1))
}
}
func TestGenTableIndexPrefix(t *testing.T) {
if GenTableIndexPrefix(2, 1) != "7480000000000000FF025F698000000000FF0000010000000000FA" {
t.Fatalf("error TestGenTableIndexPrefix")
}
}
func TestAppendTableRecordPrefix(t *testing.T) {
byteA := []byte{97, 97, 97, 116, 128, 0, 0, 0, 0, 0, 0, 1, 95, 114}
if string(appendTableRecordPrefix([]byte("aaa"), 1)) != string(byteA) {
t.Fatalf("error TestAppendTableRecordPrefix")
}
}
func TestAppendTableIndexPrefix(t *testing.T) {
byteA := []byte{97, 97, 97, 116, 128, 0, 0, 0, 0, 0, 0, 1, 95, 105}
if string(appendTableIndexPrefix([]byte("aaa"), 1)) != string(byteA) {
t.Fatalf("error TestAppendTableIndexPrefix")
}
}