-
Notifications
You must be signed in to change notification settings - Fork 8
/
cbor_appendix_a_test.go
42 lines (37 loc) · 1.07 KB
/
cbor_appendix_a_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
package gson
import "testing"
import "reflect"
import "encoding/json"
import hexcodec "encoding/hex"
func TestCborAppendixA(t *testing.T) {
t.Skip("skipping CborAppendixA")
var testcases []interface{}
data := testdataFile("testdata/cbor.appendix.a.json")
json.Unmarshal(data, &testcases)
config := NewDefaultConfig()
cbr := config.NewCbor(make([]byte, 0, 10))
for _, tcase := range testcases {
tcmap := tcase.(map[string]interface{})
hexinp, refval := tcmap["hex"].(string), tcmap["decoded"].(interface{})
roundtrip := tcmap["roundtrip"].(bool)
cborbuf, err := hexcodec.DecodeString(hexinp)
if err != nil {
t.Log(tcase)
t.Error(err)
}
val := cbr.Reset(cborbuf).Tovalue()
if reflect.DeepEqual(val, refval) == false {
t.Log(tcase)
t.Errorf("expected %v, got %v", refval, val)
}
if roundtrip {
v := config.NewValue(val)
cborbytes := v.Tocbor(cbr.Reset(make([]byte, 1024*1024))).Bytes()
s := hexcodec.EncodeToString(cborbytes)
if s != hexinp {
t.Logf("roundtrip %v", tcase)
t.Errorf("expected %q, got %q", hexinp, s)
}
}
}
}