vulcan 0.1.6 → 0.2.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 (181) hide show
  1. data/lib/vulcan/cli.rb +3 -0
  2. data/lib/vulcan/version.rb +1 -1
  3. data/server/lib/spawner.js +9 -4
  4. data/server/node_modules/cradle/lib/cradle.js +0 -1
  5. data/server/node_modules/cradle/package.json +3 -3
  6. data/server/node_modules/cradle/test/cache-test.js +6 -7
  7. data/server/node_modules/cradle/test/cradle-test.js +4 -5
  8. data/server/node_modules/cradle/test/response-test.js +5 -6
  9. data/server/node_modules/express/History.md +40 -0
  10. data/server/node_modules/express/Makefile +3 -9
  11. data/server/node_modules/express/Readme.md +3 -1
  12. data/server/node_modules/express/bin/express +61 -63
  13. data/server/node_modules/express/lib/express.js +1 -1
  14. data/server/node_modules/express/lib/request.js +9 -7
  15. data/server/node_modules/express/lib/view.js +19 -16
  16. data/server/node_modules/express/node_modules/connect/lib/connect.js +1 -1
  17. data/server/node_modules/express/node_modules/connect/lib/http.js +2 -0
  18. data/server/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js +135 -31
  19. data/server/node_modules/express/node_modules/connect/lib/middleware/limit.js +5 -1
  20. data/server/node_modules/express/node_modules/connect/lib/middleware/session.js +2 -2
  21. data/server/node_modules/express/node_modules/connect/lib/middleware/static.js +26 -21
  22. data/server/node_modules/express/node_modules/connect/lib/middleware/staticCache.js +91 -38
  23. data/server/node_modules/express/node_modules/connect/lib/middleware/vhost.js +1 -1
  24. data/server/node_modules/express/node_modules/connect/lib/utils.js +11 -4
  25. data/server/node_modules/express/node_modules/connect/node_modules/formidable/Makefile +14 -0
  26. data/server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md +286 -0
  27. data/server/node_modules/express/node_modules/connect/node_modules/formidable/TODO +3 -0
  28. data/server/node_modules/express/node_modules/connect/node_modules/formidable/benchmark/bench-multipart-parser.js +70 -0
  29. data/server/node_modules/express/node_modules/connect/node_modules/formidable/example/post.js +43 -0
  30. data/server/node_modules/express/node_modules/connect/node_modules/formidable/example/upload.js +48 -0
  31. data/server/node_modules/express/node_modules/connect/node_modules/formidable/index.js +1 -0
  32. data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/file.js +61 -0
  33. data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js +377 -0
  34. data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/index.js +3 -0
  35. data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js +312 -0
  36. data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/querystring_parser.js +25 -0
  37. data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/util.js +6 -0
  38. data/server/node_modules/express/node_modules/connect/node_modules/formidable/package.json +22 -0
  39. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/common.js +19 -0
  40. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/file/funkyfilename.txt +1 -0
  41. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/file/plain.txt +1 -0
  42. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/no-filename/generic.http +13 -0
  43. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/info.md +3 -0
  44. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +26 -0
  45. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +24 -0
  46. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +23 -0
  47. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +24 -0
  48. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +22 -0
  49. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +22 -0
  50. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +22 -0
  51. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/js/no-filename.js +3 -0
  52. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/js/special-chars-in-filename.js +21 -0
  53. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multi_video.upload +0 -0
  54. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multipart.js +72 -0
  55. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/integration/test-fixtures.js +89 -0
  56. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/common.js +24 -0
  57. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/integration/test-multipart-parser.js +80 -0
  58. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-file.js +104 -0
  59. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-incoming-form.js +715 -0
  60. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-multipart-parser.js +50 -0
  61. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-querystring-parser.js +45 -0
  62. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/system/test-multi-video-upload.js +72 -0
  63. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/run.js +2 -0
  64. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/unit/test-incoming-form.js +63 -0
  65. data/server/node_modules/express/node_modules/connect/node_modules/formidable/tool/record.js +47 -0
  66. data/server/node_modules/express/node_modules/connect/package.json +7 -6
  67. data/server/node_modules/express/node_modules/connect/test.js +44 -31
  68. data/server/node_modules/express/node_modules/qs/History.md +11 -0
  69. data/server/node_modules/express/node_modules/qs/Makefile +1 -3
  70. data/server/node_modules/express/node_modules/qs/Readme.md +2 -4
  71. data/server/node_modules/express/node_modules/qs/lib/querystring.js +100 -74
  72. data/server/node_modules/express/node_modules/qs/package.json +9 -2
  73. data/server/node_modules/express/node_modules/qs/test/mocha.opts +2 -0
  74. data/server/node_modules/express/node_modules/qs/test/{parse.test.js → parse.js} +1 -2
  75. data/server/node_modules/express/node_modules/qs/test/{stringify.test.js → stringify.js} +0 -0
  76. data/server/node_modules/express/package.json +7 -7
  77. data/server/node_modules/express/testing/foo/app.js +35 -0
  78. data/server/node_modules/express/testing/foo/package.json +9 -0
  79. data/server/node_modules/express/testing/foo/public/stylesheets/style.css +8 -0
  80. data/server/node_modules/express/testing/foo/routes/index.js +10 -0
  81. data/server/node_modules/express/testing/foo/views/index.jade +2 -0
  82. data/server/node_modules/express/testing/foo/views/layout.jade +6 -0
  83. data/server/node_modules/express/testing/index.js +31 -5
  84. data/server/node_modules/express/testing/public/test.txt +2971 -0
  85. data/server/node_modules/express/testing/views/page.html +1 -0
  86. data/server/node_modules/express/testing/views/page.jade +3 -0
  87. data/server/node_modules/express/testing/views/test.md +1 -0
  88. data/server/node_modules/express/testing/views/user/index.jade +1 -0
  89. data/server/node_modules/express/testing/views/user/list.jade +1 -0
  90. data/server/node_modules/node-uuid/README.md +166 -67
  91. data/server/node_modules/node-uuid/benchmark/README.md +53 -0
  92. data/server/node_modules/node-uuid/benchmark/bench.gnu +174 -0
  93. data/server/node_modules/node-uuid/benchmark/bench.sh +34 -0
  94. data/server/node_modules/node-uuid/{test → benchmark}/benchmark-native.c +0 -0
  95. data/server/node_modules/node-uuid/benchmark/benchmark.js +84 -0
  96. data/server/node_modules/node-uuid/package.json +5 -3
  97. data/server/node_modules/node-uuid/test/benchmark-native +0 -0
  98. data/server/node_modules/node-uuid/test/compare_v1.js +63 -0
  99. data/server/node_modules/node-uuid/test/test.html +3 -0
  100. data/server/node_modules/node-uuid/test/test.js +214 -57
  101. data/server/node_modules/node-uuid/uuid.js +225 -56
  102. data/server/node_modules/restler/README.md +20 -7
  103. data/server/node_modules/restler/bin/restler +1 -1
  104. data/server/node_modules/restler/lib/multipartform.js +9 -8
  105. data/server/node_modules/restler/lib/restler.js +64 -22
  106. data/server/node_modules/restler/package.json +2 -2
  107. data/server/node_modules/restler/test/restler.js +22 -2
  108. data/server/node_modules/restler/test/test_helper.js +20 -1
  109. data/server/package.json +8 -8
  110. data/server/web.js +22 -6
  111. metadata +72 -82
  112. data/server/node_modules/cradle/node_modules/vows/LICENSE +0 -20
  113. data/server/node_modules/cradle/node_modules/vows/Makefile +0 -7
  114. data/server/node_modules/cradle/node_modules/vows/README.md +0 -39
  115. data/server/node_modules/cradle/node_modules/vows/bin/vows +0 -515
  116. data/server/node_modules/cradle/node_modules/vows/lib/assert/error.js +0 -27
  117. data/server/node_modules/cradle/node_modules/vows/lib/assert/macros.js +0 -215
  118. data/server/node_modules/cradle/node_modules/vows/lib/assert/utils.js +0 -77
  119. data/server/node_modules/cradle/node_modules/vows/lib/vows.js +0 -193
  120. data/server/node_modules/cradle/node_modules/vows/lib/vows/console.js +0 -131
  121. data/server/node_modules/cradle/node_modules/vows/lib/vows/context.js +0 -55
  122. data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/file.js +0 -29
  123. data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/fragments/coverage-foot.html +0 -2
  124. data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/fragments/coverage-head.html +0 -61
  125. data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/report-html.js +0 -54
  126. data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/report-json.js +0 -54
  127. data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/report-plain.js +0 -38
  128. data/server/node_modules/cradle/node_modules/vows/lib/vows/extras.js +0 -28
  129. data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/dot-matrix.js +0 -67
  130. data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/json.js +0 -16
  131. data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/silent.js +0 -8
  132. data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/spec.js +0 -44
  133. data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/watch.js +0 -39
  134. data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/xunit.js +0 -90
  135. data/server/node_modules/cradle/node_modules/vows/lib/vows/suite.js +0 -319
  136. data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/LICENSE +0 -20
  137. data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/Makefile +0 -4
  138. data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/README.md +0 -72
  139. data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/lib/eyes.js +0 -233
  140. data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/package.json +0 -14
  141. data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/test/eyes-test.js +0 -55
  142. data/server/node_modules/cradle/node_modules/vows/package.json +0 -14
  143. data/server/node_modules/cradle/node_modules/vows/test/assert-test.js +0 -135
  144. data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/failing.js +0 -18
  145. data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/log.js +0 -18
  146. data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/passing.js +0 -17
  147. data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/stderr.js +0 -18
  148. data/server/node_modules/cradle/node_modules/vows/test/isolate-test.js +0 -140
  149. data/server/node_modules/cradle/node_modules/vows/test/testInherit.js +0 -133
  150. data/server/node_modules/cradle/node_modules/vows/test/vows-error-test.js +0 -51
  151. data/server/node_modules/cradle/node_modules/vows/test/vows-test.js +0 -374
  152. data/server/node_modules/express/node_modules/qs/support/expresso/History.md +0 -128
  153. data/server/node_modules/express/node_modules/qs/support/expresso/Makefile +0 -53
  154. data/server/node_modules/express/node_modules/qs/support/expresso/Readme.md +0 -61
  155. data/server/node_modules/express/node_modules/qs/support/expresso/bin/expresso +0 -856
  156. data/server/node_modules/express/node_modules/qs/support/expresso/docs/api.html +0 -1080
  157. data/server/node_modules/express/node_modules/qs/support/expresso/docs/index.html +0 -377
  158. data/server/node_modules/express/node_modules/qs/support/expresso/docs/index.md +0 -290
  159. data/server/node_modules/express/node_modules/qs/support/expresso/docs/layout/foot.html +0 -3
  160. data/server/node_modules/express/node_modules/qs/support/expresso/docs/layout/head.html +0 -42
  161. data/server/node_modules/express/node_modules/qs/support/expresso/lib/bar.js +0 -4
  162. data/server/node_modules/express/node_modules/qs/support/expresso/lib/foo.js +0 -16
  163. data/server/node_modules/express/node_modules/qs/support/expresso/package.json +0 -12
  164. data/server/node_modules/express/node_modules/qs/support/expresso/test/assert.test.js +0 -91
  165. data/server/node_modules/express/node_modules/qs/support/expresso/test/async.test.js +0 -12
  166. data/server/node_modules/express/node_modules/qs/support/expresso/test/bar.test.js +0 -13
  167. data/server/node_modules/express/node_modules/qs/support/expresso/test/foo.test.js +0 -14
  168. data/server/node_modules/express/node_modules/qs/support/expresso/test/http.test.js +0 -146
  169. data/server/node_modules/express/node_modules/qs/support/expresso/test/serial/async.test.js +0 -39
  170. data/server/node_modules/express/node_modules/qs/support/expresso/test/serial/http.test.js +0 -48
  171. data/server/node_modules/express/node_modules/qs/support/should/History.md +0 -22
  172. data/server/node_modules/express/node_modules/qs/support/should/Makefile +0 -6
  173. data/server/node_modules/express/node_modules/qs/support/should/Readme.md +0 -248
  174. data/server/node_modules/express/node_modules/qs/support/should/examples/runner.js +0 -53
  175. data/server/node_modules/express/node_modules/qs/support/should/index.js +0 -2
  176. data/server/node_modules/express/node_modules/qs/support/should/lib/eql.js +0 -91
  177. data/server/node_modules/express/node_modules/qs/support/should/lib/should.js +0 -548
  178. data/server/node_modules/express/node_modules/qs/support/should/package.json +0 -8
  179. data/server/node_modules/express/node_modules/qs/support/should/test/should.test.js +0 -358
  180. data/server/node_modules/express/testing/views/users.jade +0 -1
  181. data/server/node_modules/node-uuid/test/benchmark.js +0 -27
