|
| 1 | +'use strict'; |
| 2 | +require('../common'); |
| 3 | +constassert=require('assert'); |
| 4 | + |
| 5 | +// testing buffer write functions |
| 6 | + |
| 7 | +functionwrite(funx,args,result,res){ |
| 8 | +{ |
| 9 | +constbuf=Buffer.alloc(9); |
| 10 | +assert.strictEqual(buf[funx](...args),result); |
| 11 | +assert.deepStrictEqual(buf,res); |
| 12 | +} |
| 13 | + |
| 14 | +{ |
| 15 | +constinvalidArgs=Array.from(args); |
| 16 | +invalidArgs[1]=-1; |
| 17 | +assert.throws( |
| 18 | +()=>Buffer.alloc(9)[funx](...invalidArgs), |
| 19 | +/^RangeError:(?:Index)?outofrange(?:index)?$/ |
| 20 | +); |
| 21 | +} |
| 22 | + |
| 23 | +{ |
| 24 | +constbuf2=Buffer.alloc(9); |
| 25 | +assert.strictEqual(buf2[funx](...args,true),result); |
| 26 | +assert.deepStrictEqual(buf2,res); |
| 27 | +} |
| 28 | + |
| 29 | +} |
| 30 | + |
| 31 | +write('writeInt8',[1,0],1,Buffer.from([1,0,0,0,0,0,0,0,0])); |
| 32 | +write('writeIntBE',[1,1,4],5,Buffer.from([0,0,0,0,1,0,0,0,0])); |
| 33 | +write('writeIntLE',[1,1,4],5,Buffer.from([0,1,0,0,0,0,0,0,0])); |
| 34 | +write('writeInt16LE',[1,1],3,Buffer.from([0,1,0,0,0,0,0,0,0])); |
| 35 | +write('writeInt16BE',[1,1],3,Buffer.from([0,0,1,0,0,0,0,0,0])); |
| 36 | +write('writeInt32LE',[1,1],5,Buffer.from([0,1,0,0,0,0,0,0,0])); |
| 37 | +write('writeInt32BE',[1,1],5,Buffer.from([0,0,0,0,1,0,0,0,0])); |
| 38 | +write('writeUInt8',[1,0],1,Buffer.from([1,0,0,0,0,0,0,0,0])); |
| 39 | +write('writeUIntLE',[1,1,4],5,Buffer.from([0,1,0,0,0,0,0,0,0])); |
| 40 | +write('writeUIntBE',[1,1,4],5,Buffer.from([0,0,0,0,1,0,0,0,0])); |
| 41 | +write('writeUInt16LE',[1,1],3,Buffer.from([0,1,0,0,0,0,0,0,0])); |
| 42 | +write('writeUInt16BE',[1,1],3,Buffer.from([0,0,1,0,0,0,0,0,0])); |
| 43 | +write('writeUInt32LE',[1,1],5,Buffer.from([0,1,0,0,0,0,0,0,0])); |
| 44 | +write('writeUInt32BE',[1,1],5,Buffer.from([0,0,0,0,1,0,0,0,0])); |
| 45 | +write('writeDoubleBE',[1,1],9,Buffer.from([0,63,240,0,0,0,0,0,0])); |
| 46 | +write('writeDoubleLE',[1,1],9,Buffer.from([0,0,0,0,0,0,0,240,63])); |
| 47 | +write('writeFloatBE',[1,1],5,Buffer.from([0,63,128,0,0,0,0,0,0])); |
| 48 | +write('writeFloatLE',[1,1],5,Buffer.from([0,0,0,128,63,0,0,0,0])); |
0 commit comments