Comparing version 3.1.0 to 3.1.1
@@ -63,4 +63,6 @@ 'use strict' | ||
reverse ? stack[0].idx-- : stack[0].idx++ | ||
cb(null, { element: res.element, index: index }) | ||
reverse ? index-- : index++ | ||
cb(null, { | ||
element: res.element, | ||
index: reverse ? index-- : index++ | ||
}) | ||
} | ||
@@ -67,0 +69,0 @@ }) |
{ | ||
"name": "aolog", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Append only log", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,2 +23,12 @@ 'use strict' | ||
function range (from, to) { | ||
if (from > to) return [] | ||
var arr = [] | ||
while (from !== to) { | ||
arr.push(from++) | ||
} | ||
return arr | ||
} | ||
/* global describe, it, before */ | ||
@@ -229,11 +239,2 @@ | ||
// helper | ||
function range (from, to) { | ||
var arr = [] | ||
while (from !== to) { | ||
arr.push(from++) | ||
} | ||
return arr | ||
} | ||
it('should take all from all offsets', function (done) { | ||
@@ -541,2 +542,58 @@ var count = 0 | ||
describe('index', function () { | ||
var SIZE = BUCKET_SIZE * 100 | ||
it('should have the correct indicies', function (done) { | ||
var count = 0 | ||
add_many(aolog.empty(), SIZE, | ||
function (i, current) { | ||
current.iterator().all(function (err, res) { | ||
assert.deepEqual(range(0, i), | ||
_.map(res, function (x) { return x.index })) | ||
if (++count == SIZE) done() | ||
}) | ||
return i | ||
}, | ||
function (err, res) { | ||
if (err) throw err | ||
}) | ||
}) | ||
it('should have the correct indicies with offset', function (done) { | ||
var count = 0 | ||
var offset = 2 | ||
add_many(aolog.empty(), SIZE, | ||
function (i, current) { | ||
current.iterator({ offset: offset }).all(function (err, res) { | ||
assert.deepEqual(range(offset, i), | ||
_.map(res, function (x) { return x.index })) | ||
if (++count == SIZE) done() | ||
}) | ||
return i | ||
}, | ||
function (err, res) { | ||
if (err) throw err | ||
}) | ||
}) | ||
it('should have the correct reverse indicies', function (done) { | ||
var count = 0 | ||
add_many(aolog.empty(), SIZE, | ||
function (i, current) { | ||
return i | ||
}, | ||
function (err, res) { | ||
if (err) throw err | ||
res.iterator({ reverse: true, offset: SIZE - 1 }).all( | ||
function (err, res) { | ||
if (err) throw err | ||
assert.deepEqual(range(0, SIZE).reverse(), | ||
_.map(res, function (x) { return x.index })) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('persistance', function () { | ||
@@ -543,0 +600,0 @@ describe('persist bucket', function () { |
Sorry, the diff of this file is too big to display
765724
21944