2016-12-01 10:44:55 -06:00
|
|
|
// Flags: --expose_internals
|
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
2018-03-23 15:32:23 +01:00
|
|
|
const BufferList = require('internal/streams/buffer_list');
|
2016-12-01 10:44:55 -06:00
|
|
|
|
|
|
|
// Test empty buffer list.
|
|
|
|
const emptyList = new BufferList();
|
|
|
|
|
|
|
|
emptyList.shift();
|
|
|
|
assert.deepStrictEqual(emptyList, new BufferList());
|
|
|
|
|
|
|
|
assert.strictEqual(emptyList.join(','), '');
|
|
|
|
|
|
|
|
assert.deepStrictEqual(emptyList.concat(0), Buffer.alloc(0));
|
|
|
|
|
2018-01-18 18:51:09 +01:00
|
|
|
const buf = Buffer.from('foo');
|
|
|
|
|
2016-12-01 10:44:55 -06:00
|
|
|
// Test buffer list with one element.
|
|
|
|
const list = new BufferList();
|
2018-01-18 18:51:09 +01:00
|
|
|
list.push(buf);
|
|
|
|
|
|
|
|
const copy = list.concat(3);
|
2016-12-01 10:44:55 -06:00
|
|
|
|
2018-01-18 18:51:09 +01:00
|
|
|
assert.notStrictEqual(copy, buf);
|
|
|
|
assert.deepStrictEqual(copy, buf);
|
2016-12-01 10:44:55 -06:00
|
|
|
|
|
|
|
assert.strictEqual(list.join(','), 'foo');
|
|
|
|
|
|
|
|
const shifted = list.shift();
|
2018-01-18 18:51:09 +01:00
|
|
|
assert.strictEqual(shifted, buf);
|
2016-12-01 10:44:55 -06:00
|
|
|
assert.deepStrictEqual(list, new BufferList());
|