Skip to content

Commit a9acc2f

Browse files
larissayvettejasnell
authored andcommitted
test: check noAssert option in buf.write*()
Add test to cover previously untested `noAssert` functionality in buf.write*() functions. PR-URL: #10790 Reviewed-By: Rich Trott <[email protected]>
1 parent 644d08b commit a9acc2f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
5+
// testing buffer write functions
6+
7+
function write(funx, args, result, res) {
8+
{
9+
const buf = Buffer.alloc(9);
10+
assert.strictEqual(buf[funx](...args), result);
11+
assert.deepStrictEqual(buf, res);
12+
}
13+
14+
{
15+
const invalidArgs = Array.from(args);
16+
invalidArgs[1] = -1;
17+
assert.throws(
18+
() => Buffer.alloc(9)[funx](...invalidArgs),
19+
/^RangeError: (?:Index )?out of range(?: index)?$/
20+
);
21+
}
22+
23+
{
24+
const buf2 = 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

Comments
 (0)