Skip to content

Commit 52a078f

Browse files
committed
Test buffer values
1 parent 3c54d51 commit 52a078f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/encoding-buffer-test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ exports.all = function (test, testCommon) {
1111
const db = testCommon.factory()
1212
await db.open()
1313
await db.put('test', testBuffer(), { valueEncoding: 'buffer' })
14+
1415
t.same(await db.get('test', { valueEncoding: 'buffer' }), testBuffer())
16+
17+
if (testCommon.supports.getSync) {
18+
t.same(db.getSync('test', { valueEncoding: 'buffer' }), testBuffer(), 'sync')
19+
}
20+
1521
return db.close()
1622
})
1723

@@ -20,7 +26,13 @@ exports.all = function (test, testCommon) {
2026
const db = testCommon.factory({ valueEncoding: 'buffer' })
2127
await db.open()
2228
await db.put('test', testBuffer())
29+
2330
t.same(await db.get('test'), testBuffer())
31+
32+
if (testCommon.supports.getSync) {
33+
t.same(db.getSync('test'), testBuffer(), 'sync')
34+
}
35+
2436
return db.close()
2537
})
2638

@@ -29,7 +41,13 @@ exports.all = function (test, testCommon) {
2941
const db = testCommon.factory()
3042
await db.open()
3143
await db.put(testBuffer(), 'test', { keyEncoding: 'buffer' })
44+
3245
t.same(await db.get(testBuffer(), { keyEncoding: 'buffer' }), 'test')
46+
47+
if (testCommon.supports.getSync) {
48+
t.same(db.getSync(testBuffer(), { keyEncoding: 'buffer' }), 'test', 'sync')
49+
}
50+
3351
return db.close()
3452
})
3553

@@ -38,7 +56,13 @@ exports.all = function (test, testCommon) {
3856
const db = testCommon.factory()
3957
await db.open()
4058
await db.put(Buffer.from('foo🐄'), 'test', { keyEncoding: 'utf8' })
59+
4160
t.same(await db.get(Buffer.from('foo🐄'), { keyEncoding: 'utf8' }), 'test')
61+
62+
if (testCommon.supports.getSync) {
63+
t.same(db.getSync(Buffer.from('foo🐄'), { keyEncoding: 'utf8' }), 'test', 'sync')
64+
}
65+
4266
return db.close()
4367
})
4468

@@ -47,8 +71,15 @@ exports.all = function (test, testCommon) {
4771
const db = testCommon.factory()
4872
await db.open()
4973
await db.put('test', 'foo🐄', { valueEncoding: 'buffer' })
74+
5075
t.same(await db.get('test', { valueEncoding: 'buffer' }), Buffer.from('foo🐄'))
5176
t.same(await db.get('test', { valueEncoding: 'utf8' }), 'foo🐄')
77+
78+
if (testCommon.supports.getSync) {
79+
t.same(db.getSync('test', { valueEncoding: 'buffer' }), Buffer.from('foo🐄'), 'sync')
80+
t.same(db.getSync('test', { valueEncoding: 'utf8' }), 'foo🐄', 'sync')
81+
}
82+
5283
return db.close()
5384
})
5485

@@ -62,11 +93,19 @@ exports.all = function (test, testCommon) {
6293
const promise1 = db.put(a, a).then(async () => {
6394
const value = await db.get(Buffer.from(a), enc)
6495
t.same(value, Buffer.from(a), 'got buffer value')
96+
97+
if (testCommon.supports.getSync) {
98+
t.same(db.getSync(Buffer.from(a), enc), Buffer.from(a), 'got buffer value (sync)')
99+
}
65100
})
66101

67102
const promise2 = db.put(Buffer.from(b), Buffer.from(b), enc).then(async () => {
68103
const value = await db.get(b)
69104
t.same(value, b, 'got string value')
105+
106+
if (testCommon.supports.getSync) {
107+
t.same(db.getSync(b), b, 'got string value (sync)')
108+
}
70109
})
71110

72111
await Promise.all([promise1, promise2])

0 commit comments

Comments
 (0)