stylus-source 0.31.0 → 0.32.0

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.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/VERSION +1 -1
  3. data/vendor/lib/nodes/unit.js +1 -1
  4. data/vendor/lib/parser.js +0 -1
  5. data/vendor/lib/renderer.js +2 -0
  6. data/vendor/lib/visitor/compiler.js +6 -0
  7. data/vendor/node_modules/cssom/README.mdown +34 -0
  8. data/vendor/node_modules/cssom/package.json +2 -1
  9. data/vendor/node_modules/debug/History.md +15 -0
  10. data/vendor/node_modules/debug/Readme.md +3 -18
  11. data/vendor/node_modules/debug/component.json +9 -0
  12. data/vendor/node_modules/debug/debug.js +10 -2
  13. data/vendor/node_modules/debug/index.js +5 -2
  14. data/vendor/node_modules/debug/lib/debug.js +5 -6
  15. data/vendor/node_modules/debug/package.json +11 -6
  16. data/vendor/node_modules/mkdirp/package.json +6 -9
  17. data/vendor/node_modules/mkdirp/{README.markdown → readme.markdown} +26 -24
  18. data/vendor/node_modules/mocha/History.md +140 -58
  19. data/vendor/node_modules/mocha/LICENSE +2 -2
  20. data/vendor/node_modules/mocha/Makefile +20 -5
  21. data/vendor/node_modules/mocha/Readme.md +110 -22
  22. data/vendor/node_modules/mocha/_mocha.js +574 -182
  23. data/vendor/node_modules/mocha/bin/_mocha +39 -22
  24. data/vendor/node_modules/mocha/bin/mocha +6 -2
  25. data/vendor/node_modules/mocha/component.json +16 -0
  26. data/vendor/node_modules/mocha/lib/browser/debug.js +1 -2
  27. data/vendor/node_modules/mocha/lib/browser/diff.js +287 -0
  28. data/vendor/node_modules/mocha/lib/browser/tty.js +7 -2
  29. data/vendor/node_modules/mocha/lib/hook.js +0 -1
  30. data/vendor/node_modules/mocha/lib/interfaces/bdd.js +3 -3
  31. data/vendor/node_modules/mocha/lib/interfaces/exports.js +5 -5
  32. data/vendor/node_modules/mocha/lib/interfaces/qunit.js +38 -9
  33. data/vendor/node_modules/mocha/lib/interfaces/tdd.js +15 -2
  34. data/vendor/node_modules/mocha/lib/mocha.js +20 -4
  35. data/vendor/node_modules/mocha/lib/reporters/base.js +57 -37
  36. data/vendor/node_modules/mocha/lib/reporters/html.js +2 -4
  37. data/vendor/node_modules/mocha/lib/reporters/json-stream.js +4 -14
  38. data/vendor/node_modules/mocha/lib/reporters/json.js +9 -19
  39. data/vendor/node_modules/mocha/lib/reporters/markdown.js +0 -1
  40. data/vendor/node_modules/mocha/lib/reporters/min.js +2 -2
  41. data/vendor/node_modules/mocha/lib/reporters/nyan.js +33 -39
  42. data/vendor/node_modules/mocha/lib/reporters/tap.js +12 -2
  43. data/vendor/node_modules/mocha/lib/reporters/templates/coverage.jade +3 -3
  44. data/vendor/node_modules/mocha/lib/reporters/templates/menu.jade +1 -1
  45. data/vendor/node_modules/mocha/lib/reporters/xunit.js +4 -4
  46. data/vendor/node_modules/mocha/lib/runnable.js +7 -9
  47. data/vendor/node_modules/mocha/lib/runner.js +24 -9
  48. data/vendor/node_modules/mocha/lib/template.html +2 -1
  49. data/vendor/node_modules/mocha/lib/utils.js +3 -3
  50. data/vendor/node_modules/mocha/mocha.css +37 -13
  51. data/vendor/node_modules/mocha/mocha.js +661 -253
  52. data/vendor/node_modules/mocha/node_modules/commander/package.json +5 -1
  53. data/vendor/node_modules/mocha/node_modules/diff/package.json +5 -1
  54. data/vendor/node_modules/mocha/node_modules/glob/LICENSE +27 -0
  55. data/vendor/node_modules/mocha/node_modules/glob/README.md +250 -0
  56. data/vendor/node_modules/mocha/node_modules/glob/examples/g.js +9 -0
  57. data/vendor/node_modules/mocha/node_modules/glob/examples/usr-local.js +9 -0
  58. data/vendor/node_modules/mocha/node_modules/glob/glob.js +675 -0
  59. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/LICENSE +27 -0
  60. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/README.md +33 -0
  61. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/graceful-fs.js +442 -0
  62. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/package.json +49 -0
  63. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/test/open.js +46 -0
  64. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/test/ulimit.js +158 -0
  65. data/vendor/node_modules/mocha/node_modules/glob/node_modules/inherits/README.md +51 -0
  66. data/vendor/node_modules/mocha/node_modules/glob/node_modules/inherits/inherits.js +29 -0
  67. data/vendor/node_modules/mocha/node_modules/glob/node_modules/inherits/package.json +26 -0
  68. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/LICENSE +23 -0
  69. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/README.md +218 -0
  70. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/minimatch.js +1079 -0
  71. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/AUTHORS +8 -0
  72. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
  73. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
  74. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +257 -0
  75. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/package.json +59 -0
  76. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/s.js +25 -0
  77. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/test/basic.js +329 -0
  78. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
  79. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
  80. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
  81. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
  82. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
  83. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/package.json +38 -0
  84. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
  85. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
  86. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/package.json +36 -0
  87. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/basic.js +399 -0
  88. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/brace-expand.js +33 -0
  89. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/caching.js +14 -0
  90. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/defaults.js +274 -0
  91. data/vendor/node_modules/mocha/node_modules/glob/package.json +40 -0
  92. data/vendor/node_modules/mocha/node_modules/glob/test/00-setup.js +176 -0
  93. data/vendor/node_modules/mocha/node_modules/glob/test/bash-comparison.js +63 -0
  94. data/vendor/node_modules/mocha/node_modules/glob/test/bash-results.json +350 -0
  95. data/vendor/node_modules/mocha/node_modules/glob/test/cwd-test.js +55 -0
  96. data/vendor/node_modules/mocha/node_modules/glob/test/globstar-match.js +19 -0
  97. data/vendor/node_modules/mocha/node_modules/glob/test/mark.js +74 -0
  98. data/vendor/node_modules/mocha/node_modules/glob/test/nocase-nomagic.js +113 -0
  99. data/vendor/node_modules/mocha/node_modules/glob/test/pause-resume.js +73 -0
  100. data/vendor/node_modules/mocha/node_modules/glob/test/root-nomount.js +39 -0
  101. data/vendor/node_modules/mocha/node_modules/glob/test/root.js +46 -0
  102. data/vendor/node_modules/mocha/node_modules/glob/test/stat.js +32 -0
  103. data/vendor/node_modules/mocha/node_modules/glob/test/zz-cleanup.js +11 -0
  104. data/vendor/node_modules/mocha/node_modules/growl/History.md +5 -0
  105. data/vendor/node_modules/mocha/node_modules/growl/lib/growl.js +2 -0
  106. data/vendor/node_modules/mocha/node_modules/growl/package.json +7 -3
  107. data/vendor/node_modules/mocha/node_modules/jade/node_modules/mkdirp/package.json +5 -1
  108. data/vendor/node_modules/mocha/node_modules/jade/package.json +5 -1
  109. data/vendor/node_modules/mocha/node_modules/ms/package.json +5 -1
  110. data/vendor/node_modules/mocha/package.json +13 -7
  111. data/vendor/node_modules/mocha/test.js +10 -21
  112. data/vendor/node_modules/should/History.md +5 -0
  113. data/vendor/node_modules/should/Readme.md +172 -172
  114. data/vendor/node_modules/should/lib/eql.js +2 -0
  115. data/vendor/node_modules/should/lib/should.js +4 -3
  116. data/vendor/node_modules/should/package.json +8 -4
  117. data/vendor/node_modules/should/test/should.test.js +27 -0
  118. data/vendor/package.json +1 -1
  119. metadata +61 -35
  120. data/vendor/node_modules/debug/Makefile +0 -4
  121. data/vendor/node_modules/debug/debug.component.js +0 -120
  122. data/vendor/node_modules/debug/head.js +0 -1
  123. data/vendor/node_modules/debug/tail.js +0 -4
  124. data/vendor/node_modules/mocha/node_modules/mkdirp/LICENSE +0 -21
  125. data/vendor/node_modules/mocha/node_modules/mkdirp/README.markdown +0 -61
  126. data/vendor/node_modules/mocha/node_modules/mkdirp/examples/pow.js +0 -6
  127. data/vendor/node_modules/mocha/node_modules/mkdirp/examples/pow.js.orig +0 -6
  128. data/vendor/node_modules/mocha/node_modules/mkdirp/examples/pow.js.rej +0 -19
  129. data/vendor/node_modules/mocha/node_modules/mkdirp/index.js +0 -94
  130. data/vendor/node_modules/mocha/node_modules/mkdirp/package.json +0 -33
  131. data/vendor/node_modules/mocha/node_modules/mkdirp/test/chmod.js +0 -38
  132. data/vendor/node_modules/mocha/node_modules/mkdirp/test/clobber.js +0 -37
  133. data/vendor/node_modules/mocha/node_modules/mkdirp/test/mkdirp.js +0 -28
  134. data/vendor/node_modules/mocha/node_modules/mkdirp/test/perm.js +0 -32
  135. data/vendor/node_modules/mocha/node_modules/mkdirp/test/perm_sync.js +0 -39
  136. data/vendor/node_modules/mocha/node_modules/mkdirp/test/race.js +0 -41
  137. data/vendor/node_modules/mocha/node_modules/mkdirp/test/rel.js +0 -32
  138. data/vendor/node_modules/mocha/node_modules/mkdirp/test/return.js +0 -25
  139. data/vendor/node_modules/mocha/node_modules/mkdirp/test/return_sync.js +0 -24
  140. data/vendor/node_modules/mocha/node_modules/mkdirp/test/root.js +0 -18
  141. data/vendor/node_modules/mocha/node_modules/mkdirp/test/sync.js +0 -32
  142. data/vendor/node_modules/mocha/node_modules/mkdirp/test/umask.js +0 -28
  143. data/vendor/node_modules/mocha/node_modules/mkdirp/test/umask_sync.js +0 -32
