-
Notifications
You must be signed in to change notification settings - Fork 3
/
marshal_test.go
80 lines (73 loc) · 1.71 KB
/
marshal_test.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package p4
import (
"bytes"
"testing"
)
func TestMarshalInt(t *testing.T) {
in := "i\x01\x00\x00\x00"
out, err := Decode(bytes.NewBufferString(in))
if err != nil {
t.Fatalf("Decode err %v", err)
}
iout, ok := out.(int32)
if !ok {
t.Fatalf("want int32 got %T", out)
}
if iout != 1 {
t.Fatalf("want 1 got %v", iout)
}
}
func TestMarshalBool(t *testing.T) {
in := "T"
out, err := Decode(bytes.NewBufferString(in))
if err != nil {
t.Fatalf("Decode err %v", err)
}
iout, ok := out.(bool)
if !ok {
t.Fatalf("want bool got %T", out)
}
if iout != true {
t.Fatalf("want true got %v", iout)
}
}
func TestMarshalDict(t *testing.T) {
in := "{i\x01\x00\x00\x00i\x01\x00\x00\x00i\x02\x00\x00\x00i\x02\x00\x00\x000"
out, err := Decode(bytes.NewBufferString(in))
if err != nil {
t.Fatalf("Decode err %v", err)
}
iout, ok := out.(map[interface{}]interface{})
if !ok {
t.Fatalf("want dict got %T", out)
}
if len(iout) != 2 {
t.Fatalf("want 2 entries %d", len(iout))
}
}
func TestMarshalStr(t *testing.T) {
in := "t\x05\x00\x00\x00hello"
out, err := Decode(bytes.NewBufferString(in))
if err != nil {
t.Fatalf("Decode err %v", err)
}
iout, ok := out.(string)
if !ok {
t.Fatalf("want string got %T", out)
}
if iout != "hello" {
t.Fatalf("want 1 got %q", iout)
}
}
func xTestMarshal(t *testing.T) {
//marshal.dumps({1:-1, 'key':'val', True: [1,2,3,]})
in := "{i\x01\x00\x00\x00[\x03\x00\x00\x00i\x01\x00\x00\x00i\x02\x00\x00\x00i\x03\x00\x00\x00t\x03\x00\x00\x00keyt\x03\x00\x00\x00val0"
out, err := Decode(bytes.NewBufferString(in))
if err != nil {
t.Fatalf("Decode err %v", err)
}
dict := out.(map[interface{}]interface{})
if len(dict) != 3 {
t.Errorf("dict was %d, want 3", len(dict))
}
}