holmes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/README.md +10 -0
  4. data/Rakefile +1 -0
  5. data/holmes.gemspec +24 -0
  6. data/lib/holmes.rb +38 -0
  7. data/lib/holmes/node_modules/detective/README.markdown +64 -0
  8. data/lib/holmes/node_modules/detective/example/strings.js +6 -0
  9. data/lib/holmes/node_modules/detective/example/strings_src.js +3 -0
  10. data/lib/holmes/node_modules/detective/index.js +65 -0
  11. data/lib/holmes/node_modules/detective/node_modules/burrito/.npmignore +1 -0
  12. data/lib/holmes/node_modules/detective/node_modules/burrito/README.markdown +185 -0
  13. data/lib/holmes/node_modules/detective/node_modules/burrito/browserify.js +4296 -0
  14. data/lib/holmes/node_modules/detective/node_modules/burrito/example/microwave.js +7 -0
  15. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/bs.js +4832 -0
  16. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/index.html +14 -0
  17. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/main.js +17 -0
  18. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/server.js +12 -0
  19. data/lib/holmes/node_modules/detective/node_modules/burrito/example/wrap.js +7 -0
  20. data/lib/holmes/node_modules/detective/node_modules/burrito/index.html +8 -0
  21. data/lib/holmes/node_modules/detective/node_modules/burrito/index.js +208 -0
  22. data/lib/holmes/node_modules/detective/node_modules/burrito/main.js +11 -0
  23. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/.bin/uglifyjs +317 -0
  24. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/.npmignore +1 -0
  25. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/LICENSE +24 -0
  26. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/README.markdown +237 -0
  27. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/json.js +16 -0
  28. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/leaves.js +15 -0
  29. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/negative.js +8 -0
  30. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/scrub.js +10 -0
  31. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/stringify.js +38 -0
  32. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/index.js +267 -0
  33. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/main.js +10 -0
  34. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/package.json +18 -0
  35. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/circular.js +115 -0
  36. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/date.js +35 -0
  37. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/equal.js +220 -0
  38. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/instance.js +17 -0
  39. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/interface.js +42 -0
  40. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/json.js +47 -0
  41. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/keys.js +29 -0
  42. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/leaves.js +21 -0
  43. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/lib/deep_equal.js +92 -0
  44. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/mutability.js +252 -0
  45. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/negative.js +20 -0
  46. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/obj.js +15 -0
  47. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/siblings.js +35 -0
  48. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/stop.js +41 -0
  49. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/stringify.js +36 -0
  50. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/subexpr.js +34 -0
  51. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/super_deep.js +55 -0
  52. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/.npmignore +4 -0
  53. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/README.html +888 -0
  54. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/README.org +463 -0
  55. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/bin/uglifyjs +317 -0
  56. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/docstyle.css +75 -0
  57. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/object-ast.js +75 -0
  58. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/parse-js.js +1341 -0
  59. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/process.js +1949 -0
  60. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/squeeze-more.js +51 -0
  61. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/package.json +22 -0
  62. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/beautify.js +28 -0
  63. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/testparser.js +402 -0
  64. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array1.js +1 -0
  65. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array2.js +1 -0
  66. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array3.js +1 -0
  67. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array4.js +1 -0
  68. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/assignment.js +1 -0
  69. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/concatstring.js +1 -0
  70. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/const.js +1 -0
  71. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js +1 -0
  72. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/forstatement.js +1 -0
  73. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/if.js +1 -0
  74. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js +1 -0
  75. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/ifreturn2.js +1 -0
  76. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue10.js +1 -0
  77. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue11.js +1 -0
  78. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue13.js +1 -0
  79. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue14.js +1 -0
  80. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue16.js +1 -0
  81. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue17.js +1 -0
  82. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue20.js +1 -0
  83. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue21.js +1 -0
  84. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue25.js +1 -0
  85. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue27.js +1 -0
  86. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue28.js +1 -0
  87. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue29.js +1 -0
  88. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue30.js +1 -0
  89. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue34.js +1 -0
  90. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue4.js +1 -0
  91. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue48.js +1 -0
  92. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue50.js +1 -0
  93. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue53.js +1 -0
  94. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js +1 -0
  95. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue68.js +1 -0
  96. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue69.js +1 -0
  97. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue9.js +1 -0
  98. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/mangle.js +1 -0
  99. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js +1 -0
  100. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/var.js +1 -0
  101. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/with.js +1 -0
  102. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array1.js +3 -0
  103. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array2.js +4 -0
  104. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array3.js +4 -0
  105. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array4.js +6 -0
  106. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/assignment.js +20 -0
  107. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/concatstring.js +3 -0
  108. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/const.js +5 -0
  109. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js +4 -0
  110. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/forstatement.js +10 -0
  111. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/if.js +6 -0
  112. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/ifreturn.js +9 -0
  113. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/ifreturn2.js +16 -0
  114. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue10.js +1 -0
  115. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue11.js +3 -0
  116. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue13.js +1 -0
  117. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue14.js +1 -0
  118. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue16.js +1 -0
  119. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue17.js +4 -0
  120. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue20.js +1 -0
  121. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue21.js +6 -0
  122. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue25.js +7 -0
  123. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue27.js +1 -0
  124. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue28.js +3 -0
  125. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue29.js +1 -0
  126. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue30.js +3 -0
  127. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue34.js +3 -0
  128. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue4.js +3 -0
  129. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue48.js +1 -0
  130. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue50.js +9 -0
  131. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue53.js +1 -0
  132. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue54.1.js +3 -0
  133. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue68.js +5 -0
  134. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue69.js +1 -0
  135. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue9.js +4 -0
  136. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/mangle.js +5 -0
  137. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/strict-equals.js +3 -0
  138. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/var.js +3 -0
  139. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/with.js +2 -0
  140. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/scripts.js +55 -0
  141. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/hoist.js +33 -0
  142. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/instrument.js +97 -0
  143. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/instrument2.js +138 -0
  144. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/test.js +16 -0
  145. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/uglify-js.js +17 -0
  146. data/lib/holmes/node_modules/detective/node_modules/burrito/package.json +43 -0
  147. data/lib/holmes/node_modules/detective/node_modules/burrito/server.js +4 -0
  148. data/lib/holmes/node_modules/detective/node_modules/burrito/test/ast.js +29 -0
  149. data/lib/holmes/node_modules/detective/node_modules/burrito/test/err.js +47 -0
  150. data/lib/holmes/node_modules/detective/node_modules/burrito/test/fail.js +8 -0
  151. data/lib/holmes/node_modules/detective/node_modules/burrito/test/fail/src.js +60 -0
  152. data/lib/holmes/node_modules/detective/node_modules/burrito/test/label.js +110 -0
  153. data/lib/holmes/node_modules/detective/node_modules/burrito/test/microwave.js +33 -0
  154. data/lib/holmes/node_modules/detective/node_modules/burrito/test/parent.js +26 -0
  155. data/lib/holmes/node_modules/detective/node_modules/burrito/test/wrap.js +157 -0
  156. data/lib/holmes/node_modules/detective/package.json +39 -0
  157. data/lib/holmes/node_modules/detective/test/both.js +10 -0
  158. data/lib/holmes/node_modules/detective/test/files/both.js +4 -0
  159. data/lib/holmes/node_modules/detective/test/files/nested.js +22 -0
  160. data/lib/holmes/node_modules/detective/test/files/strings.js +13 -0
  161. data/lib/holmes/node_modules/detective/test/files/word.js +13 -0
  162. data/lib/holmes/node_modules/detective/test/nested.js +8 -0
  163. data/lib/holmes/node_modules/detective/test/strings.js +8 -0
  164. data/lib/holmes/node_modules/detective/test/word.js +11 -0
  165. data/lib/holmes/require.js +5 -0
  166. data/lib/holmes/runner.js +20 -0
  167. data/lib/holmes/version.rb +3 -0
  168. metadata +223 -0
