@@ -25,10 +25,12 @@ test('String', () => {
25
25
const bigStr = Array ( 2048 ) . fill ( 'A' ) . join ( '' ) ;
26
26
const bigUtf8 = Buffer . from ( bigStr , 'utf-8' ) ;
27
27
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
28
- expect ( serializer . fromString ( bigStr ) ) . toMatchBuffer ( Buffer . concat ( [
29
- Buffer . from ( [ 0x80 , 0x10 ] ) , // 2048 in unsigned leb128
30
- bigUtf8 ,
31
- ] ) ) ;
28
+ expect ( serializer . fromString ( bigStr ) ) . toMatchBuffer (
29
+ Buffer . concat ( [
30
+ Buffer . from ( [ 0x80 , 0x10 ] ) , // 2048 in unsigned leb128
31
+ bigUtf8 ,
32
+ ] )
33
+ ) ;
32
34
} ) ;
33
35
34
36
test ( 'Int' , ( ) => {
@@ -40,23 +42,29 @@ test('Int', () => {
40
42
test ( 'Bytes' , ( ) => {
41
43
const serializer = new Serializer ( ) ;
42
44
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
43
- expect ( serializer . fromBytes ( Buffer . from ( [ 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ) . toMatchBuffer ( Buffer . from ( [ 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
45
+ expect ( serializer . fromBytes ( Buffer . from ( [ 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ) . toMatchBuffer (
46
+ Buffer . from ( [ 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
47
+ ) ;
44
48
45
49
// Encoding a big string
46
50
const bigBuffer = Buffer . from ( Array ( 2048 ) . fill ( 'A' ) . join ( '' ) , 'utf-8' ) ;
47
51
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
48
- expect ( serializer . fromBytes ( bigBuffer ) ) . toMatchBuffer ( Buffer . concat ( [
49
- Buffer . from ( [ 0x80 , 0x10 ] ) , // 2048 in unsigned leb128
50
- bigBuffer ,
51
- ] ) ) ;
52
+ expect ( serializer . fromBytes ( bigBuffer ) ) . toMatchBuffer (
53
+ Buffer . concat ( [
54
+ Buffer . from ( [ 0x80 , 0x10 ] ) , // 2048 in unsigned leb128
55
+ bigBuffer ,
56
+ ] )
57
+ ) ;
52
58
} ) ;
53
59
54
60
test ( 'Optional' , ( ) => {
55
61
const serializer = new Serializer ( ) ;
56
62
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
57
63
expect ( serializer . fromOptional ( null , 'int' ) ) . toMatchBuffer ( Buffer . from ( [ 0x00 ] ) ) ;
58
64
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
59
- expect ( serializer . fromOptional ( 300 , 'int' ) ) . toMatchBuffer ( Buffer . from ( [ 0x01 , 0x00 , 0x00 , 0x01 , 0x2c ] ) ) ;
65
+ expect ( serializer . fromOptional ( 300 , 'int' ) ) . toMatchBuffer (
66
+ Buffer . from ( [ 0x01 , 0x00 , 0x00 , 0x01 , 0x2c ] )
67
+ ) ;
60
68
61
69
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
62
70
expect ( serializer . fromOptional ( null , 'bool' ) ) . toMatchBuffer ( Buffer . from ( [ 0x00 ] ) ) ;
@@ -66,33 +74,49 @@ test('Optional', () => {
66
74
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
67
75
expect ( serializer . fromOptional ( null , 'str' ) ) . toMatchBuffer ( Buffer . from ( [ 0x00 ] ) ) ;
68
76
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
69
- expect ( serializer . fromOptional ( 'test' , 'str' ) ) . toMatchBuffer ( Buffer . from ( [ 0x01 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
77
+ expect ( serializer . fromOptional ( 'test' , 'str' ) ) . toMatchBuffer (
78
+ Buffer . from ( [ 0x01 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
79
+ ) ;
70
80
71
81
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
72
82
expect ( serializer . fromOptional ( null , 'bytes' ) ) . toMatchBuffer ( Buffer . from ( [ 0x00 ] ) ) ;
73
83
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
74
- expect ( serializer . fromOptional ( Buffer . from ( [ 0x74 , 0x65 , 0x73 , 0x74 ] ) , 'bytes' ) ) . toMatchBuffer ( Buffer . from ( [ 0x01 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
84
+ expect ( serializer . fromOptional ( Buffer . from ( [ 0x74 , 0x65 , 0x73 , 0x74 ] ) , 'bytes' ) ) . toMatchBuffer (
85
+ Buffer . from ( [ 0x01 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
86
+ ) ;
75
87
} ) ;
76
88
77
89
test ( 'Signed' , ( ) => {
78
90
const serializer = new Serializer ( ) ;
79
91
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
80
- expect ( serializer . fromSigned ( '74657374,300,int' ) ) . toMatchBuffer ( Buffer . from ( [ 0x00 , 0x00 , 0x01 , 0x2c , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
92
+ expect ( serializer . fromSigned ( '74657374,300,int' ) ) . toMatchBuffer (
93
+ Buffer . from ( [ 0x00 , 0x00 , 0x01 , 0x2c , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
94
+ ) ;
81
95
82
96
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
83
- expect ( serializer . fromSigned ( '74657374,300,VarInt' ) ) . toMatchBuffer ( Buffer . from ( [ 0xac , 0x02 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
97
+ expect ( serializer . fromSigned ( '74657374,300,VarInt' ) ) . toMatchBuffer (
98
+ Buffer . from ( [ 0xac , 0x02 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
99
+ ) ;
84
100
85
101
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
86
- expect ( serializer . fromSigned ( '74657374,test,str' ) ) . toMatchBuffer ( Buffer . from ( [ 0x04 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
102
+ expect ( serializer . fromSigned ( '74657374,test,str' ) ) . toMatchBuffer (
103
+ Buffer . from ( [ 0x04 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
104
+ ) ;
87
105
88
106
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
89
- expect ( serializer . fromSigned ( '74657374,74657374,bytes' ) ) . toMatchBuffer ( Buffer . from ( [ 0x04 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
107
+ expect ( serializer . fromSigned ( '74657374,74657374,bytes' ) ) . toMatchBuffer (
108
+ Buffer . from ( [ 0x04 , 0x74 , 0x65 , 0x73 , 0x74 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
109
+ ) ;
90
110
91
111
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
92
- expect ( serializer . fromSigned ( '74657374,false,bool' ) ) . toMatchBuffer ( Buffer . from ( [ 0x00 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
112
+ expect ( serializer . fromSigned ( '74657374,false,bool' ) ) . toMatchBuffer (
113
+ Buffer . from ( [ 0x00 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
114
+ ) ;
93
115
94
116
// @ts -expect-error: toMatchBuffer is defined in our setupTests.js so the type check fails.
95
- expect ( serializer . fromSigned ( '74657374,true,bool' ) ) . toMatchBuffer ( Buffer . from ( [ 0x01 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] ) ) ;
117
+ expect ( serializer . fromSigned ( '74657374,true,bool' ) ) . toMatchBuffer (
118
+ Buffer . from ( [ 0x01 , 0x04 , 0x74 , 0x65 , 0x73 , 0x74 ] )
119
+ ) ;
96
120
} ) ;
97
121
98
122
test ( 'VarInt' , ( ) => {
0 commit comments