-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathhidden.js
126 lines (113 loc) · 3.39 KB
/
hidden.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const tape = require('tape')
const create = require('./helpers/create')
tape('hidden put is hidden', function (t) {
const db = create()
db.put('hello', 'world', { hidden: true }, function (err) {
t.error(err, 'no error')
db.get('hello', function (err, node) {
t.error(err, 'no error')
t.same(node, null)
db.get('hello', { hidden: true }, function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'world')
t.end()
})
})
})
})
tape('hidden and non hidden do not collide', function (t) {
const db = create()
db.put('hello', 'hidden', { hidden: true }, function (err) {
t.error(err, 'no error')
db.put('hello', 'not hidden', function (err) {
t.error(err, 'no error')
db.get('hello', function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'not hidden')
db.get('hello', { hidden: true }, function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'hidden')
t.end()
})
})
})
})
})
tape('batch hidden and non hidden do not collide', function (t) {
const db = create()
db.batch([
{ type: 'put', key: 'hello', value: 'hidden', hidden: true },
{ type: 'put', key: 'hello', value: 'not hidden' }
], function (err) {
t.error(err, 'no error')
db.get('hello', function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'not hidden')
db.get('hello', { hidden: true }, function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'hidden')
t.end()
})
})
})
})
tape('put 4 non hidden and one hidden', function (t) {
const db = create()
db.put('a', 'a', function () {
db.put('hello', 'hello', { hidden: true }, function () {
db.put('b', 'b', function () {
db.put('c', 'c', function () {
db.put('d', 'd', function () {
db.get('hello', { hidden: true }, function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'hello')
t.end()
})
})
})
})
})
})
})
tape('hidden iterators', function (t) {
const db = create()
db.batch([
{ type: 'put', key: 'a', value: 'a' },
{ type: 'put', key: 'hello', value: 'hello', hidden: true },
{ type: 'put', key: 'b', value: 'b' },
{ type: 'put', key: 'c', value: 'c' },
{ type: 'put', key: 'world', value: 'world', hidden: true },
{ type: 'put', key: 'd', value: 'd' }
], function (err) {
t.error(err, 'no error')
db.list(function (err, nodes) {
t.error(err, 'no error')
const values = nodes.map(n => n.value).sort()
t.same(values, [ 'a', 'b', 'c', 'd' ])
db.list('', { hidden: true }, function (err, nodes) {
t.error(err, 'no error')
const values = nodes.map(n => n.value).sort()
t.same(values, [ 'hello', 'world' ])
t.end()
})
})
})
})
tape('hidden deletes', function (t) {
t.plan(4)
const db = create()
db.put('a', 'a', { hidden: true }, function () {
db.put('a', 'b', function () {
db.del('a', { hidden: true }, function () {
db.get('a', function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'b')
})
db.get('a', { hidden: true }, function (err, node) {
t.error(err, 'no error')
t.same(node, null)
})
})
})
})
})