@@ -0,0 +1,34 @@
1
+ #!/bin/bash
2
+
3
+ # for a given node version run:
4
+ # for i in {0..9}; do node benchmark.js >> bench_0.6.2.log; done;
5
+
6
+ PATTERNS=('nodeuuid.v1()' "nodeuuid.v1('binary'," 'nodeuuid.v4()' "nodeuuid.v4('binary'," "uuid()" "uuid('binary')" 'uuidjs.create(1)' 'uuidjs.create(4)' '140byte')
7
+ FILES=(node_uuid_v1_string node_uuid_v1_buf node_uuid_v4_string node_uuid_v4_buf libuuid_v4_string libuuid_v4_binary uuidjs_v1_string uuidjs_v4_string 140byte_es)
8
+ INDICES=(2 3 2 3 2 2 2 2 2)
9
+ VERSIONS=$( ls bench_*.log | sed -e 's/^bench_\([0-9\.]*\)\.log/\1/' | tr "\\n" " " )
10
+ TMPJOIN="tmp_join"
11
+ OUTPUT="bench_results.txt"
12
+
13
+ for I in ${!FILES[*]}; do
14
+ F=${FILES[$I]}
15
+ P=${PATTERNS[$I]}
16
+ INDEX=${INDICES[$I]}
17
+ echo "version $F" > $F
18
+ for V in $VERSIONS; do
19
+ (VAL=$( grep "$P" bench_$V.log | LC_ALL=en_US awk '{ sum += $'$INDEX' } END { print sum/NR }' ); echo $V $VAL) >> $F
20
+ done
21
+ if [ $I == 0 ]; then
22
+ cat $F > $TMPJOIN
23
+ else
24
+ join $TMPJOIN $F > $OUTPUT
25
+ cp $OUTPUT $TMPJOIN
26
+ fi
27
+ rm $F
28
+ done
29
+
30
+ rm $TMPJOIN
31
+
32
+ gnuplot bench.gnu
33
+ convert -density 200 -resize 800x560 -flatten bench.eps bench.png
34
+ rm bench.eps
@@ -0,0 +1,84 @@
1
+ try {
2
+ var nodeuuid = require('../uuid');
3
+ } catch (e) {
4
+ console.error('node-uuid require failed - skipping tests');
5
+ }
6
+
7
+ try {
8
+ var uuid = require('uuid');
9
+ } catch (e) {
10
+ console.error('uuid require failed - skipping tests');
11
+ }
12
+
13
+ try {
14
+ var uuidjs = require('uuid-js');
15
+ } catch (e) {
16
+ console.error('uuid-js require failed - skipping tests');
17
+ }
18
+
19
+ var N = 5e5;
20
+
21
+ function rate(msg, t) {
22
+ console.log(msg + ': ' +
23
+ (N / (Date.now() - t) * 1e3 | 0) +
24
+ ' uuids/second');
25
+ }
26
+
27
+ console.log('# v4');
28
+
29
+ // node-uuid - string form
30
+ if (nodeuuid) {
31
+ for (var i = 0, t = Date.now(); i < N; i++) nodeuuid.v4();
32
+ rate('nodeuuid.v4() - using node.js crypto RNG', t);
33
+
34
+ for (var i = 0, t = Date.now(); i < N; i++) nodeuuid.v4({rng: nodeuuid.mathRNG});
35
+ rate('nodeuuid.v4() - using Math.random() RNG', t);
36
+
37
+ for (var i = 0, t = Date.now(); i < N; i++) nodeuuid.v4('binary');
38
+ rate('nodeuuid.v4(\'binary\')', t);
39
+
40
+ var buffer = new nodeuuid.BufferClass(16);
41
+ for (var i = 0, t = Date.now(); i < N; i++) nodeuuid.v4('binary', buffer);
42
+ rate('nodeuuid.v4(\'binary\', buffer)', t);
43
+ }
44
+
45
+ // libuuid - string form
46
+ if (uuid) {
47
+ for (var i = 0, t = Date.now(); i < N; i++) uuid();
48
+ rate('uuid()', t);
49
+
50
+ for (var i = 0, t = Date.now(); i < N; i++) uuid('binary');
51
+ rate('uuid(\'binary\')', t);
52
+ }
53
+
54
+ // uuid-js - string form
55
+ if (uuidjs) {
56
+ for (var i = 0, t = Date.now(); i < N; i++) uuidjs.create(4);
57
+ rate('uuidjs.create(4)', t);
58
+ }
59
+
60
+ // 140byte.es
61
+ for (var i = 0, t = Date.now(); i < N; i++) 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(s,r){r=Math.random()*16|0;return (s=='x'?r:r&0x3|0x8).toString(16)});
62
+ rate('140byte.es_v4', t);
63
+
64
+ console.log('');
65
+ console.log('# v1');
66
+
67
+ // node-uuid - v1 string form
68
+ if (nodeuuid) {
69
+ for (var i = 0, t = Date.now(); i < N; i++) nodeuuid.v1();
70
+ rate('nodeuuid.v1()', t);
71
+
72
+ for (var i = 0, t = Date.now(); i < N; i++) nodeuuid.v1('binary');
73
+ rate('nodeuuid.v1(\'binary\')', t);
74
+
75
+ var buffer = new nodeuuid.BufferClass(16);
76
+ for (var i = 0, t = Date.now(); i < N; i++) nodeuuid.v1('binary', buffer);
77
+ rate('nodeuuid.v1(\'binary\', buffer)', t);
78
+ }
79
+
80
+ // uuid-js - v1 string form
81
+ if (uuidjs) {
82
+ for (var i = 0, t = Date.now(); i < N; i++) uuidjs.create(1);
83
+ rate('uuidjs.create(1)', t);
84
+ }
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name" : "node-uuid",
3
- "description" : "Simple, fast generation of RFC4122(v4) UUIDs.",
3
+ "description" : "Rigorous implementation of RFC4122 (v1 and v4) UUIDs.",
4
4
  "url" : "http://github.com/broofa/node-uuid",
