Skip to content

Commit

Permalink
test: add test for the async generator filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Aug 15, 2023
1 parent 440e470 commit 74afcbc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/bdb-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,30 @@ describe('BDB', function() {
assert.strictEqual(values[0].toString('hex'), vectors[0].value);
assert.strictEqual(valuesIter.finished, true);
});

it('should pass iterator to fn', async () => {
const valuesIter = bucket.valuesAsync({
gte: nkey.min(),
lte: nkey.max()
});

const filter = async function*(iter) {
for await (const item of iter) {
if (item[0] === 0x8b)
yield item;

continue;
}
};

const values = [];

for await (const value of filter(valuesIter))
values.push(value);

assert.strictEqual(values.length, 1);
assert.strictEqual(values[0][0], 0x8b);
});
});

describe('thread safety', function() {
Expand Down

0 comments on commit 74afcbc

Please sign in to comment.