@@ -5,7 +5,7 @@ import "bytes"
5
5
import "fmt"
6
6
7
7
func TestCbor2CollateNil (t * testing.T ) {
8
- inp , ref , config := "null" , `\f \x00` , NewDefaultConfig ()
8
+ inp , ref , config := "null" , `2 \x00` , NewDefaultConfig ()
9
9
clt := config .NewCollate (make ([]byte , 1024 ), 0 )
10
10
cbr := config .NewCbor (make ([]byte , 1024 ), 0 )
11
11
cltback := config .NewCollate (make ([]byte , 1024 ), 0 )
@@ -19,7 +19,7 @@ func TestCbor2CollateNil(t *testing.T) {
19
19
}
20
20
21
21
func TestCbor2CollateTrue (t * testing.T ) {
22
- inp , ref , config := "true" , `\x0e \x00` , NewDefaultConfig ()
22
+ inp , ref , config := "true" , `F \x00` , NewDefaultConfig ()
23
23
clt := config .NewCollate (make ([]byte , 1024 ), 0 )
24
24
cbr := config .NewCbor (make ([]byte , 1024 ), 0 )
25
25
cltback := config .NewCollate (make ([]byte , 1024 ), 0 )
@@ -33,7 +33,7 @@ func TestCbor2CollateTrue(t *testing.T) {
33
33
}
34
34
35
35
func TestCbor2CollateFalse (t * testing.T ) {
36
- inp , ref , config := "false" , `\r \x00` , NewDefaultConfig ()
36
+ inp , ref , config := "false" , `< \x00` , NewDefaultConfig ()
37
37
clt := config .NewCollate (make ([]byte , 1024 ), 0 )
38
38
cbr := config .NewCbor (make ([]byte , 1024 ), 0 )
39
39
cltback := config .NewCollate (make ([]byte , 1024 ), 0 )
@@ -48,34 +48,33 @@ func TestCbor2CollateFalse(t *testing.T) {
48
48
49
49
func TestCbor2CollateNumber (t * testing.T ) {
50
50
testcases := [][3 ]interface {}{
51
- {"10.2" , `\x0f >>2102-\x00` , FloatNumber },
52
- {"10" , `\x0f >>21-\x00` , FloatNumber },
53
- {"10.2" , `\x0f >>2102-\x00` , SmartNumber },
54
- {"10" , `\x0f >>21-\x00` , SmartNumber },
55
- {"10" , `\x0f >>21-\x00` , FloatNumber },
56
- {"-10" , `\x0f --78>\x00` , SmartNumber },
57
- {"-10" , `\x0f --78>\x00` , FloatNumber },
58
- {"200" , `\x0f >>32-\x00` , SmartNumber },
59
- {"200" , `\x0f >>32-\x00` , FloatNumber },
60
- {"-200" , `\x0f --67>\x00` , SmartNumber },
61
- {"-200" , `\x0f --67>\x00` , FloatNumber },
51
+ {"10.2" , `P >>2102-\x00` , FloatNumber },
52
+ {"10" , `P >>21-\x00` , FloatNumber },
53
+ {"10.2" , `P >>2102-\x00` , SmartNumber },
54
+ {"10" , `P >>21-\x00` , SmartNumber },
55
+ {"10" , `P >>21-\x00` , FloatNumber },
56
+ {"-10" , `P --78>\x00` , SmartNumber },
57
+ {"-10" , `P --78>\x00` , FloatNumber },
58
+ {"200" , `P >>32-\x00` , SmartNumber },
59
+ {"200" , `P >>32-\x00` , FloatNumber },
60
+ {"-200" , `P --67>\x00` , SmartNumber },
61
+ {"-200" , `P --67>\x00` , FloatNumber },
62
62
{
63
- "4294967297" , `\x0f >>>2104294967297-\x00` , FloatNumber },
63
+ "4294967297" , `P >>>2104294967297-\x00` , FloatNumber },
64
64
{
65
- "-4294967297" , `\x0f ---7895705032702>\x00` , FloatNumber },
65
+ "-4294967297" , `P ---7895705032702>\x00` , FloatNumber },
66
66
{
67
- "4294967297" , `\x0f >>>2104294967297-\x00` , SmartNumber },
67
+ "4294967297" , `P >>>2104294967297-\x00` , SmartNumber },
68
68
{
69
- "-4294967297" , `\x0f ---7895705032702>\x00` , SmartNumber },
69
+ "-4294967297" , `P ---7895705032702>\x00` , SmartNumber },
70
70
{
71
- "9007199254740992" , `\x0f >>>2169007199254740992-\x00` , FloatNumber },
71
+ "9007199254740992" , `P >>>2169007199254740992-\x00` , FloatNumber },
72
72
{
73
- "-9007199254740993" , `\x0f ---7830992800745259007>\x00` , FloatNumber },
73
+ "-9007199254740993" , `P ---7830992800745259007>\x00` , FloatNumber },
74
74
{
75
- "9007199254740992" , `\x0f>>>2169007199254740992-\x00` , SmartNumber },
76
-
75
+ "9007199254740992" , `P>>>2169007199254740992-\x00` , SmartNumber },
77
76
{
78
- "-9007199254740993" , `\x0f ---7830992800745259006>\x00` , SmartNumber },
77
+ "-9007199254740993" , `P ---7830992800745259006>\x00` , SmartNumber },
79
78
}
80
79
81
80
for _ , tcase := range testcases {
@@ -101,9 +100,9 @@ func TestCbor2CollateNumber(t *testing.T) {
101
100
102
101
func TestCbor2CollateString (t * testing.T ) {
103
102
testcases := [][2 ]string {
104
- {`""` , `\x10 \x00\x00` },
105
- {`"hello world"` , `\x10hello world\x00\x00` },
106
- {fmt .Sprintf (`"%s"` , MissingLiteral ), `\v \x00` },
103
+ {`""` , `Z \x00\x00` },
104
+ {`"hello world"` , `Zhello world\x00\x00` },
105
+ {fmt .Sprintf (`"%s"` , MissingLiteral ), `1 \x00` },
107
106
}
108
107
109
108
config := NewDefaultConfig ()
@@ -128,36 +127,36 @@ func TestCbor2CollateString(t *testing.T) {
128
127
}
129
128
130
129
// missing string without doMissing configuration
131
- inp := fmt .Sprintf (`"%s"` , MissingLiteral )
132
- refcode := `\x10 ~[]{}falsenilNA~\x00\x00`
130
+ inp := [] byte ( fmt .Sprintf (`"%s"` , MissingLiteral ) )
131
+ refcode := `Z ~[]{}falsenilNA~\x00\x00`
133
132
config = NewDefaultConfig ().UseMissing (false )
134
133
clt = config .NewCollate (make ([]byte , 1024 ), 0 )
135
134
cbr = config .NewCbor (make ([]byte , 1024 ), 0 )
136
135
cltback = config .NewCollate (make ([]byte , 1024 ), 0 )
137
136
138
- config .NewJson ([] byte ( inp ) , - 1 ).Tocollate (clt ).Tocbor (cbr ).Tocollate (cltback )
137
+ config .NewJson (inp , - 1 ).Tocollate (clt ).Tocbor (cbr ).Tocollate (cltback )
139
138
seqn := fmt .Sprintf ("%q" , cltback .Bytes ())
140
139
if seqn = seqn [1 : len (seqn )- 1 ]; seqn != refcode {
141
140
t .Errorf ("expected %v, got %v" , refcode , seqn )
142
141
}
143
142
144
143
// utf8 string
145
- inp = `"汉语 / 漢語; Hàn\b \t\uef24yǔ "`
144
+ inp = [] byte ( `"汉语 / 漢語; Hàn\b \t\uef24yǔ "` )
146
145
147
146
config = NewDefaultConfig ()
148
147
clt = config .NewCollate (make ([]byte , 1024 ), 0 )
149
148
cbr = config .NewCbor (make ([]byte , 1024 ), 0 )
150
149
cltback = config .NewCollate (make ([]byte , 1024 ), 0 )
151
150
152
- config .NewJson ([] byte ( inp ) , - 1 ).Tocollate (clt ).Tocbor (cbr ).Tocollate (cltback )
151
+ config .NewJson (inp , - 1 ).Tocollate (clt ).Tocbor (cbr ).Tocollate (cltback )
153
152
154
153
if bytes .Compare (clt .Bytes (), cltback .Bytes ()) != 0 {
155
154
t .Errorf ("expected %v, got %v" , clt .Bytes (), cltback .Bytes ())
156
155
}
157
156
}
158
157
159
158
func TestCbor2CollateBytes (t * testing.T ) {
160
- inp , refcode := []byte ("hello world" ), `\x14hello world\x00`
159
+ inp , refcode := []byte ("hello world" ), `\x82hello world\x00`
161
160
config := NewDefaultConfig ()
162
161
clt := config .NewCollate (make ([]byte , 1024 ), 0 )
163
162
cbr := config .NewCbor (make ([]byte , 1024 ), 0 )
@@ -175,20 +174,18 @@ func TestCbor2CollateArray(t *testing.T) {
175
174
// without length prefix
176
175
testcases := [][4 ]string {
177
176
{`[]` ,
178
- `\x12 \x00` ,
179
- `\x12\x110 \x00\x00` ,
177
+ `n \x00` ,
178
+ `nd0 \x00\x00` ,
180
179
`[]` },
181
180
{`[null,true,false,10.0,"hello"]` ,
182
- `\x12\f\x00\x0e\x00\r\x00\x0f>>21-\x00\x10hello\x00\x00\x00` ,
183
- `\x12\x11>5\x00\f\x00\x0e\x00\r\x00\x0f>>21-\x00\x10hello\x00` +
184
- `\x00\x00` ,
181
+ `n2\x00F\x00<\x00P>>21-\x00Zhello\x00\x00\x00` ,
182
+ `nd>5\x002\x00F\x00<\x00P>>21-\x00Zhello\x00\x00\x00` ,
185
183
`[null,true,false,+0.1e+2,"hello"]` },
186
184
{`[null,true,10.0,10.2,[],{"key":{}}]` ,
187
- `\x12\f\x00\x0e\x00\x0f>>21-\x00\x0f>>2102-\x00\x12\x00` +
188
- `\x13\x11>1\x00\x10key\x00\x00\x13\x110\x00\x00\x00\x00` ,
189
- `\x12\x11>6\x00\f\x00\x0e\x00\x0f>>21-\x00\x0f>>2102-\x00` +
190
- `\x12\x110\x00\x00\x13\x11>1\x00\x10key\x00\x00\x13\x110` +
191
- `\x00\x00\x00\x00` ,
185
+ `n2\x00F\x00P>>21-\x00P>>2102-\x00n\x00xd>1\x00Zkey\x00` +
186
+ `\x00xd0\x00\x00\x00\x00` ,
187
+ `nd>6\x002\x00F\x00P>>21-\x00P>>2102-\x00nd0\x00\x00xd>1` +
188
+ `\x00Zkey\x00\x00xd0\x00\x00\x00\x00` ,
192
189
`[null,true,+0.1e+2,+0.102e+2,[],{"key":{}}]` },
193
190
}
194
191
@@ -258,17 +255,17 @@ func TestCbor2CollateMap(t *testing.T) {
258
255
testcases := [][4 ]string {
259
256
{
260
257
`{}` ,
261
- `\x13\x110 \x00\x00` ,
262
- `\x13 \x00` ,
258
+ `xd0 \x00\x00` ,
259
+ `x \x00` ,
263
260
`{}` },
264
261
{
265
262
`{"a":null,"b":true,"c":false,"d":10.0,"e":"hello","f":["wo"]}` ,
266
- `\x13\x11 >6\x00\x10a\ x00\x00\f \x00\x10b\ x00\x00\x0e \x00\x10c ` +
267
- `\x00\x00\r\x00\x10d\x00\x00\x0f >>21-\x00\x10e \x00\x00\x10hello ` +
268
- `\x00\x00\x10f\x00\x00\x12\x10wo\x00\x00\x00\ x00` ,
269
- `\x13\x10a\ x00\x00\f \x00\x10b\x00 \x00\x0e\ x00\x10c \x00\x00 ` +
270
- `\r \x00\x10d \x00\x00\x0f>>21-\ x00\x10e \x00\x00\x10hello ` +
271
- `\x00\x00\x10f\x00\x00\x12\x10wo\x00\x00\x00\x00 ` ,
263
+ `xd >6\x00Za\ x00\x002\x00Zb \x00\x00F\x00Zc\ x00\x00<\x00Zd \x00` +
264
+ `\x00P >>21-\x00Ze\ x00\x00Zhello \x00\x00Zf\ x00\x00nZwo\x00 ` +
265
+ `\x00\x00\x00` ,
266
+ `xZa\ x00\x002\x00Zb \x00\x00F\x00Zc \x00\x00<\x00Zd \x00\x00P ` +
267
+ `>>21-\x00Ze \x00\x00Zhello \x00\x00Zf\ x00\x00nZwo \x00\x00` +
268
+ `\x00\x00` ,
272
269
`{"a":null,"b":true,"c":false,"d":+0.1e+2,"e":"hello","f":["wo"]}` },
273
270
}
274
271
0 commit comments