5
5
  "keywords" : ["uuid", "guid", "rfc4122"],
6
6
  "author" : "Robert Kieffer <robert@broofa.com>",
7
- "contributors" : [],
7
+ "contributors" : [
8
+ {"name": "Christoph Tavan <dev@tavan.de>", "github": "https://github.com/ctavan"}
9
+ ],
8
10
  "dependencies" : [],
9
11
  "lib" : ".",
10
12
  "main" : "./uuid.js",
11
- "version" : "1.2.0"
13
+ "version" : "1.3.3"
12
14
  }
@@ -0,0 +1,63 @@
1
+ var assert = require('assert'),
2
+ nodeuuid = require('../uuid'),
3
+ uuidjs = require('uuid-js'),
4
+ libuuid = require('uuid').generate,
5
+ util = require('util'),
6
+ exec = require('child_process').exec,
7
+ os = require('os');
8
+
9
+ // On Mac Os X / macports there's only the ossp-uuid package that provides uuid
10
+ // On Linux there's uuid-runtime which provides uuidgen
11
+ var uuidCmd = os.type() === 'Darwin' ? 'uuid -1' : 'uuidgen -t';
12
+
13
+ function compare(ids) {
14
+ console.log(ids);
15
+ for (var i = 0; i < ids.length; i++) {
16
+ var id = ids[i].split('-');
17
+ id = [id[2], id[1], id[0]].join('');
18
+ ids[i] = id;
19
+ }
20
+ var sorted = ([].concat(ids)).sort();
21
+
22
+ if (sorted.toString() !== ids.toString()) {
23
+ console.log('Warning: sorted !== ids');
24
+ } else {
25
+ console.log('everything in order!');
26
+ }
27
+ }
28
+
29
+ // Test time order of v1 uuids
30
+ var ids = [];
31
+ while (ids.length < 10e3) ids.push(nodeuuid.v1());
32
+
33
+ var max = 10;
34
+ console.log('node-uuid:');
35
+ ids = [];
36
+ for (var i = 0; i < max; i++) ids.push(nodeuuid.v1());
37
+ compare(ids);
38
+
39
+ console.log('');
40
+ console.log('uuidjs:');
41
+ ids = [];
42
+ for (var i = 0; i < max; i++) ids.push(uuidjs.create(1).toString());
43
+ compare(ids);
44
+
45
+ console.log('');
46
+ console.log('libuuid:');
47
+ ids = [];
48
+ var count = 0;
49
+ var last = function() {
50
+ compare(ids);
51
+ }
52
+ var cb = function(err, stdout, stderr) {
53
+ ids.push(stdout.substring(0, stdout.length-1));
54
+ count++;
55
+ if (count < max) {
56
+ return next();
57
+ }
58
+ last();
59
+ };
60
+ var next = function() {
61
+ exec(uuidCmd, cb);
62
+ };
63
+ next();
@@ -5,6 +5,9 @@
5
5
  font-family: monospace;
