-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
172 lines (155 loc) · 4.05 KB
/
index.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const test = require('ava');
const SharedArrayBufferStore = require('../lib/index');
test('init', t => {
const instance = new SharedArrayBufferStore();
t.is(instance.keyArray instanceof Uint32Array, true);
t.is(instance.valueArray instanceof Uint32Array, true);
});
test('change length', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 10,
valueBufferLength: 20
});
t.is(instance.keyArray.length, 10);
t.is(instance.valueArray.length, 20);
});
test('get, key is undefined', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 10,
valueBufferLength: 20
});
t.is(instance.get('test'), undefined);
});
test('get and set', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
t.is(instance.get('name'), 'test');
});
test('get and set, length not enough', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 10,
valueBufferLength: 20
});
try {
instance.set('name', 'test');
t.is(1, 2);
} catch (e) {
t.is(e instanceof Error, true);
}
});
test('get and set, reset', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.set('name', 'test2');
t.is(instance.get('name'), 'test2');
});
test('get and set, reset2', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.set('name', 't');
t.is(instance.get('name'), 't');
});
test('get and set, reset4', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.set('name', 'wwww');
t.is(instance.get('name'), 'wwww');
});
test('get, buffer', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.set('name', 't');
const data = instance.get('name', null);
t.is(data instanceof Buffer, true);
t.is(data[0], 116);
});
test('delete', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.delete('name');
// console.log(instance.keyArray)
t.is(instance.get('name'), undefined);
});
test('delete 2', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.delete('name');
t.is(instance.get('name'), undefined);
});
test('delete 3', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.delete('name2');
t.is(instance.get('name'), 'test');
});
test('delete 4', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.set('name1', 'test');
instance.delete('name');
t.is(instance.get('name1'), 'test');
});
test('get keys', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.set('name1', 'test');
instance.delete('name');
t.deepEqual(instance.keys(), ['name1']);
});
test('get keys 2', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
instance.set('name', 'test');
instance.set('name1', 'test');
t.deepEqual(instance.keys(), ['name', 'name1']);
});
test('get keys 3', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 200
});
t.deepEqual(instance.keys(), []);
});
test('set error', t => {
const instance = new SharedArrayBufferStore({
keyBufferLength: 100,
valueBufferLength: 20
});
try {
instance.set('value', 'fasdfafasdfasdfasdfafd');
t.is(1, 2);
} catch (e) {
t.is(e instanceof Error, true);
}
});