diff --git a/iterator.js b/iterator.js index 9d412e56..1e99a819 100644 --- a/iterator.js +++ b/iterator.js @@ -13,18 +13,9 @@ function Iterator (db, options) { util.inherits(Iterator, AbstractIterator) -Iterator.prototype.seek = function (target) { - if (this._ended) { - throw new Error('cannot call seek() after end()') - } - if (this._nexting) { - throw new Error('cannot call seek() before next() has completed') - } - if (typeof target !== 'string' && !Buffer.isBuffer(target)) { - throw new Error('seek() requires a string or buffer key') - } +Iterator.prototype._seek = function (target) { if (target.length === 0) { - throw new Error('cannot seek() to an empty key') + throw new Error('cannot seek() to an empty target') } this.cache = null diff --git a/test/iterator-test.js b/test/iterator-test.js index 6e611ee8..2d08015b 100644 --- a/test/iterator-test.js +++ b/test/iterator-test.js @@ -3,21 +3,13 @@ const iota = require('iota-array') const lexi = require('lexicographic-integer') const util = require('util') -make('iterator throws if key is not a string or buffer', function (db, t, done) { - var keys = [null, undefined, 1, true, false] - var pending = keys.length +make('iterator#seek throws if target is empty', function (db, t, done) { + var targets = [null, undefined, '', Buffer.alloc(0), []] + var pending = targets.length - keys.forEach(function (key) { - var error + targets.forEach(function (target) { var ite = db.iterator() - - try { - ite.seek(key) - } catch (e) { - error = e - } - - t.ok(error, 'had error from seek()') + t.throws(ite.seek.bind(ite, target), /Error: cannot seek\(\) to an empty target/) ite.end(end) })