forked from fernomac/ion-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buf_test.go
79 lines (73 loc) · 1.57 KB
/
buf_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
package ion
import (
"bytes"
"testing"
)
func TestBufnode(t *testing.T) {
root := container{code: 0xE0}
root.Append(atom([]byte{0x81, 0x83}))
{
symtab := &container{code: 0xD0}
{
symtab.Append(atom([]byte{0x86})) // varUint(6)
{
imps := &container{code: 0xB0}
{
imp0 := &container{code: 0xD0}
{
imp0.Append(atom([]byte{0x84})) // varUint(4)
imp0.Append(atom([]byte{0x85, 'b', 'o', 'g', 'u', 's'}))
imp0.Append(atom([]byte{0x85})) // varUint(5)
imp0.Append(atom([]byte{0x21, 0x2A}))
imp0.Append(atom([]byte{0x88})) // varUint(8)
imp0.Append(atom([]byte{0x21, 0x64}))
}
imps.Append(imp0)
}
symtab.Append(imps)
}
symtab.Append(atom([]byte{0x87})) // varUint(7)
{
syms := &container{code: 0xB0}
{
syms.Append(atom([]byte{0x83, 'f', 'o', 'o'}))
syms.Append(atom([]byte{0x83, 'b', 'a', 'r'}))
}
symtab.Append(syms)
}
}
root.Append(symtab)
}
buf := bytes.Buffer{}
if err := root.EmitTo(&buf); err != nil {
t.Fatal(err)
}
val := buf.Bytes()
eval := []byte{
// $ion_symbol_table::{
0xEE, 0x9F, 0x81, 0x83, 0xDE, 0x9B,
// imports:[
0x86, 0xBE, 0x8E,
// {
0xDD,
// name: "bogus"
0x84, 0x85, 'b', 'o', 'g', 'u', 's',
// version: 42
0x85, 0x21, 0x2A,
// max_id: 100
0x88, 0x21, 0x64,
// }
// ],
// symbols:[
0x87, 0xB8,
// "foo",
0x83, 'f', 'o', 'o',
// "bar"
0x83, 'b', 'a', 'r',
// ]
// }
}
if !bytes.Equal(val, eval) {
t.Errorf("expected %v, got %v", fmtbytes(eval), fmtbytes(val))
}
}