@@ -0,0 +1,10 @@
1
+ // scrub out circular references
2
+ var traverse = require('./index.js');
3
+
4
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
5
+ obj.c.push(obj);
6
+
7
+ var scrubbed = traverse(obj).map(function (x) {
8
+ if (this.circular) this.remove()
9
+ });
10
+ console.dir(scrubbed);
@@ -0,0 +1,18 @@
1
+ {
2
+ "name" : "traverse",
3
+ "version" : "0.5.2",
4
+ "description" : "Traverse and transform objects by visiting every node on a recursive walk",
5
+ "author" : "James Halliday",
6
+ "license" : "MIT/X11",
7
+ "main" : "./index",
8
+ "repository" : {
9
+ "type" : "git",
10
+ "url" : "http://github.com/substack/js-traverse.git"
11
+ },
12
+ "devDependencies" : {
13
+ "expresso" : "0.7.x"
14
+ },
15
+ "scripts" : {
16
+ "test" : "expresso"
17
+ }
18
+ }
@@ -0,0 +1,115 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+ var deepEqual = require('./lib/deep_equal');
4
+ var util = require('util');
5
+
6
+ exports.circular = function () {
7
+ var obj = { x : 3 };
8
+ obj.y = obj;
9
+ var foundY = false;
10
+ Traverse(obj).forEach(function (x) {
11
+ if (this.path.join('') == 'y') {
12
+ assert.equal(
13
+ util.inspect(this.circular.node),
14
+ util.inspect(obj)
15
+ );
16
+ foundY = true;
17
+ }
18
+ });
19
+ assert.ok(foundY);
20
+ };
21
+
22
+ exports.deepCirc = function () {
23
+ var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
24
+ obj.y[2] = obj;
25
+
26
+ var times = 0;
27
+ Traverse(obj).forEach(function (x) {
28
+ if (this.circular) {
29
+ assert.deepEqual(this.circular.path, []);
30
+ assert.deepEqual(this.path, [ 'y', 2 ]);
31
+ times ++;
32
+ }
33
+ });
34
+
35
+ assert.deepEqual(times, 1);
36
+ };
37
+
38
+ exports.doubleCirc = function () {
39
+ var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
40
+ obj.y[2] = obj;
41
+ obj.x.push(obj.y);
42
+
43
+ var circs = [];
44
+ Traverse(obj).forEach(function (x) {
45
+ if (this.circular) {
46
+ circs.push({ circ : this.circular, self : this, node : x });
47
+ }
48
+ });
49
+
50
+ assert.deepEqual(circs[0].self.path, [ 'x', 3, 2 ]);
51
+ assert.deepEqual(circs[0].circ.path, []);
52
+
53
+ assert.deepEqual(circs[1].self.path, [ 'y', 2 ]);
54
+ assert.deepEqual(circs[1].circ.path, []);
55
+
56
+ assert.deepEqual(circs.length, 2);
57
+ };
58
+
59
+ exports.circDubForEach = function () {
60
+ var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
61
+ obj.y[2] = obj;
62
+ obj.x.push(obj.y);
63
+
64
+ Traverse(obj).forEach(function (x) {
65
+ if (this.circular) this.update('...');
66
+ });
67
+
68
+ assert.deepEqual(obj, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
69
+ };
70
+
71
+ exports.circDubMap = function () {
72
+ var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
73
+ obj.y[2] = obj;
74
+ obj.x.push(obj.y);
75
+
76
+ var c = Traverse(obj).map(function (x) {
77
+ if (this.circular) {
78
+ this.update('...');
79
+ }
80
+ });
81
+
82
+ assert.deepEqual(c, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
83
+ };
84
+
85
+ exports.circClone = function () {
86
+ var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
87
+ obj.y[2] = obj;
88
+ obj.x.push(obj.y);
89
+
90
+ var clone = Traverse.clone(obj);
91
+ assert.ok(obj !== clone);
92
+
93
+ assert.ok(clone.y[2] === clone);
94
+ assert.ok(clone.y[2] !== obj);
95
+ assert.ok(clone.x[3][2] === clone);
96
+ assert.ok(clone.x[3][2] !== obj);
97
+ assert.deepEqual(clone.x.slice(0,3), [1,2,3]);
98
+ assert.deepEqual(clone.y.slice(0,2), [4,5]);
99
+ };
100
+
101
+ exports.circMapScrub = function () {
102
+ var obj = { a : 1, b : 2 };
103
+ obj.c = obj;
104
+
105
+ var scrubbed = Traverse(obj).map(function (node) {
106
+ if (this.circular) this.remove();
107
+ });
108
+ assert.deepEqual(
109
+ Object.keys(scrubbed).sort(),
110
+ [ 'a', 'b' ]
111
+ );
112
+ assert.ok(deepEqual(scrubbed, { a : 1, b : 2 }));
113
+
114
+ assert.equal(obj.c, obj);
115
+ };
@@ -0,0 +1,35 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+
4
+ exports.dateEach = function () {
5
+ var obj = { x : new Date, y : 10, z : 5 };
6
+
7
+ var counts = {};
8
+
9
+ Traverse(obj).forEach(function (node) {
10
+ var t = (node instanceof Date && 'Date') || typeof node;
11
+ counts[t] = (counts[t] || 0) + 1;
12
+ });
13
+
14
+ assert.deepEqual(counts, {
15
+ object : 1,
16
+ Date : 1,
17
+ number : 2,
18
+ });
19
+ };
20
+
21
+ exports.dateMap = function () {
22
+ var obj = { x : new Date, y : 10, z : 5 };
23
+
24
+ var res = Traverse(obj).map(function (node) {
25
+ if (typeof node === 'number') this.update(node + 100);
26
+ });
27
+
28
+ assert.ok(obj.x !== res.x);
29
+ assert.deepEqual(res, {
30
+ x : obj.x,
31
+ y : 110,
32
+ z : 105,
33
+ });
34
+ };
35
+
@@ -0,0 +1,220 @@
1
+ var assert = require('assert');
2
+ var traverse = require('../');
3
+ var deepEqual = require('./lib/deep_equal');
4
+
5
+ exports.deepDates = function () {
6
+ assert.ok(
7
+ deepEqual(
8
+ { d : new Date, x : [ 1, 2, 3 ] },
9
+ { d : new Date, x : [ 1, 2, 3 ] }
10
+ ),
11
+ 'dates should be equal'
12
+ );
13
+
14
+ var d0 = new Date;
15
+ setTimeout(function () {
16
+ assert.ok(
17
+ !deepEqual(
18
+ { d : d0, x : [ 1, 2, 3 ], },
19
+ { d : new Date, x : [ 1, 2, 3 ] }
20
+ ),
21
+ 'microseconds should count in date equality'
22
+ );
23
+ }, 5);
24
+ };
25
+
26
+ exports.deepCircular = function () {
27
+ var a = [1];
28
+ a.push(a); // a = [ 1, *a ]
29
+
30
+ var b = [1];
31
+ b.push(a); // b = [ 1, [ 1, *a ] ]
32
+
33
+ assert.ok(
34
+ !deepEqual(a, b),
35
+ 'circular ref mount points count towards equality'
36
+ );
37
+
38
+ var c = [1];
39
+ c.push(c); // c = [ 1, *c ]
40
+ assert.ok(
41
+ deepEqual(a, c),
42
+ 'circular refs are structurally the same here'
43
+ );
44
+
45
+ var d = [1];
46
+ d.push(a); // c = [ 1, [ 1, *d ] ]
47
+ assert.ok(
48
+ deepEqual(b, d),
49
+ 'non-root circular ref structural comparison'
50
+ );
51
+ };
52
+
53
+ exports.deepInstances = function () {
54
+ assert.ok(
55
+ !deepEqual([ new Boolean(false) ], [ false ]),
56
+ 'boolean instances are not real booleans'
57
+ );
58
+
59
+ assert.ok(
60
+ !deepEqual([ new String('x') ], [ 'x' ]),
61
+ 'string instances are not real strings'
62
+ );
63
+
64
+ assert.ok(
65
+ !deepEqual([ new Number(4) ], [ 4 ]),
66
+ 'number instances are not real numbers'
67
+ );
68
+
69
+ assert.ok(
70
+ deepEqual([ new RegExp('x') ], [ /x/ ]),
71
+ 'regexp instances are real regexps'
72
+ );
73
+
74
+ assert.ok(
75
+ !deepEqual([ new RegExp(/./) ], [ /../ ]),
76
+ 'these regexps aren\'t the same'
77
+ );
78
+
79
+ assert.ok(
80
+ !deepEqual(
81
+ [ function (x) { return x * 2 } ],
82
+ [ function (x) { return x * 2 } ]
83
+ ),
84
+ 'functions with the same .toString() aren\'t necessarily the same'
85
+ );
86
+
87
+ var f = function (x) { return x * 2 };
88
+ assert.ok(
89
+ deepEqual([ f ], [ f ]),
90
+ 'these functions are actually equal'
91
+ );
92
+ };
93
+
94
+ exports.deepEqual = function () {
95
+ assert.ok(
96
+ !deepEqual([ 1, 2, 3 ], { 0 : 1, 1 : 2, 2 : 3 }),
97
+ 'arrays are not objects'
98
+ );
99
+ };
100
+
101
+ exports.falsy = function () {
102
+ assert.ok(
103
+ !deepEqual([ undefined ], [ null ]),
104
+ 'null is not undefined!'
105
+ );
106
+
107
+ assert.ok(
108
+ !deepEqual([ null ], [ undefined ]),
109
+ 'undefined is not null!'
110
+ );
111
+
112
+ assert.ok(
113
+ !deepEqual(
114
+ { a : 1, b : 2, c : [ 3, undefined, 5 ] },
115
+ { a : 1, b : 2, c : [ 3, null, 5 ] }
116
+ ),
117
+ 'undefined is not null, however deeply!'
118
+ );
119
+
120
+ assert.ok(
121
+ !deepEqual(
122
+ { a : 1, b : 2, c : [ 3, undefined, 5 ] },
123
+ { a : 1, b : 2, c : [ 3, null, 5 ] }
124
+ ),
125
+ 'null is not undefined, however deeply!'
126
+ );
127
+
128
+ assert.ok(
129
+ !deepEqual(
130
+ { a : 1, b : 2, c : [ 3, undefined, 5 ] },
131
+ { a : 1, b : 2, c : [ 3, null, 5 ] }
132
+ ),
133
+ 'null is not undefined, however deeply!'
134
+ );
135
+ };
136
+
137
+ exports.deletedArrayEqual = function () {
138
+ var xs = [ 1, 2, 3, 4 ];
139
+ delete xs[2];
140
+
141
+ var ys = Object.create(Array.prototype);
142
+ ys[0] = 1;
143
+ ys[1] = 2;
144
+ ys[3] = 4;
145
+
146
+ assert.ok(
147
+ deepEqual(xs, ys),
148
+ 'arrays with deleted elements are only equal to'
149
+ + ' arrays with similarly deleted elements'
150
+ );
151
+
152
+ assert.ok(
153
+ !deepEqual(xs, [ 1, 2, undefined, 4 ]),
154
+ 'deleted array elements cannot be undefined'
155
+ );
156
+
157
+ assert.ok(
158
+ !deepEqual(xs, [ 1, 2, null, 4 ]),
159
+ 'deleted array elements cannot be null'
160
+ );
161
+ };
162
+
163
+ exports.deletedObjectEqual = function () {
164
+ var obj = { a : 1, b : 2, c : 3 };
165
+ delete obj.c;
166
+
167
+ assert.ok(
168
+ deepEqual(obj, { a : 1, b : 2 }),
169
+ 'deleted object elements should not show up'
170
+ );
171
+
172
+ assert.ok(
173
+ !deepEqual(obj, { a : 1, b : 2, c : undefined }),
174
+ 'deleted object elements are not undefined'
175
+ );
176
+
177
+ assert.ok(
178
+ !deepEqual(obj, { a : 1, b : 2, c : null }),
179
+ 'deleted object elements are not null'
180
+ );
181
+ };
182
+
183
+ exports.emptyKeyEqual = function () {
184
+ assert.ok(!deepEqual(
185
+ { a : 1 }, { a : 1, '' : 55 }
186
+ ));
187
+ };
188
+
189
+ exports.deepArguments = function () {
190
+ assert.ok(
191
+ !deepEqual(
192
+ [ 4, 5, 6 ],
193
+ (function () { return arguments })(4, 5, 6)
194
+ ),
195
+ 'arguments are not arrays'
196
+ );
197
+
198
+ assert.ok(
199
+ deepEqual(
200
+ (function () { return arguments })(4, 5, 6),
201
+ (function () { return arguments })(4, 5, 6)
202
+ ),
203
+ 'arguments should equal'
204
+ );
205
+ };
206
+
207
+ exports.deepUn = function () {
208
+ assert.ok(!deepEqual({ a : 1, b : 2 }, undefined));
209
+ assert.ok(!deepEqual({ a : 1, b : 2 }, {}));
210
+ assert.ok(!deepEqual(undefined, { a : 1, b : 2 }));
211
+ assert.ok(!deepEqual({}, { a : 1, b : 2 }));
212
+ assert.ok(deepEqual(undefined, undefined));
213
+ assert.ok(deepEqual(null, null));
214
+ assert.ok(!deepEqual(undefined, null));
215
+ };
216
+
217
+ exports.deepLevels = function () {
218
+ var xs = [ 1, 2, [ 3, 4, [ 5, 6 ] ] ];
219
+ assert.ok(!deepEqual(xs, []));
220
+ };
@@ -0,0 +1,17 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+ var EventEmitter = require('events').EventEmitter;
4
+
5
+ exports['check instanceof on node elems'] = function () {
6
+
7
+ var counts = { emitter : 0 };
8
+
9
+ Traverse([ new EventEmitter, 3, 4, { ev : new EventEmitter }])
10
+ .forEach(function (node) {
11
+ if (node instanceof EventEmitter) counts.emitter ++;
12
+ })
13
+ ;
14
+
15
+ assert.equal(counts.emitter, 2);
16
+ };
17
+
@@ -0,0 +1,42 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+
4
+ exports['interface map'] = function () {
5
+ var obj = { a : [ 5,6,7 ], b : { c : [8] } };
6
+
7
+ assert.deepEqual(
8
+ Traverse.paths(obj)
9
+ .sort()
10
+ .map(function (path) { return path.join('/') })
11
+ .slice(1)
12
+ .join(' ')
13
+ ,
14
+ 'a a/0 a/1 a/2 b b/c b/c/0'
15
+ );
16
+
17
+ assert.deepEqual(
18
+ Traverse.nodes(obj),
19
+ [
20
+ { a: [ 5, 6, 7 ], b: { c: [ 8 ] } },
21
+ [ 5, 6, 7 ], 5, 6, 7,
22
+ { c: [ 8 ] }, [ 8 ], 8
23
+ ]
24
+ );
25
+
26
+ assert.deepEqual(
27
+ Traverse.map(obj, function (node) {
28
+ if (typeof node == 'number') {
29
+ return node + 1000;
30
+ }
31
+ else if (Array.isArray(node)) {
32
+ return node.join(' ');
33
+ }
34
+ }),
35
+ { a: '5 6 7', b: { c: '8' } }
36
+ );
37
+
38
+ var nodes = 0;
39
+ Traverse.forEach(obj, function (node) { nodes ++ });
40
+ assert.deepEqual(nodes, 8);
41
+ };
42
+