forked from smarty-archives/mafsa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
encoder_test.go
50 lines (45 loc) · 1.28 KB
/
encoder_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
package mafsa
import (
"bytes"
"testing"
)
func TestEncoder(t *testing.T) {
tree := New()
tree.Insert("dog")
tree.Insert("dogs")
tree.Insert("hello")
tree.Insert("jello")
err := tree.Insert("été")
if err != nil {
t.Errorf("Could not insert 'été': %q", err)
}
err = tree.Insert("あello")
if err != nil {
t.Errorf("Could not insert 'あello': %q", err)
}
tree.Finish()
enc := new(Encoder)
actual, err := enc.Encode(tree)
if err != nil {
t.Errorf("Encode produced an error: %v", err)
}
if !bytes.Equal(actual, encodedTestTree) {
t.Errorf("\nExpected:\n%x\nGot:\n%v", encodedTestTree, actual)
}
}
var encodedTestTree = []byte{
0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x64,
0x00, 0x00, 0x00, 0x27, 0x04, 0x68, 0x00, 0x00,
0x00, 0x2d, 0x04, 0x6a, 0x00, 0x00, 0x00, 0x33,
0x08, 0xc3, 0xa9, 0x00, 0x00, 0x00, 0x39, 0x0e,
0xe3, 0x81, 0x82, 0x00, 0x00, 0x00, 0x3f, 0x06,
0x6f, 0x00, 0x00, 0x00, 0x45, 0x06, 0x65, 0x00,
0x00, 0x00, 0x4b, 0x06, 0x65, 0x00, 0x00, 0x00,
0x4b, 0x06, 0x74, 0x00, 0x00, 0x00, 0x51, 0x06,
0x65, 0x00, 0x00, 0x00, 0x4b, 0x07, 0x67, 0x00,
0x00, 0x00, 0x58, 0x06, 0x6c, 0x00, 0x00, 0x00,
0x5e, 0x0b, 0xc3, 0xa9, 0x00, 0x00, 0x00, 0x00,
0x07, 0x73, 0x00, 0x00, 0x00, 0x00, 0x06, 0x6c,
0x00, 0x00, 0x00, 0x64, 0x07, 0x6f, 0x00, 0x00,
0x00, 0x00,
}