@@ -214,6 +214,150 @@ describe("buffer", () => {
214214 // }).toThrow();
215215 } ) ;
216216
217+ test ( "#readInt32LE" , ( ) => {
218+ let buff = create < Buffer > ( [ 0xEF , 0xBE , 0xAD , 0xDE , 0x0d , 0xc0 , 0xde , 0x10 ] ) ;
219+ expect < i32 > ( buff . readInt32LE ( ) ) . toBe ( - 559038737 ) ;
220+ expect < i32 > ( buff . readInt32LE ( 4 ) ) . toBe ( 283033613 ) ;
221+ // TODO:
222+ // expectFn(() => {
223+ // let newBuff = new Buffer(1);
224+ // newBuff.readInt32LE(0);
225+ // }).toThrow();
226+ } ) ;
227+
228+ test ( "#readInt32BE" , ( ) => {
229+ let buff = create < Buffer > ( [ 0xDE , 0xAD , 0xBE , 0xEF , 0x10 , 0xde , 0xc0 , 0x0d ] ) ;
230+ expect < i32 > ( buff . readInt32BE ( ) ) . toBe ( - 559038737 ) ;
231+ expect < i32 > ( buff . readInt32BE ( 4 ) ) . toBe ( 283033613 ) ;
232+ // TODO:
233+ // expectFn(() => {
234+ // let newBuff = new Buffer(1);
235+ // newBuff.readInt32BE(0);
236+ // }).toThrow();
237+ } ) ;
238+
239+ test ( "#readUInt32LE" , ( ) => {
240+ let buff = create < Buffer > ( [ 0xEF , 0xBE , 0xAD , 0xDE , 0x0d , 0xc0 , 0xde , 0x10 ] ) ;
241+ expect < u32 > ( buff . readUInt32LE ( ) ) . toBe ( 3735928559 ) ;
242+ expect < u32 > ( buff . readUInt32LE ( 4 ) ) . toBe ( 283033613 ) ;
243+ // TODO:
244+ // expectFn(() => {
245+ // let newBuff = new Buffer(1);
246+ // newBuff.readUInt32LE(0);
247+ // }).toThrow();
248+ } ) ;
249+
250+ test ( "#readUInt32BE" , ( ) => {
251+ let buff = create < Buffer > ( [ 0xDE , 0xAD , 0xBE , 0xEF , 0x10 , 0xde , 0xc0 , 0x0d ] ) ;
252+ expect < u32 > ( buff . readUInt32BE ( ) ) . toBe ( 3735928559 ) ;
253+ expect < u32 > ( buff . readUInt32BE ( 4 ) ) . toBe ( 283033613 ) ;
254+ // TODO:
255+ // expectFn(() => {
256+ // let newBuff = new Buffer(1);
257+ // newBuff.readUInt32BE(0);
258+ // }).toThrow();
259+ } ) ;
260+
261+ test ( "#writeInt32LE" , ( ) => {
262+ let buff = new Buffer ( 8 ) ;
263+ expect < i32 > ( buff . writeInt32LE ( - 559038737 ) ) . toBe ( 4 ) ;
264+ expect < i32 > ( buff . writeInt32LE ( 283033613 , 4 ) ) . toBe ( 8 ) ;
265+ let result = create < Buffer > ( [ 0xEF , 0xBE , 0xAD , 0xDE , 0x0d , 0xc0 , 0xde , 0x10 ] ) ;
266+ expect < Buffer > ( buff ) . toStrictEqual ( result ) ;
267+ // TODO:
268+ // expectFn(() => {
269+ // let newBuff = new Buffer(1);
270+ // newBuff.writeInt32LE(0);
271+ // }).toThrow();
272+ } ) ;
273+
274+ test ( "#writeInt32BE" , ( ) => {
275+ let buff = new Buffer ( 8 ) ;
276+ expect < i32 > ( buff . writeInt32BE ( - 559038737 ) ) . toBe ( 4 ) ;
277+ expect < i32 > ( buff . writeInt32BE ( 283033613 , 4 ) ) . toBe ( 8 ) ;
278+ let result = create < Buffer > ( [ 0xDE , 0xAD , 0xBE , 0xEF , 0x10 , 0xde , 0xc0 , 0x0d ] ) ;
279+ expect < Buffer > ( buff ) . toStrictEqual ( result ) ;
280+ // TODO:
281+ // expectFn(() => {
282+ // let newBuff = new Buffer(1);
283+ // newBuff.writeInt32BE(0);
284+ // }).toThrow();
285+ } ) ;
286+
287+ test ( "#writeUInt32LE" , ( ) => {
288+ let buff = new Buffer ( 8 ) ;
289+ expect < i32 > ( buff . writeUInt32LE ( 3735928559 ) ) . toBe ( 4 ) ;
290+ expect < i32 > ( buff . writeUInt32LE ( 283033613 , 4 ) ) . toBe ( 8 ) ;
291+ let result = create < Buffer > ( [ 0xEF , 0xBE , 0xAD , 0xDE , 0x0d , 0xc0 , 0xde , 0x10 ] ) ; ;
292+ expect < Buffer > ( buff ) . toStrictEqual ( result ) ;
293+ // TODO:
294+ // expectFn(() => {
295+ // let newBuff = new Buffer(1);
296+ // newBuff.writeUInt32LE(0);
297+ // }).toThrow();
298+ } ) ;
299+
300+ test ( "#writeUInt32BE" , ( ) => {
301+ let buff = new Buffer ( 8 ) ;
302+ expect < i32 > ( buff . writeUInt32BE ( 3735928559 ) ) . toBe ( 4 ) ;
303+ expect < i32 > ( buff . writeUInt32BE ( 283033613 , 4 ) ) . toBe ( 8 ) ;
304+ let result = create < Buffer > ( [ 0xDE , 0xAD , 0xBE , 0xEF , 0x10 , 0xde , 0xc0 , 0x0d ] ) ;
305+ expect < Buffer > ( buff ) . toStrictEqual ( result ) ;
306+ // TODO:
307+ // expectFn(() => {
308+ // let newBuff = new Buffer(1);
309+ // newBuff.writeUInt32BE(0);
310+ // }).toThrow();
311+ } ) ;
312+
313+ test ( "#readFloatLE" , ( ) => {
314+ let buff = create < Buffer > ( [ 0xbb , 0xfe , 0x4a , 0x4f , 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
315+ expect < f32 > ( buff . readFloatLE ( ) ) . toBe ( 0xcafebabe ) ;
316+ expect < f32 > ( buff . readFloatLE ( 4 ) ) . toBe ( 1.539989614439558e-36 ) ;
317+ // TODO:
318+ // expectFn(() => {
319+ // let newBuff = new Buffer(1);
320+ // newBuff.readFloatLE(0);
321+ // }).toThrow();
322+ } ) ;
323+
324+ test ( "#readFloatBE" , ( ) => {
325+ let buff = create < Buffer > ( [ 0x4f , 0x4a , 0xfe , 0xbb , 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
326+ expect < f32 > ( buff . readFloatBE ( ) ) . toBe ( 0xcafebabe ) ;
327+ expect < f32 > ( buff . readFloatBE ( 4 ) ) . toBe ( 2.387939260590663e-38 ) ;
328+ // TODO:
329+ // expectFn(() => {
330+ // let newBuff = new Buffer(1);
331+ // newBuff.readFloatBE(0);
332+ // }).toThrow();
333+ } ) ;
334+
335+ test ( "#writeFloatLE" , ( ) => {
336+ let buff = new Buffer ( 8 ) ;
337+ expect < i32 > ( buff . writeFloatLE ( 0xcafebabe ) ) . toBe ( 4 ) ;
338+ expect < i32 > ( buff . writeFloatLE ( 1.539989614439558e-36 , 4 ) ) . toBe ( 8 ) ;
339+ let result = create < Buffer > ( [ 0xbb , 0xfe , 0x4a , 0x4f , 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
340+ expect < Buffer > ( buff ) . toStrictEqual ( result ) ;
341+ // TODO:
342+ // expectFn(() => {
343+ // let newBuff = new Buffer(1);
344+ // newBuff.writeFloatLE(0);
345+ // }).toThrow();
346+ } ) ;
347+
348+ test ( "#writeFloatBE" , ( ) => {
349+ let buff = new Buffer ( 8 ) ;
350+ expect < i32 > ( buff . writeFloatBE ( 0xcafebabe ) ) . toBe ( 4 ) ;
351+ expect < i32 > ( buff . writeFloatBE ( 2.387939260590663e-38 , 4 ) ) . toBe ( 8 ) ;
352+ let result = create < Buffer > ( [ 0x4f , 0x4a , 0xfe , 0xbb , 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
353+ expect < Buffer > ( buff ) . toStrictEqual ( result ) ;
354+ // TODO:
355+ // expectFn(() => {
356+ // let newBuff = new Buffer(1);
357+ // newBuff.writeFloatBE(0);
358+ // }).toThrow();
359+ } ) ;
360+
217361 test ( "#subarray" , ( ) => {
218362 let example = create < Buffer > ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
219363
0 commit comments