File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -293,5 +293,43 @@ exports.seek = function (test, testCommon) {
293
293
} )
294
294
}
295
295
} )
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
+ }
296
334
}
297
335
}
You can’t perform that action at this time.
0 commit comments