fsevents 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fsevents might be problematic. Click here for more details.
- package/node_modules/ansi-styles/package.json +4 -21
- package/node_modules/aws4/node_modules/lru-cache/README.md +1 -1
- package/node_modules/aws4/node_modules/lru-cache/lib/lru-cache.js +1 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/package.json +2 -1
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/package.json +2 -1
- package/node_modules/aws4/node_modules/lru-cache/package.json +20 -12
- package/node_modules/aws4/package.json +2 -1
- package/node_modules/bl/package.json +2 -1
- package/node_modules/chalk/package.json +22 -17
- package/node_modules/dashdash/node_modules/assert-plus/package.json +2 -1
- package/node_modules/dashdash/package.json +2 -1
- package/node_modules/escape-string-regexp/package.json +2 -1
- package/node_modules/form-data/package.json +2 -1
- package/node_modules/is-my-json-valid/package.json +2 -1
- package/node_modules/mime-db/package.json +2 -1
- package/node_modules/mime-types/package.json +2 -1
- package/node_modules/node-pre-gyp/CHANGELOG.md +6 -0
- package/node_modules/node-pre-gyp/lib/util/abi_crosswalk.json +8 -0
- package/node_modules/node-pre-gyp/lib/util/versioning.js +14 -2
- package/node_modules/node-pre-gyp/package.json +15 -15
- package/node_modules/oauth-sign/package.json +2 -1
- package/node_modules/once/package.json +1 -1
- package/node_modules/pinkie/package.json +2 -1
- package/node_modules/qs/package.json +2 -1
- package/node_modules/readable-stream/package.json +1 -1
- package/node_modules/request/package.json +2 -1
- package/node_modules/rimraf/node_modules/glob/package.json +2 -1
- package/node_modules/rimraf/package.json +2 -1
- package/node_modules/semver/package.json +2 -1
- package/node_modules/sshpk/package.json +2 -1
- package/node_modules/strip-ansi/package.json +2 -1
- package/node_modules/tar-pack/package.json +1 -1
- package/node_modules/tough-cookie/package.json +2 -1
- package/node_modules/tweetnacl/README.md +12 -4
- package/node_modules/tweetnacl/nacl-fast.js +1 -1
- package/node_modules/tweetnacl/nacl-fast.min.js +2 -2
- package/node_modules/tweetnacl/package.json +12 -11
- package/node_modules/verror/package.json +3 -2
- package/package.json +2 -2
- package/node_modules/ansi-styles/license +0 -21
- package/node_modules/aws4/node_modules/lru-cache/.npmignore +0 -4
- package/node_modules/aws4/node_modules/lru-cache/.travis.yml +0 -7
- package/node_modules/aws4/node_modules/lru-cache/CONTRIBUTORS +0 -14
- package/node_modules/aws4/node_modules/lru-cache/LICENSE +0 -15
- package/node_modules/aws4/node_modules/lru-cache/benchmarks/insertion-time.js +0 -32
- package/node_modules/aws4/node_modules/lru-cache/test/basic.js +0 -520
- package/node_modules/aws4/node_modules/lru-cache/test/foreach.js +0 -134
- package/node_modules/aws4/node_modules/lru-cache/test/inspect.js +0 -54
- package/node_modules/aws4/node_modules/lru-cache/test/no-symbol.js +0 -3
- package/node_modules/aws4/node_modules/lru-cache/test/serialize.js +0 -227
@@ -1,520 +0,0 @@
|
|
1
|
-
var test = require('tap').test
|
2
|
-
var LRU = require('../')
|
3
|
-
|
4
|
-
test('basic', function (t) {
|
5
|
-
var cache = new LRU({max: 10})
|
6
|
-
cache.set('key', 'value')
|
7
|
-
t.equal(cache.get('key'), 'value')
|
8
|
-
t.equal(cache.get('nada'), undefined)
|
9
|
-
t.equal(cache.length, 1)
|
10
|
-
t.equal(cache.max, 10)
|
11
|
-
t.end()
|
12
|
-
})
|
13
|
-
|
14
|
-
test('least recently set', function (t) {
|
15
|
-
var cache = new LRU(2)
|
16
|
-
cache.set('a', 'A')
|
17
|
-
cache.set('b', 'B')
|
18
|
-
cache.set('c', 'C')
|
19
|
-
t.equal(cache.get('c'), 'C')
|
20
|
-
t.equal(cache.get('b'), 'B')
|
21
|
-
t.equal(cache.get('a'), undefined)
|
22
|
-
t.end()
|
23
|
-
})
|
24
|
-
|
25
|
-
test('lru recently gotten', function (t) {
|
26
|
-
var cache = new LRU(2)
|
27
|
-
cache.set('a', 'A')
|
28
|
-
cache.set('b', 'B')
|
29
|
-
cache.get('a')
|
30
|
-
cache.set('c', 'C')
|
31
|
-
t.equal(cache.get('c'), 'C')
|
32
|
-
t.equal(cache.get('b'), undefined)
|
33
|
-
t.equal(cache.get('a'), 'A')
|
34
|
-
t.end()
|
35
|
-
})
|
36
|
-
|
37
|
-
test('del', function (t) {
|
38
|
-
var cache = new LRU(2)
|
39
|
-
cache.set('a', 'A')
|
40
|
-
cache.del('a')
|
41
|
-
t.equal(cache.get('a'), undefined)
|
42
|
-
t.end()
|
43
|
-
})
|
44
|
-
|
45
|
-
test('max', function (t) {
|
46
|
-
var cache = new LRU(3)
|
47
|
-
|
48
|
-
// test changing the max, verify that the LRU items get dropped.
|
49
|
-
cache.max = 100
|
50
|
-
var i
|
51
|
-
for (i = 0; i < 100; i++) cache.set(i, i)
|
52
|
-
t.equal(cache.length, 100)
|
53
|
-
for (i = 0; i < 100; i++) {
|
54
|
-
t.equal(cache.get(i), i)
|
55
|
-
}
|
56
|
-
cache.max = 3
|
57
|
-
t.equal(cache.length, 3)
|
58
|
-
for (i = 0; i < 97; i++) {
|
59
|
-
t.equal(cache.get(i), undefined)
|
60
|
-
}
|
61
|
-
for (i = 98; i < 100; i++) {
|
62
|
-
t.equal(cache.get(i), i)
|
63
|
-
}
|
64
|
-
|
65
|
-
// now remove the max restriction, and try again.
|
66
|
-
cache.max = 'hello'
|
67
|
-
for (i = 0; i < 100; i++) cache.set(i, i)
|
68
|
-
t.equal(cache.length, 100)
|
69
|
-
for (i = 0; i < 100; i++) {
|
70
|
-
t.equal(cache.get(i), i)
|
71
|
-
}
|
72
|
-
// should trigger an immediate resize
|
73
|
-
cache.max = 3
|
74
|
-
t.equal(cache.length, 3)
|
75
|
-
for (i = 0; i < 97; i++) {
|
76
|
-
t.equal(cache.get(i), undefined)
|
77
|
-
}
|
78
|
-
for (i = 98; i < 100; i++) {
|
79
|
-
t.equal(cache.get(i), i)
|
80
|
-
}
|
81
|
-
t.end()
|
82
|
-
})
|
83
|
-
|
84
|
-
test('reset', function (t) {
|
85
|
-
var cache = new LRU(10)
|
86
|
-
cache.set('a', 'A')
|
87
|
-
cache.set('b', 'B')
|
88
|
-
cache.reset()
|
89
|
-
t.equal(cache.length, 0)
|
90
|
-
t.equal(cache.max, 10)
|
91
|
-
t.equal(cache.get('a'), undefined)
|
92
|
-
t.equal(cache.get('b'), undefined)
|
93
|
-
t.end()
|
94
|
-
})
|
95
|
-
|
96
|
-
test('basic with weighed length', function (t) {
|
97
|
-
var cache = new LRU({
|
98
|
-
max: 100,
|
99
|
-
length: function (item, key) {
|
100
|
-
t.isa(key, 'string')
|
101
|
-
return item.size
|
102
|
-
}
|
103
|
-
})
|
104
|
-
cache.set('key', {val: 'value', size: 50})
|
105
|
-
t.equal(cache.get('key').val, 'value')
|
106
|
-
t.equal(cache.get('nada'), undefined)
|
107
|
-
t.equal(cache.lengthCalculator(cache.get('key'), 'key'), 50)
|
108
|
-
t.equal(cache.length, 50)
|
109
|
-
t.equal(cache.max, 100)
|
110
|
-
t.end()
|
111
|
-
})
|
112
|
-
|
113
|
-
test('weighed length item too large', function (t) {
|
114
|
-
var cache = new LRU({
|
115
|
-
max: 10,
|
116
|
-
length: function (item) { return item.size }
|
117
|
-
})
|
118
|
-
t.equal(cache.max, 10)
|
119
|
-
|
120
|
-
// should fall out immediately
|
121
|
-
cache.set('key', {val: 'value', size: 50})
|
122
|
-
|
123
|
-
t.equal(cache.length, 0)
|
124
|
-
t.equal(cache.get('key'), undefined)
|
125
|
-
t.end()
|
126
|
-
})
|
127
|
-
|
128
|
-
test('least recently set with weighed length', function (t) {
|
129
|
-
var cache = new LRU({
|
130
|
-
max: 8,
|
131
|
-
length: function (item) { return item.length }
|
132
|
-
})
|
133
|
-
cache.set('a', 'A')
|
134
|
-
cache.set('b', 'BB')
|
135
|
-
cache.set('c', 'CCC')
|
136
|
-
cache.set('d', 'DDDD')
|
137
|
-
t.equal(cache.get('d'), 'DDDD')
|
138
|
-
t.equal(cache.get('c'), 'CCC')
|
139
|
-
t.equal(cache.get('b'), undefined)
|
140
|
-
t.equal(cache.get('a'), undefined)
|
141
|
-
t.end()
|
142
|
-
})
|
143
|
-
|
144
|
-
test('lru recently gotten with weighed length', function (t) {
|
145
|
-
var cache = new LRU({
|
146
|
-
max: 8,
|
147
|
-
length: function (item) { return item.length }
|
148
|
-
})
|
149
|
-
cache.set('a', 'A')
|
150
|
-
cache.set('b', 'BB')
|
151
|
-
cache.set('c', 'CCC')
|
152
|
-
cache.get('a')
|
153
|
-
cache.get('b')
|
154
|
-
cache.set('d', 'DDDD')
|
155
|
-
t.equal(cache.get('c'), undefined)
|
156
|
-
t.equal(cache.get('d'), 'DDDD')
|
157
|
-
t.equal(cache.get('b'), 'BB')
|
158
|
-
t.equal(cache.get('a'), 'A')
|
159
|
-
t.end()
|
160
|
-
})
|
161
|
-
|
162
|
-
test('lru recently updated with weighed length', function (t) {
|
163
|
-
var cache = new LRU({
|
164
|
-
max: 8,
|
165
|
-
length: function (item) { return item.length }
|
166
|
-
})
|
167
|
-
cache.set('a', 'A')
|
168
|
-
cache.set('b', 'BB')
|
169
|
-
cache.set('c', 'CCC')
|
170
|
-
t.equal(cache.length, 6) // CCC BB A
|
171
|
-
cache.set('a', '+A')
|
172
|
-
t.equal(cache.length, 7) // +A CCC BB
|
173
|
-
cache.set('b', '++BB')
|
174
|
-
t.equal(cache.length, 6) // ++BB +A
|
175
|
-
t.equal(cache.get('c'), undefined)
|
176
|
-
|
177
|
-
cache.set('c', 'oversized')
|
178
|
-
t.equal(cache.length, 6) // ++BB +A
|
179
|
-
t.equal(cache.get('c'), undefined)
|
180
|
-
|
181
|
-
cache.set('a', 'oversized')
|
182
|
-
t.equal(cache.length, 4) // ++BB
|
183
|
-
t.equal(cache.get('a'), undefined)
|
184
|
-
t.equal(cache.get('b'), '++BB')
|
185
|
-
t.end()
|
186
|
-
})
|
187
|
-
|
188
|
-
test('set returns proper booleans', function (t) {
|
189
|
-
var cache = new LRU({
|
190
|
-
max: 5,
|
191
|
-
length: function (item) { return item.length }
|
192
|
-
})
|
193
|
-
|
194
|
-
t.equal(cache.set('a', 'A'), true)
|
195
|
-
|
196
|
-
// should return false for max exceeded
|
197
|
-
t.equal(cache.set('b', 'donuts'), false)
|
198
|
-
|
199
|
-
t.equal(cache.set('b', 'B'), true)
|
200
|
-
t.equal(cache.set('c', 'CCCC'), true)
|
201
|
-
t.end()
|
202
|
-
})
|
203
|
-
|
204
|
-
test('drop the old items', function (t) {
|
205
|
-
var cache = new LRU({
|
206
|
-
max: 5,
|
207
|
-
maxAge: 50
|
208
|
-
})
|
209
|
-
|
210
|
-
cache.set('a', 'A')
|
211
|
-
|
212
|
-
setTimeout(function () {
|
213
|
-
cache.set('b', 'b')
|
214
|
-
t.equal(cache.get('a'), 'A')
|
215
|
-
}, 25)
|
216
|
-
|
217
|
-
setTimeout(function () {
|
218
|
-
cache.set('c', 'C')
|
219
|
-
// timed out
|
220
|
-
t.notOk(cache.get('a'))
|
221
|
-
}, 60 + 25)
|
222
|
-
|
223
|
-
setTimeout(function () {
|
224
|
-
t.notOk(cache.get('b'))
|
225
|
-
t.equal(cache.get('c'), 'C')
|
226
|
-
}, 90)
|
227
|
-
|
228
|
-
setTimeout(function () {
|
229
|
-
t.notOk(cache.get('c'))
|
230
|
-
t.end()
|
231
|
-
}, 155)
|
232
|
-
})
|
233
|
-
|
234
|
-
test('manual pruning', function (t) {
|
235
|
-
var cache = new LRU({
|
236
|
-
max: 5,
|
237
|
-
maxAge: 50
|
238
|
-
})
|
239
|
-
|
240
|
-
cache.set('a', 'A')
|
241
|
-
cache.set('b', 'b')
|
242
|
-
cache.set('c', 'C')
|
243
|
-
|
244
|
-
setTimeout(function () {
|
245
|
-
cache.prune()
|
246
|
-
|
247
|
-
t.notOk(cache.get('a'))
|
248
|
-
t.notOk(cache.get('b'))
|
249
|
-
t.notOk(cache.get('c'))
|
250
|
-
|
251
|
-
t.end()
|
252
|
-
}, 100)
|
253
|
-
})
|
254
|
-
|
255
|
-
test('individual item can have its own maxAge', function (t) {
|
256
|
-
var cache = new LRU({
|
257
|
-
max: 5,
|
258
|
-
maxAge: 50
|
259
|
-
})
|
260
|
-
|
261
|
-
cache.set('a', 'A', 20)
|
262
|
-
setTimeout(function () {
|
263
|
-
t.notOk(cache.get('a'))
|
264
|
-
t.end()
|
265
|
-
}, 25)
|
266
|
-
})
|
267
|
-
|
268
|
-
test('individual item can have its own maxAge > cache', function (t) {
|
269
|
-
var cache = new LRU({
|
270
|
-
max: 5,
|
271
|
-
maxAge: 20
|
272
|
-
})
|
273
|
-
|
274
|
-
cache.set('a', 'A', 50)
|
275
|
-
setTimeout(function () {
|
276
|
-
t.equal(cache.get('a'), 'A')
|
277
|
-
t.end()
|
278
|
-
}, 25)
|
279
|
-
})
|
280
|
-
|
281
|
-
test('disposal function', function (t) {
|
282
|
-
var disposed = false
|
283
|
-
var cache = new LRU({
|
284
|
-
max: 1,
|
285
|
-
dispose: function (k, n) {
|
286
|
-
disposed = n
|
287
|
-
}
|
288
|
-
})
|
289
|
-
|
290
|
-
cache.set(1, 1)
|
291
|
-
cache.set(2, 2)
|
292
|
-
t.equal(disposed, 1)
|
293
|
-
cache.set(2, 10)
|
294
|
-
t.equal(disposed, 2)
|
295
|
-
cache.set(3, 3)
|
296
|
-
t.equal(disposed, 10)
|
297
|
-
cache.reset()
|
298
|
-
t.equal(disposed, 3)
|
299
|
-
t.end()
|
300
|
-
})
|
301
|
-
|
302
|
-
test('disposal function on too big of item', function (t) {
|
303
|
-
var disposed = false
|
304
|
-
var cache = new LRU({
|
305
|
-
max: 1,
|
306
|
-
length: function (k) {
|
307
|
-
return k.length
|
308
|
-
},
|
309
|
-
dispose: function (k, n) {
|
310
|
-
disposed = n
|
311
|
-
}
|
312
|
-
})
|
313
|
-
var obj = [ 1, 2 ]
|
314
|
-
|
315
|
-
t.equal(disposed, false)
|
316
|
-
cache.set('obj', obj)
|
317
|
-
t.equal(disposed, obj)
|
318
|
-
t.end()
|
319
|
-
})
|
320
|
-
|
321
|
-
test('has()', function (t) {
|
322
|
-
var cache = new LRU({
|
323
|
-
max: 1,
|
324
|
-
maxAge: 10
|
325
|
-
})
|
326
|
-
|
327
|
-
cache.set('foo', 'bar')
|
328
|
-
t.equal(cache.has('foo'), true)
|
329
|
-
cache.set('blu', 'baz')
|
330
|
-
t.equal(cache.has('foo'), false)
|
331
|
-
t.equal(cache.has('blu'), true)
|
332
|
-
setTimeout(function () {
|
333
|
-
t.equal(cache.has('blu'), false)
|
334
|
-
t.end()
|
335
|
-
}, 15)
|
336
|
-
})
|
337
|
-
|
338
|
-
test('stale', function (t) {
|
339
|
-
var cache = new LRU({
|
340
|
-
maxAge: 10,
|
341
|
-
stale: true
|
342
|
-
})
|
343
|
-
|
344
|
-
t.equal(cache.allowStale, true)
|
345
|
-
|
346
|
-
cache.set('foo', 'bar')
|
347
|
-
t.equal(cache.get('foo'), 'bar')
|
348
|
-
t.equal(cache.has('foo'), true)
|
349
|
-
setTimeout(function () {
|
350
|
-
t.equal(cache.has('foo'), false)
|
351
|
-
t.equal(cache.get('foo'), 'bar')
|
352
|
-
t.equal(cache.get('foo'), undefined)
|
353
|
-
t.end()
|
354
|
-
}, 15)
|
355
|
-
})
|
356
|
-
|
357
|
-
test('lru update via set', function (t) {
|
358
|
-
var cache = LRU({ max: 2 })
|
359
|
-
|
360
|
-
cache.set('foo', 1)
|
361
|
-
cache.set('bar', 2)
|
362
|
-
cache.del('bar')
|
363
|
-
cache.set('baz', 3)
|
364
|
-
cache.set('qux', 4)
|
365
|
-
|
366
|
-
t.equal(cache.get('foo'), undefined)
|
367
|
-
t.equal(cache.get('bar'), undefined)
|
368
|
-
t.equal(cache.get('baz'), 3)
|
369
|
-
t.equal(cache.get('qux'), 4)
|
370
|
-
t.end()
|
371
|
-
})
|
372
|
-
|
373
|
-
test('least recently set w/ peek', function (t) {
|
374
|
-
var cache = new LRU(2)
|
375
|
-
cache.set('a', 'A')
|
376
|
-
cache.set('b', 'B')
|
377
|
-
t.equal(cache.peek('a'), 'A')
|
378
|
-
cache.set('c', 'C')
|
379
|
-
t.equal(cache.get('c'), 'C')
|
380
|
-
t.equal(cache.get('b'), 'B')
|
381
|
-
t.equal(cache.get('a'), undefined)
|
382
|
-
t.end()
|
383
|
-
})
|
384
|
-
|
385
|
-
test('pop the least used item', function (t) {
|
386
|
-
var cache = new LRU(3)
|
387
|
-
var last
|
388
|
-
|
389
|
-
cache.set('a', 'A')
|
390
|
-
cache.set('b', 'B')
|
391
|
-
cache.set('c', 'C')
|
392
|
-
|
393
|
-
t.equal(cache.length, 3)
|
394
|
-
t.equal(cache.max, 3)
|
395
|
-
|
396
|
-
// Ensure we pop a, c, b
|
397
|
-
cache.get('b', 'B')
|
398
|
-
|
399
|
-
last = cache.pop()
|
400
|
-
t.equal(last.key, 'a')
|
401
|
-
t.equal(last.value, 'A')
|
402
|
-
t.equal(cache.length, 2)
|
403
|
-
t.equal(cache.max, 3)
|
404
|
-
|
405
|
-
last = cache.pop()
|
406
|
-
t.equal(last.key, 'c')
|
407
|
-
t.equal(last.value, 'C')
|
408
|
-
t.equal(cache.length, 1)
|
409
|
-
t.equal(cache.max, 3)
|
410
|
-
|
411
|
-
last = cache.pop()
|
412
|
-
t.equal(last.key, 'b')
|
413
|
-
t.equal(last.value, 'B')
|
414
|
-
t.equal(cache.length, 0)
|
415
|
-
t.equal(cache.max, 3)
|
416
|
-
|
417
|
-
last = cache.pop()
|
418
|
-
t.equal(last, null)
|
419
|
-
t.equal(cache.length, 0)
|
420
|
-
t.equal(cache.max, 3)
|
421
|
-
|
422
|
-
t.end()
|
423
|
-
})
|
424
|
-
|
425
|
-
test('get and set only accepts strings and numbers as keys', function (t) {
|
426
|
-
var cache = new LRU()
|
427
|
-
|
428
|
-
cache.set('key', 'value')
|
429
|
-
cache.set(123, 456)
|
430
|
-
|
431
|
-
t.equal(cache.get('key'), 'value')
|
432
|
-
t.equal(cache.get(123), 456)
|
433
|
-
|
434
|
-
t.end()
|
435
|
-
})
|
436
|
-
|
437
|
-
test('peek with wierd keys', function (t) {
|
438
|
-
var cache = new LRU()
|
439
|
-
|
440
|
-
cache.set('key', 'value')
|
441
|
-
cache.set(123, 456)
|
442
|
-
|
443
|
-
t.equal(cache.peek('key'), 'value')
|
444
|
-
t.equal(cache.peek(123), 456)
|
445
|
-
|
446
|
-
t.equal(cache.peek({
|
447
|
-
toString: function () { return 'key' }
|
448
|
-
}), undefined)
|
449
|
-
|
450
|
-
t.end()
|
451
|
-
})
|
452
|
-
|
453
|
-
test('invalid length calc results in basic length', function (t) {
|
454
|
-
var l = new LRU({ length: true })
|
455
|
-
t.isa(l.lengthCalculator, 'function')
|
456
|
-
l.lengthCalculator = 'not a function'
|
457
|
-
t.isa(l.lengthCalculator, 'function')
|
458
|
-
t.end()
|
459
|
-
})
|
460
|
-
|
461
|
-
test('change length calculator recalculates', function (t) {
|
462
|
-
var l = new LRU({ max: 3 })
|
463
|
-
l.set(2, 2)
|
464
|
-
l.set(1, 1)
|
465
|
-
l.lengthCalculator = function (key, val) {
|
466
|
-
return key + val
|
467
|
-
}
|
468
|
-
t.equal(l.itemCount, 1)
|
469
|
-
t.equal(l.get(2), undefined)
|
470
|
-
t.equal(l.get(1), 1)
|
471
|
-
l.set(0, 1)
|
472
|
-
t.equal(l.itemCount, 2)
|
473
|
-
l.lengthCalculator = function (key, val) {
|
474
|
-
return key
|
475
|
-
}
|
476
|
-
t.equal(l.lengthCalculator(1, 10), 1)
|
477
|
-
t.equal(l.lengthCalculator(10, 1), 10)
|
478
|
-
l.lengthCalculator = { not: 'a function' }
|
479
|
-
t.equal(l.lengthCalculator(1, 10), 1)
|
480
|
-
t.equal(l.lengthCalculator(10, 1), 1)
|
481
|
-
t.end()
|
482
|
-
})
|
483
|
-
|
484
|
-
test('delete non-existent item has no effect', function (t) {
|
485
|
-
var l = new LRU({ max: 2 })
|
486
|
-
l.set('foo', 1)
|
487
|
-
l.set('bar', 2)
|
488
|
-
l.del('baz')
|
489
|
-
t.same(l.dumpLru().toArray().map(function (hit) {
|
490
|
-
return hit.key
|
491
|
-
}), [ 'bar', 'foo' ])
|
492
|
-
t.end()
|
493
|
-
})
|
494
|
-
|
495
|
-
test('maxAge on list, cleared in forEach', function (t) {
|
496
|
-
var l = new LRU({ stale: true })
|
497
|
-
l.set('foo', 1)
|
498
|
-
|
499
|
-
// hacky. make it seem older.
|
500
|
-
l.dumpLru().head.value.now = Date.now() - 100000
|
501
|
-
|
502
|
-
// setting maxAge to invalid values does nothing.
|
503
|
-
t.equal(l.maxAge, 0)
|
504
|
-
l.maxAge = -100
|
505
|
-
t.equal(l.maxAge, 0)
|
506
|
-
l.maxAge = {}
|
507
|
-
t.equal(l.maxAge, 0)
|
508
|
-
|
509
|
-
l.maxAge = 1
|
510
|
-
|
511
|
-
var saw = false
|
512
|
-
l.forEach(function (val, key) {
|
513
|
-
saw = true
|
514
|
-
t.equal(key, 'foo')
|
515
|
-
})
|
516
|
-
t.ok(saw)
|
517
|
-
t.equal(l.length, 0)
|
518
|
-
|
519
|
-
t.end()
|
520
|
-
})
|
@@ -1,134 +0,0 @@
|
|
1
|
-
var test = require('tap').test
|
2
|
-
var LRU = require('../')
|
3
|
-
|
4
|
-
test('forEach', function (t) {
|
5
|
-
var l = new LRU(5)
|
6
|
-
var i
|
7
|
-
for (i = 0; i < 10; i++) {
|
8
|
-
l.set(i, i.toString(2))
|
9
|
-
}
|
10
|
-
|
11
|
-
i = 9
|
12
|
-
l.forEach(function (val, key, cache) {
|
13
|
-
t.equal(cache, l)
|
14
|
-
t.equal(key, i)
|
15
|
-
t.equal(val, i.toString(2))
|
16
|
-
i -= 1
|
17
|
-
})
|
18
|
-
|
19
|
-
// get in order of most recently used
|
20
|
-
l.get(6)
|
21
|
-
l.get(8)
|
22
|
-
|
23
|
-
var order = [ 8, 6, 9, 7, 5 ]
|
24
|
-
i = 0
|
25
|
-
|
26
|
-
l.forEach(function (val, key, cache) {
|
27
|
-
var j = order[i++]
|
28
|
-
t.equal(cache, l)
|
29
|
-
t.equal(key, j)
|
30
|
-
t.equal(val, j.toString(2))
|
31
|
-
})
|
32
|
-
t.equal(i, order.length)
|
33
|
-
|
34
|
-
i = 0
|
35
|
-
order.reverse()
|
36
|
-
l.rforEach(function (val, key, cache) {
|
37
|
-
var j = order[i++]
|
38
|
-
t.equal(cache, l)
|
39
|
-
t.equal(key, j)
|
40
|
-
t.equal(val, j.toString(2))
|
41
|
-
})
|
42
|
-
t.equal(i, order.length)
|
43
|
-
|
44
|
-
t.end()
|
45
|
-
})
|
46
|
-
|
47
|
-
test('keys() and values()', function (t) {
|
48
|
-
var l = new LRU(5)
|
49
|
-
var i
|
50
|
-
for (i = 0; i < 10; i++) {
|
51
|
-
l.set(i, i.toString(2))
|
52
|
-
}
|
53
|
-
|
54
|
-
t.similar(l.keys(), [9, 8, 7, 6, 5])
|
55
|
-
t.similar(l.values(), ['1001', '1000', '111', '110', '101'])
|
56
|
-
|
57
|
-
// get in order of most recently used
|
58
|
-
l.get(6)
|
59
|
-
l.get(8)
|
60
|
-
|
61
|
-
t.similar(l.keys(), [8, 6, 9, 7, 5])
|
62
|
-
t.similar(l.values(), ['1000', '110', '1001', '111', '101'])
|
63
|
-
|
64
|
-
t.end()
|
65
|
-
})
|
66
|
-
|
67
|
-
test('all entries are iterated over', function (t) {
|
68
|
-
var l = new LRU(5)
|
69
|
-
var i
|
70
|
-
for (i = 0; i < 10; i++) {
|
71
|
-
l.set(i.toString(), i.toString(2))
|
72
|
-
}
|
73
|
-
|
74
|
-
i = 0
|
75
|
-
l.forEach(function (val, key, cache) {
|
76
|
-
if (i > 0) {
|
77
|
-
cache.del(key)
|
78
|
-
}
|
79
|
-
i += 1
|
80
|
-
})
|
81
|
-
|
82
|
-
t.equal(i, 5)
|
83
|
-
t.equal(l.keys().length, 1)
|
84
|
-
|
85
|
-
t.end()
|
86
|
-
})
|
87
|
-
|
88
|
-
test('all stale entries are removed', function (t) {
|
89
|
-
var l = new LRU({ max: 5, maxAge: -5, stale: true })
|
90
|
-
var i
|
91
|
-
for (i = 0; i < 10; i++) {
|
92
|
-
l.set(i.toString(), i.toString(2))
|
93
|
-
}
|
94
|
-
|
95
|
-
i = 0
|
96
|
-
l.forEach(function () {
|
97
|
-
i += 1
|
98
|
-
})
|
99
|
-
|
100
|
-
t.equal(i, 5)
|
101
|
-
t.equal(l.keys().length, 0)
|
102
|
-
|
103
|
-
t.end()
|
104
|
-
})
|
105
|
-
|
106
|
-
test('expires', function (t) {
|
107
|
-
var l = new LRU({
|
108
|
-
max: 10,
|
109
|
-
maxAge: 50
|
110
|
-
})
|
111
|
-
var i
|
112
|
-
for (i = 0; i < 10; i++) {
|
113
|
-
l.set(i.toString(), i.toString(2), ((i % 2) ? 25 : undefined))
|
114
|
-
}
|
115
|
-
|
116
|
-
i = 0
|
117
|
-
var order = [ 8, 6, 4, 2, 0 ]
|
118
|
-
setTimeout(function () {
|
119
|
-
l.forEach(function (val, key, cache) {
|
120
|
-
var j = order[i++]
|
121
|
-
t.equal(cache, l)
|
122
|
-
t.equal(key, j.toString())
|
123
|
-
t.equal(val, j.toString(2))
|
124
|
-
})
|
125
|
-
t.equal(i, order.length)
|
126
|
-
|
127
|
-
setTimeout(function () {
|
128
|
-
var count = 0
|
129
|
-
l.forEach(function (val, key, cache) { count++ })
|
130
|
-
t.equal(0, count)
|
131
|
-
t.end()
|
132
|
-
}, 25)
|
133
|
-
}, 26)
|
134
|
-
})
|
@@ -1,54 +0,0 @@
|
|
1
|
-
// vim: set nowrap:
|
2
|
-
var util = require('util')
|
3
|
-
var t = require('tap')
|
4
|
-
var LRU = require('../')
|
5
|
-
|
6
|
-
var l = LRU()
|
7
|
-
|
8
|
-
function inspect (str) {
|
9
|
-
t.equal(util.inspect(l), str)
|
10
|
-
t.equal(l.inspect(), str)
|
11
|
-
}
|
12
|
-
|
13
|
-
inspect('LRUCache {}')
|
14
|
-
|
15
|
-
l.max = 10
|
16
|
-
inspect('LRUCache {\n max: 10\n}')
|
17
|
-
|
18
|
-
l.maxAge = 50
|
19
|
-
inspect('LRUCache {\n max: 10,\n maxAge: 50\n}')
|
20
|
-
|
21
|
-
l.set({ foo: 'bar' }, 'baz')
|
22
|
-
inspect("LRUCache {\n max: 10,\n maxAge: 50,\n\n { foo: 'bar' } => { value: 'baz' }\n}")
|
23
|
-
|
24
|
-
l.maxAge = 0
|
25
|
-
l.set(1, {a: {b: {c: {d: {e: {f: {}}}}}}})
|
26
|
-
inspect("LRUCache {\n max: 10,\n\n 1 => { value: { a: { b: [Object] } } },\n { foo: 'bar' } => { value: 'baz', maxAge: 50 }\n}")
|
27
|
-
|
28
|
-
l.allowStale = true
|
29
|
-
inspect("LRUCache {\n allowStale: true,\n max: 10,\n\n 1 => { value: { a: { b: [Object] } } },\n { foo: 'bar' } => { value: 'baz', maxAge: 50 }\n}")
|
30
|
-
|
31
|
-
setTimeout(function () {
|
32
|
-
inspect("LRUCache {\n allowStale: true,\n max: 10,\n\n 1 => { value: { a: { b: [Object] } } },\n { foo: 'bar' } => { value: 'baz', maxAge: 50, stale: true }\n}")
|
33
|
-
|
34
|
-
// prune stale items
|
35
|
-
l.forEach(function () {})
|
36
|
-
inspect('LRUCache {\n allowStale: true,\n max: 10,\n\n 1 => { value: { a: { b: [Object] } } }\n}')
|
37
|
-
|
38
|
-
l.lengthCalculator = function () { return 5 }
|
39
|
-
inspect('LRUCache {\n allowStale: true,\n max: 10,\n length: 5,\n\n 1 => { value: { a: { b: [Object] } }, length: 5 }\n}')
|
40
|
-
|
41
|
-
l.max = 0
|
42
|
-
inspect('LRUCache {\n allowStale: true,\n length: 5,\n\n 1 => { value: { a: { b: [Object] } }, length: 5 }\n}')
|
43
|
-
|
44
|
-
l.maxAge = 100
|
45
|
-
inspect('LRUCache {\n allowStale: true,\n maxAge: 100,\n length: 5,\n\n 1 => { value: { a: { b: [Object] } }, maxAge: 0, length: 5 }\n}')
|
46
|
-
l.allowStale = false
|
47
|
-
inspect('LRUCache {\n maxAge: 100,\n length: 5,\n\n 1 => { value: { a: { b: [Object] } }, maxAge: 0, length: 5 }\n}')
|
48
|
-
|
49
|
-
l.maxAge = 0
|
50
|
-
inspect('LRUCache {\n length: 5,\n\n 1 => { value: { a: { b: [Object] } }, length: 5 }\n}')
|
51
|
-
|
52
|
-
l.lengthCalculator = null
|
53
|
-
inspect('LRUCache {\n 1 => { value: { a: { b: [Object] } } }\n}')
|
54
|
-
}, 100)
|