Skip to content

Commit 90ee9b5

Browse files
authored
Test seeking outside of range options (#113)
Closes a code coverage gap in memory-level. Category: fix
1 parent 6e72c9d commit 90ee9b5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/iterator-seek-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,5 +293,43 @@ exports.seek = function (test, testCommon) {
293293
})
294294
}
295295
})
296+
297+
// Tests the specific case where an iterator can (theoretically) tell that
298+
// a seek() would be out of range by comparing the seek target against
299+
// range options, before performing an actual seek. MemoryLevel works this
300+
// way for example. Also test the same scenario without an explicit seek()
301+
// which should have the same result.
302+
for (const reverse of [false, true]) {
303+
for (const seek of [true, false]) {
304+
const props = `reverse = ${reverse}, seek = ${seek}`
305+
const name = `${mode}() seek outside of range options (${props})`
306+
const key = 'a'
307+
308+
test(name, async function (t) {
309+
const db = testCommon.factory()
310+
311+
await db.open()
312+
await db.put(key, '123')
313+
314+
// Pick ranges that exclude the key
315+
const ranges = [
316+
{ gt: 'x', reverse },
317+
{ gte: 'x', reverse },
318+
{ lt: '0', reverse },
319+
{ lte: '0', reverse }
320+
]
321+
322+
// Test each range
323+
for (let i = 0; i < ranges.length; i++) {
324+
const iterator = db[mode](ranges[i])
325+
if (seek) iterator.seek(key)
326+
t.same(await iterator.next(), undefined, `end of iterator ${i}`)
327+
await iterator.close()
328+
}
329+
330+
return db.close()
331+
})
332+
}
333+
}
296334
}
297335
}

0 commit comments

Comments
 (0)