This repository has been archived by the owner on Mar 30, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
test-browser.js
64 lines (49 loc) · 1.64 KB
/
test-browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict'
var test = require('tape')
var leveljs = require('level-js')
var testCommon = require('level-js/test/util/test-common')
var levelup = require('levelup')
var level = require('./')
var encoding = require('encoding-down')
require('level-packager/abstract/base-test')(test, level)
require('level-packager/abstract/db-values-test')(test, level)
test('setup', testCommon.setUp)
test('levelup put', function (t) {
t.plan(4)
var down = leveljs(testCommon.location())
var db = levelup(down)
db.put('name', 'LevelUP string', function (err) {
t.ifError(err, 'no put error')
db.get('name', { asBuffer: false }, function (err, value) {
t.ifError(err, 'no get error')
t.is(value, 'LevelUP string')
db.close(function (err) {
t.ifError(err, 'no close error')
})
})
})
})
test('binary', function (t) {
t.plan(9)
var down = leveljs(testCommon.location())
var db = levelup(encoding(down, { valueEncoding: 'binary' }))
var buf = Buffer.from('00ff', 'hex')
db.put('binary', buf, function (err) {
t.ifError(err, 'no put error')
db.get('binary', function (err, value) {
t.ifError(err, 'no get error')
t.ok(Buffer.isBuffer(value), 'is a buffer')
t.same(value, buf)
db.get('binary', { valueEncoding: 'id' }, function (err, value) {
t.ifError(err, 'no get error')
t.notOk(Buffer.isBuffer(value), 'is not a buffer')
t.ok(value instanceof Uint8Array, 'is a Uint8Array')
t.same(Buffer.from(value), buf)
db.close(function (err) {
t.ifError(err, 'no close error')
})
})
})
})
})
test('teardown', testCommon.tearDown)