mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
stream: encapsulate buffer-list
PR-URL: https://github.com/nodejs/node/pull/28974 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
8fdd634517
commit
c15b4969e9
3 changed files with 30 additions and 7 deletions
|
@ -16,11 +16,28 @@ assert.deepStrictEqual(emptyList.concat(0), Buffer.alloc(0));
|
|||
|
||||
const buf = Buffer.from('foo');
|
||||
|
||||
function testIterator(list, count) {
|
||||
// test iterator
|
||||
let len = 0;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
for (const x of list) {
|
||||
len++;
|
||||
}
|
||||
assert.strictEqual(len, count);
|
||||
}
|
||||
|
||||
// Test buffer list with one element.
|
||||
const list = new BufferList();
|
||||
testIterator(list, 0);
|
||||
|
||||
list.push(buf);
|
||||
testIterator(list, 1);
|
||||
for (const x of list) {
|
||||
assert.strictEqual(x, buf);
|
||||
}
|
||||
|
||||
const copy = list.concat(3);
|
||||
testIterator(copy, 3);
|
||||
|
||||
assert.notStrictEqual(copy, buf);
|
||||
assert.deepStrictEqual(copy, buf);
|
||||
|
@ -28,5 +45,6 @@ assert.deepStrictEqual(copy, buf);
|
|||
assert.strictEqual(list.join(','), 'foo');
|
||||
|
||||
const shifted = list.shift();
|
||||
testIterator(list, 0);
|
||||
assert.strictEqual(shifted, buf);
|
||||
assert.deepStrictEqual(list, new BufferList());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue