-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_test.go
38 lines (32 loc) · 884 Bytes
/
encode_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
package senml
import (
"encoding/json"
"reflect"
"testing"
)
// TestEncode tests if encoding the expected result gives the same result as decoding the JSON into Objects.
func TestEncode(t *testing.T) {
for n, test := range testVectors {
if test.SkipEncode {
continue
}
var exp []Record
err := json.Unmarshal([]byte(test.JSON), &exp)
if err != nil {
t.Errorf("JSON error in test %s: %s", n, err)
continue
}
res := Encode(test.Result)
if !reflect.DeepEqual(exp, res) {
t.Errorf("Encode for test %s incorrect, got:\n%#v\nexpected:\n%#v", n, res, exp)
}
}
}
func TestEncodeCompare(t *testing.T) {
for n, example := range testVectors {
c, _ := EncodeCBOR(example.Result)
j, _ := EncodeJSON(example.Result)
x, _ := EncodeXML(example.Result)
t.Logf("Comparison for %s CBOR/JSON/XML (bytes): %03d/%03d/%03d", n, len(c), len(j), len(x))
}
}