6
6
  font-size: 8pt;
7
7
  }
8
+ div.log {color: #444;}
9
+ div.warn {color: #550;}
10
+ div.error {color: #800; font-weight: bold;}
8
11
  </style>
9
12
  <script src="../uuid.js"></script>
10
13
  </head>
@@ -1,83 +1,240 @@
1
- if (typeof(uuid) == 'undefined') {
1
+ if (!this.uuid) {
2
+ // node.js
2
3
  uuid = require('../uuid');
3
4
  }
4
5
 
5
- var UUID_FORMAT = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89a-fAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}/;
6
- var N = 1e5;
6
+ //
7
+ // x-platform log/assert shims
8
+ //
9
+
10
+ function _log(msg, type) {
11
+ type = type || 'log';
7
12
 
8
- function log(msg) {
9
13
  if (typeof(document) != 'undefined') {
10
- document.write('<div>' + msg + '</div>');
14
+ document.write('<div class="' + type + '">' + msg.replace(/\n/g, '<br />') + '</div>');
11
15
  }
12
16
  if (typeof(console) != 'undefined') {
13
- console.log(msg);
17
+ var color = {
18
+ log: '\033[30m',
19
+ warn: '\033[33m',
20
+ error: '\033[31m'
21
+ }
22
+ console[type](color[type] + msg + color.log);
14
23
  }
15
24
  }
16
25
 
17
- function rate(msg, t) {
18
- log(msg + ': ' + (N / (Date.now() - t) * 1e3 | 0) + ' uuids/second');
19
- }
26
+ function log(msg) {_log(msg, 'log');}
27
+ function warn(msg) {_log(msg, 'warn');}
28
+ function error(msg) {_log(msg, 'error');}
20
29
 
21
- // Perf tests
22
- log('- - - Performance Data - - -');
23
- for (var i = 0, t = Date.now(); i < N; i++) uuid();
24
- rate('uuid()', t);
25
- for (var i = 0, t = Date.now(); i < N; i++) uuid('binary');
26
- rate('uuid(\'binary\')', t);
27
- var buf = new uuid.BufferClass(16);
28
- for (var i = 0, t = Date.now(); i < N; i++) uuid('binary', buf);
29
- rate('uuid(\'binary\', buffer)', t);
30
-
31
- var counts = {}, max = 0;
32
-
33
- var b = new uuid.BufferClass(16);
34
- for (var i = 0; i < N; i++) {
35
- id = uuid();
36
- if (!UUID_FORMAT.test(id)) {
37
- throw Error(id + ' is not a valid UUID string');
30
+ function assert(res, msg) {
31
+ if (!res) {
32
+ error('FAIL: ' + msg);
33
+ } else {
34
+ log('Pass: ' + msg);
38
35
  }
36
+ }
39
37
 
40
- if (id != uuid.unparse(uuid.parse(id))) {
41
- throw Error(id + ' does not parse/unparse');
42
- }
38
+ //
39
+ // Unit tests
40
+ //
43
41
 
44
- // Count digits for our randomness check
45
- var digits = id.replace(/-/g, '').split('');
46
- for (var j = digits.length-1; j >= 0; j--) {
47
- var c = digits[j];
48
- max = Math.max(max, counts[c] = (counts[c] || 0) + 1);
49
- }
42
+ // Verify ordering of v1 ids created with explicit times
43
+ var TIME = 1321644961388; // 2011-11-18 11:36:01.388-08:00
44
+
45
+ function compare(name, ids) {
46
+ ids = ids.map(function(id) {
47
+ return id.split('-').reverse().join('-');
48
+ }).sort();
49
+ var sorted = ([].concat(ids)).sort();
50
+
51
+ assert(sorted.toString() == ids.toString(), name + ' have expected order');
50
52
  }
51
53
 
54
+ // Verify ordering of v1 ids created using default behavior
55
+ compare('uuids with current time', [
56
+ uuid.v1(),
57
+ uuid.v1(),
58
+ uuid.v1(),
59
+ uuid.v1(),
60
+ uuid.v1()
61
+ ]);
62
+
63
+ // Verify ordering of v1 ids created with explicit times
64
+ compare('uuids with time option', [
65
+ uuid.v1({msecs: TIME - 10*3600*1000}),
66
+ uuid.v1({msecs: TIME - 1}),
67
+ uuid.v1({msecs: TIME}),
68
+ uuid.v1({msecs: TIME + 1}),
69
+ uuid.v1({msecs: TIME + 28*24*3600*1000}),
70
+ ]);
71
+
72
+ assert(
73
+ uuid.v1({msecs: TIME}) != uuid.v1({msecs: TIME}),
74
+ 'IDs created at same msec are different'
75
+ );
76
+
77
+ // Verify throw if too many ids created
78
+ var thrown = false;
79
+ try {
80
+ uuid.v1({msecs: TIME, nsecs: 10000});
81
+ } catch (e) {
82
+ thrown = true;
83
+ }
84
+ assert(thrown, 'Exception thrown when > 10K ids created in 1 ms');
85
+
86
+ // Verify clock regression bumps clockseq
87
+ var uidt = uuid.v1({msecs: TIME});
88
+ var uidtb = uuid.v1({msecs: TIME - 1});
89
+ assert(
90
+ parseInt(uidtb.split('-')[3], 16) - parseInt(uidt.split('-')[3], 16) === 1,
91
+ 'Clock regression by msec increments the clockseq'
92
+ );
93
+
94
+ // Verify clock regression bumps clockseq
95
+ var uidtn = uuid.v1({msecs: TIME, nsecs: 10});
96
+ var uidtnb = uuid.v1({msecs: TIME, nsecs: 9});
97
+ assert(
98
+ parseInt(uidtnb.split('-')[3], 16) - parseInt(uidtn.split('-')[3], 16) === 1,
99
+ 'Clock regression by nsec increments the clockseq'
100
+ );
101
+
102
+ // Verify explicit options produce expected id
103
+ var id = uuid.v1({
104
+ msecs: 1321651533573,
105
+ nsecs: 5432,
106
+ clockseq: 0x385c,
107
+ node: [ 0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10 ]
108
+ });
109
+ assert(id == 'd9428888-122b-11e1-b85c-61cd3cbb3210', 'Explicit options produce expected id');
110
+
111
+ // Verify adjacent ids across a msec boundary are 1 time unit apart
112
+ var u0 = uuid.v1({msecs: TIME, nsecs: 9999});
113
+ var u1 = uuid.v1({msecs: TIME + 1, nsecs: 0});
114
+
115
+ var before = u0.split('-')[0], after = u1.split('-')[0];
116
+ var dt = parseInt(after, 16) - parseInt(before, 16);
117
+ assert(dt === 1, 'Ids spanning 1ms boundary are 100ns apart');
118
+
119
+ //
120
+ // Test parse/unparse
121
+ //
122
+
123
+ id = '00112233445566778899aabbccddeeff';
124
+ assert(uuid.unparse(uuid.parse(id.substr(0,10))) ==
125
+ '00112233-4400-0000-0000-000000000000', 'Short parse');
126
+ assert(uuid.unparse(uuid.parse('(this is the uuid -> ' + id + id)) ==
127
+ '00112233-4455-6677-8899-aabbccddeeff', 'Dirty parse');
128
+
129
+ //
130
+ // Perf tests
131
+ //
132
+
133
+ var generators = {
134
+ v1: uuid.v1,
135
+ v4: uuid.v4
136
+ };
137
+
138
+ var UUID_FORMAT = {
139
+ v1: /[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
140
+ v4: /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i
141
+ };
142
+
143
+ var N = 1e4;
144
+
52
145
  // Get %'age an actual value differs from the ideal value
53
146
  function divergence(actual, ideal) {
54
147
  return Math.round(100*100*(actual - ideal)/ideal)/100;
55
148
  }
56
149
 
57
- log('<br />- - - Distribution of Hex Digits (% deviation from ideal) - - -');
58
-
59
- // Check randomness
60
- for (var i = 0; i < 16; i++) {
61
- var c = i.toString(16);
62
- var bar = '', n = counts[c], p = Math.round(n/max*100|0);
63
-
64
- // 1-3,5-8, and D-F: 1:16 odds over 30 digits
65
- var ideal = N*30/16;
66
- if (i == 4) {
67
- // 4: 1:1 odds on 1 digit, plus 1:16 odds on 30 digits
68
- ideal = N*(1 + 30/16);
69
- } else if (i >= 8 && i <= 11) {
70
- // 8-B: 1:4 odds on 1 digit, plus 1:16 odds on 30 digits
71
- ideal = N*(1/4 + 30/16);
150
+ function rate(msg, t) {
151
+ log(msg + ': ' + (N / (Date.now() - t) * 1e3 | 0) + ' uuids\/second');
152
+ }
153
+
154
+ for (var version in generators) {
155
+ var counts = {}, max = 0;
156
+ var generator = generators[version];
157
+ var format = UUID_FORMAT[version];
158
+
159
+ log('\nSanity check ' + N + ' ' + version + ' uuids');
160
+ for (var i = 0, ok = 0; i < N; i++) {
161
+ id = generator();
162
+ if (!format.test(id)) {
163
+ throw Error(id + ' is not a valid UUID string');
164
+ }
165
+
166
+ if (id != uuid.unparse(uuid.parse(id))) {
167
+ assert(fail, id + ' is not a valid id');
168
+ }
169
+
170
+ // Count digits for our randomness check
171
+ if (version == 'v4') {
172
+ var digits = id.replace(/-/g, '').split('');
173
+ for (var j = digits.length-1; j >= 0; j--) {
174
+ var c = digits[j];
175
+ max = Math.max(max, counts[c] = (counts[c] || 0) + 1);
176
+ }
177
+ }
178
+ }
179
+
180
+ // Check randomness for v4 UUIDs
181
+ if (version == 'v4') {
182
+ // Limit that we get worried about randomness. (Purely empirical choice, this!)
183
+ var limit = 2*100*Math.sqrt(1/N);
184
+
185
+ log('\nChecking v4 randomness. Distribution of Hex Digits (% deviation from ideal)');
186
+
187
+ for (var i = 0; i < 16; i++) {
188
+ var c = i.toString(16);
189
+ var bar = '', n = counts[c], p = Math.round(n/max*100|0);
190
+
191
+ // 1-3,5-8, and D-F: 1:16 odds over 30 digits
192
+ var ideal = N*30/16;
193
+ if (i == 4) {
194
+ // 4: 1:1 odds on 1 digit, plus 1:16 odds on 30 digits
195
+ ideal = N*(1 + 30/16);
196
+ } else if (i >= 8 && i <= 11) {
197
+ // 8-B: 1:4 odds on 1 digit, plus 1:16 odds on 30 digits
198
+ ideal = N*(1/4 + 30/16);
199
+ } else {
200
+ // Otherwise: 1:16 odds on 30 digits
201
+ ideal = N*30/16;
202
+ }
203
+ var d = divergence(n, ideal);
204
+
205
+ // Draw bar using UTF squares (just for grins)
206
+ var s = n/max*50 | 0;
207
+ while (s--) bar += '=';
208
+
209
+ assert(Math.abs(d) < limit, c + ' |' + bar + '| ' + counts[c] + ' (' + d + '% < ' + limit + '%)');
210
+ }
211
+ }
212
+ }
213
+
214
+ // Perf tests
215
+ for (var version in generators) {
216
+ log('\nPerformance testing ' + version + ' UUIDs');
217
+ var generator = generators[version];
218
+ var buf = new uuid.BufferClass(16);
219
+
220
+ if (version == 'v4') {
221
+ ['mathRNG', 'whatwgRNG', 'nodeRNG'].forEach(function(rng) {
222
+ if (uuid[rng]) {
223
+ var options = {rng: uuid[rng]};
224
+ for (var i = 0, t = Date.now(); i < N; i++) generator(options);
225
+ rate('uuid.' + version + '() with ' + rng, t);
226
+ } else {
227
+ log('uuid.' + version + '() with ' + rng + ': not defined');
228
+ }
229
+ });
72
230
  } else {
73
- // Otherwise: 1:16 odds on 30 digits
74
- ideal = N*30/16;
231
+ for (var i = 0, t = Date.now(); i < N; i++) generator();
232
+ rate('uuid.' + version + '()', t);
75
233
  }
76
- var d = divergence(n, ideal);
77
234
 
78
- // Draw bar using UTF squares (just for grins)
79
- var s = n/max*50 | 0;
80
- while (s--) bar += '=';
235
+ for (var i = 0, t = Date.now(); i < N; i++) generator('binary');
236
+ rate('uuid.' + version + '(\'binary\')', t);
81
237
 
82
- log(c + ' |' + bar + '| ' + counts[c] + ' (' + d + '%)');
238
+ for (var i = 0, t = Date.now(); i < N; i++) generator('binary', buf);
239
+ rate('uuid.' + version + '(\'binary\', buffer)', t);
83
240
  }