@@ -0,0 +1,329 @@
1
+ var test = require("tap").test
2
+ , 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
+ for (var i = 0; i < 100; i ++) cache.set(i, i)
51
+ t.equal(cache.length, 100)
52
+ for (var i = 0; i < 100; i ++) {
53
+ t.equal(cache.get(i), i)
54
+ }
55
+ cache.max = 3
56
+ t.equal(cache.length, 3)
57
+ for (var i = 0; i < 97; i ++) {
58
+ t.equal(cache.get(i), undefined)
59
+ }
60
+ for (var i = 98; i < 100; i ++) {
61
+ t.equal(cache.get(i), i)
62
+ }
63
+
64
+ // now remove the max restriction, and try again.
65
+ cache.max = "hello"
66
+ for (var i = 0; i < 100; i ++) cache.set(i, i)
67
+ t.equal(cache.length, 100)
68
+ for (var i = 0; i < 100; i ++) {
69
+ t.equal(cache.get(i), i)
70
+ }
71
+ // should trigger an immediate resize
72
+ cache.max = 3
73
+ t.equal(cache.length, 3)
74
+ for (var i = 0; i < 97; i ++) {
75
+ t.equal(cache.get(i), undefined)
76
+ }
77
+ for (var i = 98; i < 100; i ++) {
78
+ t.equal(cache.get(i), i)
79
+ }
80
+ t.end()
81
+ })
82
+
83
+ test("reset", function (t) {
84
+ var cache = new LRU(10)
85
+ cache.set("a", "A")
86
+ cache.set("b", "B")
87
+ cache.reset()
88
+ t.equal(cache.length, 0)
89
+ t.equal(cache.max, 10)
90
+ t.equal(cache.get("a"), undefined)
91
+ t.equal(cache.get("b"), undefined)
92
+ t.end()
93
+ })
94
+
95
+
96
+ // Note: `<cache>.dump()` is a debugging tool only. No guarantees are made
97
+ // about the format/layout of the response.
98
+ test("dump", function (t) {
99
+ var cache = new LRU(10)
100
+ var d = cache.dump();
101
+ t.equal(Object.keys(d).length, 0, "nothing in dump for empty cache")
102
+ cache.set("a", "A")
103
+ var d = cache.dump() // { a: { key: "a", value: "A", lu: 0 } }
104
+ t.ok(d.a)
105
+ t.equal(d.a.key, "a")
106
+ t.equal(d.a.value, "A")
107
+ t.equal(d.a.lu, 0)
108
+
109
+ cache.set("b", "B")
110
+ cache.get("b")
111
+ d = cache.dump()
112
+ t.ok(d.b)
113
+ t.equal(d.b.key, "b")
114
+ t.equal(d.b.value, "B")
115
+ t.equal(d.b.lu, 2)
116
+
117
+ t.end()
118
+ })
119
+
120
+
121
+ test("basic with weighed length", function (t) {
122
+ var cache = new LRU({
123
+ max: 100,
124
+ length: function (item) { return item.size }
125
+ })
126
+ cache.set("key", {val: "value", size: 50})
127
+ t.equal(cache.get("key").val, "value")
128
+ t.equal(cache.get("nada"), undefined)
129
+ t.equal(cache.lengthCalculator(cache.get("key")), 50)
130
+ t.equal(cache.length, 50)
131
+ t.equal(cache.max, 100)
132
+ t.end()
133
+ })
134
+
135
+
136
+ test("weighed length item too large", function (t) {
137
+ var cache = new LRU({
138
+ max: 10,
139
+ length: function (item) { return item.size }
140
+ })
141
+ t.equal(cache.max, 10)
142
+
143
+ // should fall out immediately
144
+ cache.set("key", {val: "value", size: 50})
145
+
146
+ t.equal(cache.length, 0)
147
+ t.equal(cache.get("key"), undefined)
148
+ t.end()
149
+ })
150
+
151
+ test("least recently set with weighed length", function (t) {
152
+ var cache = new LRU({
153
+ max:8,
154
+ length: function (item) { return item.length }
155
+ })
156
+ cache.set("a", "A")
157
+ cache.set("b", "BB")
158
+ cache.set("c", "CCC")
159
+ cache.set("d", "DDDD")
160
+ t.equal(cache.get("d"), "DDDD")
161
+ t.equal(cache.get("c"), "CCC")
162
+ t.equal(cache.get("b"), undefined)
163
+ t.equal(cache.get("a"), undefined)
164
+ t.end()
165
+ })
166
+
167
+ test("lru recently gotten with weighed length", function (t) {
168
+ var cache = new LRU({
169
+ max: 8,
170
+ length: function (item) { return item.length }
171
+ })
172
+ cache.set("a", "A")
173
+ cache.set("b", "BB")
174
+ cache.set("c", "CCC")
175
+ cache.get("a")
176
+ cache.get("b")
177
+ cache.set("d", "DDDD")
178
+ t.equal(cache.get("c"), undefined)
179
+ t.equal(cache.get("d"), "DDDD")
180
+ t.equal(cache.get("b"), "BB")
181
+ t.equal(cache.get("a"), "A")
182
+ t.end()
183
+ })
184
+
185
+ test("set returns proper booleans", function(t) {
186
+ var cache = new LRU({
187
+ max: 5,
188
+ length: function (item) { return item.length }
189
+ })
190
+
191
+ t.equal(cache.set("a", "A"), true)
192
+
193
+ // should return false for max exceeded
194
+ t.equal(cache.set("b", "donuts"), false)
195
+
196
+ t.equal(cache.set("b", "B"), true)
197
+ t.equal(cache.set("c", "CCCC"), true)
198
+ t.end()
199
+ })
200
+
201
+ test("drop the old items", function(t) {
202
+ var cache = new LRU({
203
+ max: 5,
204
+ maxAge: 50
205
+ })
206
+
207
+ cache.set("a", "A")
208
+
209
+ setTimeout(function () {
210
+ cache.set("b", "b")
211
+ t.equal(cache.get("a"), "A")
212
+ }, 25)
213
+
214
+ setTimeout(function () {
215
+ cache.set("c", "C")
216
+ // timed out
217
+ t.notOk(cache.get("a"))
218
+ }, 60)
219
+
220
+ setTimeout(function () {
221
+ t.notOk(cache.get("b"))
222
+ t.equal(cache.get("c"), "C")
223
+ }, 90)
224
+
225
+ setTimeout(function () {
226
+ t.notOk(cache.get("c"))
227
+ t.end()
228
+ }, 155)
229
+ })
230
+
231
+ test("disposal function", function(t) {
232
+ var disposed = false
233
+ var cache = new LRU({
234
+ max: 1,
235
+ dispose: function (k, n) {
236
+ disposed = n
237
+ }
238
+ })
239
+
240
+ cache.set(1, 1)
241
+ cache.set(2, 2)
242
+ t.equal(disposed, 1)
243
+ cache.set(3, 3)
244
+ t.equal(disposed, 2)
245
+ cache.reset()
246
+ t.equal(disposed, 3)
247
+ t.end()
248
+ })
249
+
250
+ test("disposal function on too big of item", function(t) {
251
+ var disposed = false
252
+ var cache = new LRU({
253
+ max: 1,
254
+ length: function (k) {
255
+ return k.length
256
+ },
257
+ dispose: function (k, n) {
258
+ disposed = n
259
+ }
260
+ })
261
+ var obj = [ 1, 2 ]
262
+
263
+ t.equal(disposed, false)
264
+ cache.set("obj", obj)
265
+ t.equal(disposed, obj)
266
+ t.end()
267
+ })
268
+
269
+ test("has()", function(t) {
270
+ var cache = new LRU({
271
+ max: 1,
272
+ maxAge: 10
273
+ })
274
+
275
+ cache.set('foo', 'bar')
276
+ t.equal(cache.has('foo'), true)
277
+ cache.set('blu', 'baz')
278
+ t.equal(cache.has('foo'), false)
279
+ t.equal(cache.has('blu'), true)
280
+ setTimeout(function() {
281
+ t.equal(cache.has('blu'), false)
282
+ t.end()
283
+ }, 15)
284
+ })
285
+
286
+ test("stale", function(t) {
287
+ var cache = new LRU({
288
+ maxAge: 10,
289
+ stale: true
290
+ })
291
+
292
+ cache.set('foo', 'bar')
293
+ t.equal(cache.get('foo'), 'bar')
294
+ t.equal(cache.has('foo'), true)
295
+ setTimeout(function() {
296
+ t.equal(cache.has('foo'), false)
297
+ t.equal(cache.get('foo'), 'bar')
298
+ t.equal(cache.get('foo'), undefined)
299
+ t.end()
300
+ }, 15)
301
+ })
302
+
303
+ test("lru update via set", function(t) {
304
+ var cache = LRU({ max: 2 });
305
+
306
+ cache.set('foo', 1);
307
+ cache.set('bar', 2);
308
+ cache.del('bar');
309
+ cache.set('baz', 3);
310
+ cache.set('qux', 4);
311
+
312
+ t.equal(cache.get('foo'), undefined)
313
+ t.equal(cache.get('bar'), undefined)
314
+ t.equal(cache.get('baz'), 3)
315
+ t.equal(cache.get('qux'), 4)
316
+ t.end()
317
+ })
318
+
319
+ test("least recently set w/ peek", function (t) {
320
+ var cache = new LRU(2)
321
+ cache.set("a", "A")
322
+ cache.set("b", "B")
323
+ t.equal(cache.peek("a"), "A")
324
+ cache.set("c", "C")
325
+ t.equal(cache.get("c"), "C")
326
+ t.equal(cache.get("b"), "B")
327
+ t.equal(cache.get("a"), undefined)
328
+ t.end()
329
+ })
@@ -0,0 +1,52 @@
1
+ var test = require('tap').test
2
+ var LRU = require('../')
3
+
4
+ test('forEach', function (t) {
5
+ var l = new LRU(5)
6
+ for (var i = 0; i < 10; i ++) {
7
+ l.set(i.toString(), i.toString(2))
8
+ }
9
+
10
+ var i = 9
11
+ l.forEach(function (val, key, cache) {
12
+ t.equal(cache, l)
13
+ t.equal(key, i.toString())
14
+ t.equal(val, i.toString(2))
15
+ i -= 1
16
+ })
17
+
18
+ // get in order of most recently used
19
+ l.get(6)
20
+ l.get(8)
21
+
22
+ var order = [ 8, 6, 9, 7, 5 ]
23
+ var i = 0
24
+
25
+ l.forEach(function (val, key, cache) {
26
+ var j = order[i ++]
27
+ t.equal(cache, l)
28
+ t.equal(key, j.toString())
29
+ t.equal(val, j.toString(2))
30
+ })
31
+
32
+ t.end()
33
+ })
34
+
35
+ test('keys() and values()', function (t) {
36
+ var l = new LRU(5)
37
+ for (var i = 0; i < 10; i ++) {
38
+ l.set(i.toString(), i.toString(2))
39
+ }
40
+
41
+ t.similar(l.keys(), ['9', '8', '7', '6', '5'])
42
+ t.similar(l.values(), ['1001', '1000', '111', '110', '101'])
43
+
44
+ // get in order of most recently used
45
+ l.get(6)
46
+ l.get(8)
47
+
48
+ t.similar(l.keys(), ['8', '6', '9', '7', '5'])
49
+ t.similar(l.values(), ['1000', '110', '1001', '111', '101'])
50
+
51
+ t.end()
52
+ })
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node --expose_gc
2
+
3
+ var weak = require('weak');
4
+ var test = require('tap').test
5
+ var LRU = require('../')
6
+ var l = new LRU({ max: 10 })
7
+ var refs = 0
8
+ function X() {
9
+ refs ++
10
+ weak(this, deref)
11
+ }
12
+
13
+ function deref() {
14
+ refs --
15
+ }
16
+
17
+ test('no leaks', function (t) {
18
+ // fill up the cache
19
+ for (var i = 0; i < 100; i++) {
20
+ l.set(i, new X);
21
+ // throw some gets in there, too.
22
+ if (i % 2 === 0)
23
+ l.get(i / 2)
24
+ }
25
+
26
+ gc()
27
+
28
+ var start = process.memoryUsage()
29
+
30
+ // capture the memory
31
+ var startRefs = refs
32
+
33
+ // do it again, but more
34
+ for (var i = 0; i < 10000; i++) {
35
+ l.set(i, new X);
36
+ // throw some gets in there, too.
37
+ if (i % 2 === 0)
38
+ l.get(i / 2)
39
+ }
40
+
41
+ gc()
42
+
43
+ var end = process.memoryUsage()
44
+ t.equal(refs, startRefs, 'no leaky refs')
45
+
46
+ console.error('start: %j\n' +
47
+ 'end: %j', start, end);
48
+ t.pass();
49
+ t.end();
50
+ })
@@ -0,0 +1,27 @@
1
+ Copyright (c) Isaac Z. Schlueter ("Author")
2
+ All rights reserved.
3
+
4
+ The BSD License
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+
13
+ 2. Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in the
15
+ documentation and/or other materials provided with the distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
21
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,53 @@
1
+ # sigmund
2
+
3
+ Quick and dirty signatures for Objects.
4
+
5
+ This is like a much faster `deepEquals` comparison, which returns a
6
+ string key suitable for caches and the like.
7
+
8
+ ## Usage
9
+
10
+ ```javascript
11
+ function doSomething (someObj) {
12
+ var key = sigmund(someObj, maxDepth) // max depth defaults to 10
13
+ var cached = cache.get(key)
14
+ if (cached) return cached)
15
+
16
+ var result = expensiveCalculation(someObj)
17
+ cache.set(key, result)
18
+ return result
19
+ }
20
+ ```
21
+
22
+ The resulting key will be as unique and reproducible as calling
23
+ `JSON.stringify` or `util.inspect` on the object, but is much faster.
24
+ In order to achieve this speed, some differences are glossed over.
25
+ For example, the object `{0:'foo'}` will be treated identically to the
26
+ array `['foo']`.
27
+
28
+ Also, just as there is no way to summon the soul from the scribblings
29
+ of a cocain-addled psychoanalyst, there is no way to revive the object
30
+ from the signature string that sigmund gives you. In fact, it's
31
+ barely even readable.
32
+
33
+ As with `sys.inspect` and `JSON.stringify`, larger objects will
34
+ produce larger signature strings.
35
+
36
+ Because sigmund is a bit less strict than the more thorough
37
+ alternatives, the strings will be shorter, and also there is a
38
+ slightly higher chance for collisions. For example, these objects
39
+ have the same signature:
40
+
41
+ var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}
42
+ var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}
43
+
44
+ Like a good Freudian, sigmund is most effective when you already have
45
+ some understanding of what you're looking for. It can help you help
46
+ yourself, but you must be willing to do some work as well.
47
+
48
+ Cycles are handled, and cyclical objects are silently omitted (though
49
+ the key is included in the signature output.)
50
+
51
+ The second argument is the maximum depth, which defaults to 10,
52
+ because that is the maximum object traversal depth covered by most
53
+ insurance carriers.