@@ -4,116 +4,6 @@ import * as cborFixtures from '../cbor/fixtures.json';
4
4
describe ( 'deser-lib' , function ( ) {
5
5
describe ( 'cbor' , function ( ) {
6
6
describe ( 'transform' , function ( ) {
7
- it ( 'orders object properties canonically' , function ( ) {
8
- const res = Cbor . transform ( { b : 'second' , a : 'first' } ) as any ;
9
- const properties = Object . getOwnPropertyNames ( res ) ;
10
- properties [ 0 ] . should . equal ( 'a' ) ;
11
- properties [ 1 ] . should . equal ( 'b' ) ;
12
- res . a . should . equal ( 'first' ) ;
13
- res . b . should . equal ( 'second' ) ;
14
- } ) ;
15
-
16
- describe ( 'canonical ordering' , function ( ) {
17
- it ( 'orders by weight' , function ( ) {
18
- const res = Cbor . transform ( [
19
- { weight : 2 , value : null } ,
20
- { weight : 1 , value : null } ,
21
- ] ) as any ;
22
- res [ 0 ] . weight . should . equal ( 1 ) ;
23
- res [ 1 ] . weight . should . equal ( 2 ) ;
24
- } ) ;
25
-
26
- it ( 'groups equal elements' , function ( ) {
27
- const res = Cbor . transform ( [
28
- {
29
- weight : 2 ,
30
- value : 'b' ,
31
- } ,
32
- {
33
- weight : 1 ,
34
- value : 'a' ,
35
- } ,
36
- {
37
- weight : 3 ,
38
- value : 'c' ,
39
- } ,
40
- {
41
- weight : 2 ,
42
- value : 'b' ,
43
- } ,
44
- ] ) as any ;
45
- res [ 0 ] . weight . should . equal ( 1 ) ;
46
- res [ 1 ] . weight . should . equal ( 2 ) ;
47
- res [ 2 ] . weight . should . equal ( 2 ) ;
48
- res [ 3 ] . weight . should . equal ( 3 ) ;
49
- } ) ;
50
-
51
- it ( 'orders number values' , function ( ) {
52
- const res = Cbor . transform ( [
53
- { weight : 1 , value : 2 } ,
54
- { weight : 1 , value : 1 } ,
55
- ] ) as any ;
56
- res [ 0 ] . value . should . equal ( 1 ) ;
57
- res [ 1 ] . value . should . equal ( 2 ) ;
58
- } ) ;
59
-
60
- it ( 'orders string values' , function ( ) {
61
- const res = Cbor . transform ( [
62
- { weight : 1 , value : 'ab' } ,
63
- { weight : 1 , value : 'aa' } ,
64
- ] ) as any ;
65
- res [ 0 ] . value . should . equal ( 'aa' ) ;
66
- res [ 1 ] . value . should . equal ( 'ab' ) ;
67
- } ) ;
68
-
69
- it ( 'orders byte values' , function ( ) {
70
- const res = Cbor . transform ( [
71
- { weight : 1 , value : '0x0b' } ,
72
- { weight : 1 , value : '0x0a' } ,
73
- ] ) as any ;
74
- res [ 0 ] . value . equals ( Buffer . from ( [ 0x0a ] ) ) . should . equal ( true ) ;
75
- res [ 1 ] . value . equals ( Buffer . from ( [ 0x0b ] ) ) . should . equal ( true ) ;
76
- } ) ;
77
-
78
- it ( 'orders string values of different lengths' , function ( ) {
79
- const res = Cbor . transform ( [
80
- { weight : 1 , value : 'ab' } ,
81
- { weight : 1 , value : 'a' } ,
82
- ] ) as any ;
83
- res [ 0 ] . value . should . equal ( 'a' ) ;
84
- res [ 1 ] . value . should . equal ( 'ab' ) ;
85
- } ) ;
86
-
87
- it ( 'throws for elements without weight' , function ( ) {
88
- ( ( ) => Cbor . transform ( [ { } , { } ] ) ) . should . throw ( ) ;
89
- } ) ;
90
-
91
- it ( 'throws for elements without value' , function ( ) {
92
- ( ( ) => Cbor . transform ( [ { weight : 1 } , { weight : 1 } ] ) ) . should . throw ( ) ;
93
- } ) ;
94
-
95
- it ( 'throws for values that cannot be compared' , function ( ) {
96
- ( ( ) =>
97
- Cbor . transform ( [
98
- { weight : 1 , value : { } } ,
99
- { weight : 1 , value : 1 } ,
100
- ] ) ) . should . throw ( ) ;
101
- ( ( ) =>
102
- Cbor . transform ( [
103
- { weight : 1 , value : undefined } ,
104
- { weight : 1 , value : null } ,
105
- ] ) ) . should . throw ( ) ;
106
- } ) ;
107
-
108
- it ( 'throws for elements of mixed type' , function ( ) {
109
- ( ( ) =>
110
- Cbor . transform ( [
111
- { weight : 0 , value : '0' } ,
112
- { weight : 0 , value : 0 } ,
113
- ] ) ) . should . throw ( ) ;
114
- } ) ;
115
- } ) ;
116
-
117
7
it ( 'preserves null values' , function ( ) {
118
8
const res = Cbor . transform ( { value : null } ) as any ;
119
9
res . should . have . property ( 'value' ) . which . is . null ( ) ;
@@ -139,21 +29,21 @@ describe('deser-lib', function () {
139
29
} ) ;
140
30
141
31
it ( 'transforms object recursively' , function ( ) {
142
- const res = Cbor . transform ( { value : { b : 'second ' , a : 'first ' } } ) as any ;
32
+ const res = Cbor . transform ( { value : { b : 'first ' , a : 'second ' } } ) as any ;
143
33
const properties = Object . getOwnPropertyNames ( res . value ) ;
144
- properties [ 0 ] . should . equal ( 'a ' ) ;
145
- properties [ 1 ] . should . equal ( 'b ' ) ;
146
- res . value . a . should . equal ( 'first' ) ;
147
- res . value . b . should . equal ( 'second' ) ;
34
+ properties [ 0 ] . should . equal ( 'b ' ) ;
35
+ properties [ 1 ] . should . equal ( 'a ' ) ;
36
+ res . value . b . should . equal ( 'first' ) ;
37
+ res . value . a . should . equal ( 'second' ) ;
148
38
} ) ;
149
39
150
40
it ( 'transforms array recursively' , function ( ) {
151
- const res = Cbor . transform ( [ { weight : 0 , value : { b : 'second ' , a : 'first ' } } ] ) as any ;
41
+ const res = Cbor . transform ( [ { weight : 0 , value : { b : 'first ' , a : 'second ' } } ] ) as any ;
152
42
const properties = Object . getOwnPropertyNames ( res [ 0 ] . value ) ;
153
- properties [ 0 ] . should . equal ( 'a ' ) ;
154
- properties [ 1 ] . should . equal ( 'b ' ) ;
155
- res [ 0 ] . value . a . should . equal ( 'first' ) ;
156
- res [ 0 ] . value . b . should . equal ( 'second' ) ;
43
+ properties [ 0 ] . should . equal ( 'b ' ) ;
44
+ properties [ 1 ] . should . equal ( 'a ' ) ;
45
+ res [ 0 ] . value . b . should . equal ( 'first' ) ;
46
+ res [ 0 ] . value . a . should . equal ( 'second' ) ;
157
47
} ) ;
158
48
159
49
it ( 'throws for invalid hex strings' , function ( ) {
@@ -171,14 +61,6 @@ describe('deser-lib', function () {
171
61
res . b . should . equal ( 'second' ) ;
172
62
} ) ;
173
63
174
- it ( 'enforces canonical object property order' , function ( ) {
175
- ( ( ) => Cbor . untransform ( { b : 'second' , a : 'first' } ) ) . should . throw ( ) ;
176
- } ) ;
177
-
178
- it ( 'enforces canonical array element order' , function ( ) {
179
- ( ( ) => Cbor . untransform ( [ { weight : 2 } , { weight : 1 } ] ) ) . should . throw ( ) ;
180
- } ) ;
181
-
182
64
it ( 'replaces Buffers with prefixed hex strings' , function ( ) {
183
65
const hex = '00010203' ;
184
66
const res = Cbor . untransform ( { value : Buffer . from ( hex , 'hex' ) } ) as any ;
0 commit comments