Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c1e166a

Browse filesBrowse files
larissayvetteevanlucas
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 <rtrott@gmail.com>
1 parent da59a57 commit c1e166a
Copy full SHA for c1e166a

File tree

Expand file treeCollapse file tree

1 file changed

+48
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+48
-0
lines changed
Open diff view settings
Collapse file
+48Lines changed: 48 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.