|
| 1 | +const test = require('tape') |
| 2 | +const concat = require('level-concat-iterator') |
| 3 | +const testCommon = require('./common') |
| 4 | +const rangeOptions = 'start end gt gte lt lte'.split(' ') |
| 5 | + |
| 6 | +test('empty range options are ignored', function (t) { |
| 7 | + const db = testCommon.factory() |
| 8 | + |
| 9 | + t.test('setup', function (t) { |
| 10 | + db.open(function (err) { |
| 11 | + t.ifError(err, 'no open error') |
| 12 | + |
| 13 | + db.batch() |
| 14 | + .put(Buffer.from([0]), 'value') |
| 15 | + .put(Buffer.from([126]), 'value') |
| 16 | + .write(t.end.bind(t)) |
| 17 | + }) |
| 18 | + }) |
| 19 | + |
| 20 | + rangeOptions.forEach(function (option) { |
| 21 | + t.test(option, function (t) { |
| 22 | + t.plan(8) |
| 23 | + |
| 24 | + concat(db.iterator({ [option]: Buffer.alloc(0) }), verifyBuffer) |
| 25 | + concat(db.iterator({ [option]: Buffer.alloc(0), keyAsBuffer: false }), verifyString) |
| 26 | + concat(db.iterator({ [option]: '' }), verifyBuffer) |
| 27 | + concat(db.iterator({ [option]: '', keyAsBuffer: false }), verifyString) |
| 28 | + |
| 29 | + function verifyBuffer (err, entries) { |
| 30 | + t.ifError(err, 'no concat error') |
| 31 | + t.same(entries.map(getKey), [Buffer.from([0]), Buffer.from([126])]) |
| 32 | + } |
| 33 | + |
| 34 | + function verifyString (err, entries) { |
| 35 | + t.ifError(err, 'no concat error') |
| 36 | + t.same(entries.map(getKey), ['\x00', '~']) |
| 37 | + } |
| 38 | + |
| 39 | + function getKey (entry) { |
| 40 | + return entry.key |
| 41 | + } |
| 42 | + }) |
| 43 | + }) |
| 44 | + |
| 45 | + t.test('teardown', function (t) { |
| 46 | + db.close(t.end.bind(t)) |
| 47 | + }) |
| 48 | + |
| 49 | + t.end() |
| 50 | +}) |
0 commit comments