-
Notifications
You must be signed in to change notification settings - Fork 23
/
encoder_test.go
70 lines (56 loc) · 1.47 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2018 Alexander Poltoratskiy. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package fast_test
import (
"bytes"
"github.com/co11ter/goFAST"
"os"
"reflect"
"testing"
)
var (
encoder *fast.Encoder
writer *bytes.Buffer
)
func init() {
ftpl, err := os.Open("testdata/test.xml")
if err != nil {
panic(err)
}
defer ftpl.Close()
tpls, _ := fast.ParseXMLTemplate(ftpl)
writer = &bytes.Buffer{}
encoder = fast.NewEncoder(writer, tpls...)
//encoder.SetLog(os.Stdout)
}
func encode(msg interface{}, expect []byte, t *testing.T) {
err := encoder.Encode(msg)
if err != nil {
t.Fatal("can not encode", err)
}
if !reflect.DeepEqual(writer.Bytes(), expect) {
t.Fatalf("data is not equal. current: %x expected: %x", writer.Bytes(), expect)
}
writer.Reset()
}
func TestDecimalEncode(t *testing.T) {
encode(&decimalMessage1, decimalData1, t)
// TODO have to provide decimal interface to set mantissa end exponent separately
//encode(&decimalMessage2, decimalData2, t)
}
func TestSequenceEncode(t *testing.T) {
encode(&sequenceMessage1, sequenceData1, t)
}
func TestByteVectorEncode(t *testing.T) {
encode(&byteVectorMessage1, byteVectorData1, t)
}
func TestStringEncode(t *testing.T) {
encode(&stringMessage1, stringData1, t)
}
func TestIntegerEncode(t *testing.T) {
encode(&integerMessage1, integerData1, t)
}
func TestGroupEncode(t *testing.T) {
encode(&groupMessage1, groupData1, t)
}