Skip to content

Commit 8b7c97b

Browse files
joyeecheungFishrock123
authored andcommitted
test: increase test coverage of BufferList
Add tests for edges cases of BufferList: - test operations when the length is 0 - test operations when the list only has one element PR-URL: #10171 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent dded482 commit 8b7c97b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Flags: --expose_internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const BufferList = require('internal/streams/BufferList');
6+
7+
// Test empty buffer list.
8+
const emptyList = new BufferList();
9+
10+
emptyList.shift();
11+
assert.deepStrictEqual(emptyList, new BufferList());
12+
13+
assert.strictEqual(emptyList.join(','), '');
14+
15+
assert.deepStrictEqual(emptyList.concat(0), Buffer.alloc(0));
16+
17+
// Test buffer list with one element.
18+
const list = new BufferList();
19+
list.push('foo');
20+
21+
assert.strictEqual(list.concat(1), 'foo');
22+
23+
assert.strictEqual(list.join(','), 'foo');
24+
25+
const shifted = list.shift();
26+
assert.strictEqual(shifted, 'foo');
27+
assert.deepStrictEqual(list, new BufferList());

0 commit comments

Comments
 (0)