@@ -131,6 +131,158 @@ Deno.test(
131
131
} ,
132
132
) ;
133
133
134
+ Deno . test (
135
+ "readFloat32() - little endian" ,
136
+ function ( ) : void {
137
+ const buffer = new ArrayBuffer ( 4 ) ;
138
+ const array = new Uint8Array ( buffer ) ;
139
+
140
+ array [ 0 ] = 0xF9 ;
141
+ array [ 1 ] = 0x0F ;
142
+ array [ 2 ] = 0x49 ;
143
+ array [ 3 ] = 0x40 ;
144
+
145
+ const binaryReader = new BinaryReader ( array ) ;
146
+ assertEquals ( binaryReader . readFloat32 ( true ) , 3.1415998935699463 ) ;
147
+ } ,
148
+ ) ;
149
+
150
+ Deno . test (
151
+ "readFloat32() - big endian" ,
152
+ function ( ) : void {
153
+ const buffer = new ArrayBuffer ( 4 ) ;
154
+ const array = new Uint8Array ( buffer ) ;
155
+
156
+ array [ 0 ] = 0x40 ;
157
+ array [ 1 ] = 0x49 ;
158
+ array [ 2 ] = 0x0F ;
159
+ array [ 3 ] = 0xF9 ;
160
+
161
+ const binaryReader = new BinaryReader ( array ) ;
162
+ assertEquals ( binaryReader . readFloat32 ( ) , 3.1415998935699463 ) ;
163
+ } ,
164
+ ) ;
165
+
166
+ Deno . test (
167
+ "readFloat64() - little endian" ,
168
+ function ( ) : void {
169
+ const buffer = new ArrayBuffer ( 8 ) ;
170
+ const array = new Uint8Array ( buffer ) ;
171
+
172
+ array [ 0 ] = 0x00 ;
173
+ array [ 1 ] = 0x00 ;
174
+ array [ 2 ] = 0x00 ;
175
+ array [ 3 ] = 0x00 ;
176
+ array [ 4 ] = 0x00 ;
177
+ array [ 5 ] = 0x00 ;
178
+ array [ 6 ] = 0x00 ;
179
+ array [ 7 ] = 0x40 ;
180
+
181
+ const binaryReader = new BinaryReader ( array ) ;
182
+ assertEquals ( binaryReader . readFloat64 ( true ) , 2.0 ) ;
183
+ } ,
184
+ ) ;
185
+
186
+ Deno . test (
187
+ "readFloat64() - big endian" ,
188
+ function ( ) : void {
189
+ const buffer = new ArrayBuffer ( 8 ) ;
190
+ const array = new Uint8Array ( buffer ) ;
191
+
192
+ array [ 0 ] = 0x40 ;
193
+ array [ 1 ] = 0x00 ;
194
+ array [ 2 ] = 0x00 ;
195
+ array [ 3 ] = 0x00 ;
196
+ array [ 4 ] = 0x00 ;
197
+ array [ 5 ] = 0x00 ;
198
+ array [ 6 ] = 0x00 ;
199
+ array [ 7 ] = 0x00 ;
200
+
201
+ const binaryReader = new BinaryReader ( array ) ;
202
+ assertEquals ( binaryReader . readFloat64 ( ) , 2.0 ) ;
203
+ } ,
204
+ ) ;
205
+
206
+ Deno . test (
207
+ "readBigInt64() - little endian" ,
208
+ function ( ) : void {
209
+ const buffer = new ArrayBuffer ( 8 ) ;
210
+ const array = new Uint8Array ( buffer ) ;
211
+
212
+ array [ 0 ] = 0x40 ;
213
+ array [ 1 ] = 0x00 ;
214
+ array [ 2 ] = 0x00 ;
215
+ array [ 3 ] = 0x00 ;
216
+ array [ 4 ] = 0x00 ;
217
+ array [ 5 ] = 0x00 ;
218
+ array [ 6 ] = 0x00 ;
219
+ array [ 7 ] = 0x00 ;
220
+
221
+ const binaryReader = new BinaryReader ( array ) ;
222
+ assertEquals ( binaryReader . readBigInt64 ( true ) , 64n ) ;
223
+ } ,
224
+ ) ;
225
+
226
+ Deno . test (
227
+ "readBigInt64() - big endian" ,
228
+ function ( ) : void {
229
+ const buffer = new ArrayBuffer ( 8 ) ;
230
+ const array = new Uint8Array ( buffer ) ;
231
+
232
+ array [ 0 ] = 0x00 ;
233
+ array [ 1 ] = 0x00 ;
234
+ array [ 2 ] = 0x00 ;
235
+ array [ 3 ] = 0x00 ;
236
+ array [ 4 ] = 0x00 ;
237
+ array [ 5 ] = 0x00 ;
238
+ array [ 6 ] = 0x00 ;
239
+ array [ 7 ] = 0x40 ;
240
+
241
+ const binaryReader = new BinaryReader ( array ) ;
242
+ assertEquals ( binaryReader . readBigInt64 ( ) , 64n ) ;
243
+ } ,
244
+ ) ;
245
+
246
+ Deno . test (
247
+ "readBigUint64() - little endian" ,
248
+ function ( ) : void {
249
+ const buffer = new ArrayBuffer ( 8 ) ;
250
+ const array = new Uint8Array ( buffer ) ;
251
+
252
+ array [ 0 ] = 0x40 ;
253
+ array [ 1 ] = 0x00 ;
254
+ array [ 2 ] = 0x00 ;
255
+ array [ 3 ] = 0x00 ;
256
+ array [ 4 ] = 0x00 ;
257
+ array [ 5 ] = 0x00 ;
258
+ array [ 6 ] = 0x00 ;
259
+ array [ 7 ] = 0x00 ;
260
+
261
+ const binaryReader = new BinaryReader ( array ) ;
262
+ assertEquals ( binaryReader . readBigUint64 ( true ) , 64n ) ;
263
+ } ,
264
+ ) ;
265
+
266
+ Deno . test (
267
+ "readBigUint64() - big endian" ,
268
+ function ( ) : void {
269
+ const buffer = new ArrayBuffer ( 8 ) ;
270
+ const array = new Uint8Array ( buffer ) ;
271
+
272
+ array [ 0 ] = 0x00 ;
273
+ array [ 1 ] = 0x00 ;
274
+ array [ 2 ] = 0x00 ;
275
+ array [ 3 ] = 0x00 ;
276
+ array [ 4 ] = 0x00 ;
277
+ array [ 5 ] = 0x00 ;
278
+ array [ 6 ] = 0x00 ;
279
+ array [ 7 ] = 0x40 ;
280
+
281
+ const binaryReader = new BinaryReader ( array ) ;
282
+ assertEquals ( binaryReader . readBigUint64 ( ) , 64n ) ;
283
+ } ,
284
+ ) ;
285
+
134
286
Deno . test (
135
287
"readChar" ,
136
288
function ( ) : void {
@@ -168,3 +320,21 @@ Deno.test(
168
320
assertEquals ( binaryReader . readString ( 13 ) , "Hello, World!" ) ;
169
321
} ,
170
322
) ;
323
+
324
+ Deno . test (
325
+ "position" ,
326
+ function ( ) : void {
327
+ const buffer = new ArrayBuffer ( 4 ) ;
328
+ const array = new Uint8Array ( buffer ) ;
329
+
330
+ array [ 0 ] = 0x48 ;
331
+ array [ 1 ] = 0x65 ;
332
+ array [ 2 ] = 0x6C ;
333
+ array [ 3 ] = 0x6C ;
334
+
335
+ const binaryReader = new BinaryReader ( array ) ;
336
+ assertEquals ( binaryReader . position , 0 ) ;
337
+ binaryReader . readBytes ( 4 ) ;
338
+ assertEquals ( binaryReader . position , 4 ) ;
339
+ } ,
340
+ ) ;
0 commit comments