Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Test seek() integration (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers authored Jun 28, 2019
1 parent 9318f99 commit b4af053
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/iterator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var memdown = require('memdown')
var assert = require('referee').assert
var refute = require('referee').refute
var buster = require('bustermove')
var encode = require('encoding-down')
var levelup = require('../lib/levelup')
var common = require('./common')

Expand Down Expand Up @@ -32,3 +33,76 @@ buster.testCase('iterator', {
})
}
})

buster.testCase('iterator#seek()', {
setUp: function (done) {
this.mem = memdown()
this.mem.open(function () {})
this.mem.batch([
{ type: 'put', key: '"a"', value: 'a' },
{ type: 'put', key: '"b"', value: 'b' }
], function () {})
this.mem.close(done)
},
tearDown: function (done) {
this.db.close(done)
},

'without encoding, without deferred-open': function (done) {
var db = this.db = levelup(this.mem)

db.open(function (err) {
refute(err)

var it = db.iterator({ keyAsBuffer: false })

it.seek('"b"')
it.next(function (err, key, value) {
refute(err)
assert.equals(key, '"b"')
it.end(done)
})
})
},

'without encoding, with deferred-open': function (done) {
var db = this.db = levelup(this.mem)
var it = db.iterator({ keyAsBuffer: false })

it.seek('"b"')
it.next(function (err, key, value) {
refute(err)
assert.equals(key, '"b"')
it.end(done)
})
},

'with encoding, with deferred-open': function (done) {
var db = this.db = levelup(encode(this.mem, { keyEncoding: 'json' }))
var it = db.iterator()

it.seek('b')
it.next(function (err, key, value) {
refute(err)
assert.equals(key, 'b')
it.end(done)
})
},

'with encoding, without deferred-open': function (done) {
var db = this.db = levelup(encode(this.mem, { keyEncoding: 'json' }))

db.open(function (err) {
refute(err)

var it = db.iterator()

it.seek('b')
it.next(function (err, key, value) {
refute(err)
assert.equals(key, 'b')
it.end(done)
})
})
}
})

0 comments on commit b4af053

Please sign in to comment.