2015-07-14 17:23:54 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Flags: --expose-internals
|
|
|
|
|
2015-09-27 22:31:36 +00:00
|
|
|
require('../common');
|
2015-07-14 17:23:54 +00:00
|
|
|
const assert = require('assert');
|
2015-11-09 21:38:13 +00:00
|
|
|
const freelist = require('internal/freelist');
|
2015-07-14 17:23:54 +00:00
|
|
|
|
2016-12-01 16:21:29 +00:00
|
|
|
assert.strictEqual(typeof freelist, 'object');
|
|
|
|
assert.strictEqual(typeof freelist.FreeList, 'function');
|
2015-07-14 17:23:54 +00:00
|
|
|
|
|
|
|
const flist1 = new freelist.FreeList('flist1', 3, String);
|
|
|
|
|
|
|
|
// Allocating when empty, should not change the list size
|
2017-01-08 13:19:00 +00:00
|
|
|
const result = flist1.alloc('test');
|
2015-07-14 17:23:54 +00:00
|
|
|
assert.strictEqual(typeof result, 'string');
|
|
|
|
assert.strictEqual(result, 'test');
|
|
|
|
assert.strictEqual(flist1.list.length, 0);
|
|
|
|
|
|
|
|
// Exhaust the free list
|
|
|
|
assert(flist1.free('test1'));
|
|
|
|
assert(flist1.free('test2'));
|
|
|
|
assert(flist1.free('test3'));
|
|
|
|
|
|
|
|
// Now it should not return 'true', as max length is exceeded
|
|
|
|
assert.strictEqual(flist1.free('test4'), false);
|
|
|
|
assert.strictEqual(flist1.free('test5'), false);
|
|
|
|
|
|
|
|
// At this point 'alloc' should just return the stored values
|
|
|
|
assert.strictEqual(flist1.alloc(), 'test3');
|
2016-01-26 12:13:12 +00:00
|
|
|
assert.strictEqual(flist1.alloc(), 'test2');
|
|
|
|
assert.strictEqual(flist1.alloc(), 'test1');
|