sproutit-narwhal 0.1.106

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. data/DISTRIBUTION.yml +15 -0
  2. data/README.md +86 -0
  3. data/Rakefile +349 -0
  4. data/VERSION.yml +7 -0
  5. data/bin/activate +50 -0
  6. data/bin/activate.bash +50 -0
  7. data/bin/activate.cmd +3 -0
  8. data/bin/js +67 -0
  9. data/bin/json +2 -0
  10. data/bin/narwhal +67 -0
  11. data/bin/narwhal.cmd +29 -0
  12. data/bin/sea +45 -0
  13. data/bin/sea.cmd +25 -0
  14. data/bin/tusk +2 -0
  15. data/bin/tusk.cmd +5 -0
  16. data/catalog.json +902 -0
  17. data/docs/available-packages.md +32 -0
  18. data/docs/browser-api-plan.md +290 -0
  19. data/docs/browser-api.md +153 -0
  20. data/docs/download.md +25 -0
  21. data/docs/engines.md +32 -0
  22. data/docs/json-tool.md +121 -0
  23. data/docs/lib/binary.wiki +242 -0
  24. data/docs/lib/file.wiki +325 -0
  25. data/docs/lib/os/popen.md +70 -0
  26. data/docs/modules.md +38 -0
  27. data/docs/narwhal.md +487 -0
  28. data/docs/packages-howto.md +32 -0
  29. data/docs/packages.md +30 -0
  30. data/docs/posts/2009-07-29-hello-0.1.md +19 -0
  31. data/docs/quick-start.md +69 -0
  32. data/docs/sea.md +49 -0
  33. data/engines/browser/lib/binary.js +2 -0
  34. data/engines/browser/lib/reactor.js +21 -0
  35. data/engines/browser/lib/system.js +3 -0
  36. data/engines/default/lib/array.js +164 -0
  37. data/engines/default/lib/binary-engine.js +53 -0
  38. data/engines/default/lib/binary.js +755 -0
  39. data/engines/default/lib/date.js +8 -0
  40. data/engines/default/lib/file-engine.js +119 -0
  41. data/engines/default/lib/function.js +119 -0
  42. data/engines/default/lib/global.js +11 -0
  43. data/engines/default/lib/io-engine.js +26 -0
  44. data/engines/default/lib/json.js +488 -0
  45. data/engines/default/lib/object.js +69 -0
  46. data/engines/default/lib/os-engine.js +3 -0
  47. data/engines/default/lib/reactor.js +12 -0
  48. data/engines/default/lib/string.js +84 -0
  49. data/engines/default/lib/system.js +20 -0
  50. data/engines/default/lib/worker.js +133 -0
  51. data/engines/jsc/README.md +18 -0
  52. data/engines/jsc/bootstrap.js +53 -0
  53. data/engines/jsc/deps/http-parser/LICENSE +77 -0
  54. data/engines/jsc/deps/http-parser/README.md +145 -0
  55. data/engines/jsc/deps/http-parser/http_parser.c +6087 -0
  56. data/engines/jsc/deps/http-parser/http_parser.h +141 -0
  57. data/engines/jsc/deps/http-parser/http_parser.rl +500 -0
  58. data/engines/jsc/deps/http-parser/test.c +858 -0
  59. data/engines/jsc/include/binary-engine.h +11 -0
  60. data/engines/jsc/include/io-engine.h +23 -0
  61. data/engines/jsc/include/narwhal.h +427 -0
  62. data/engines/jsc/lib/file-engine.js +31 -0
  63. data/engines/jsc/lib/http.js +1 -0
  64. data/engines/jsc/lib/io-engine.js +202 -0
  65. data/engines/jsc/lib/os-engine.js +25 -0
  66. data/engines/jsc/lib/system.js +18 -0
  67. data/engines/jsc/lib/zip.js +1 -0
  68. data/engines/jsc/narwhal-jsc.c +273 -0
  69. data/engines/jsc/narwhal.c +29 -0
  70. data/engines/jsc/package.json +8 -0
  71. data/engines/jsc/src/binary-engine.cc +290 -0
  72. data/engines/jsc/src/file-engine.cc +405 -0
  73. data/engines/jsc/src/io-engine.cc +423 -0
  74. data/engines/jsc/src/jack/handler/jill.cc +710 -0
  75. data/engines/jsc/src/os-engine.cc +210 -0
  76. data/engines/rhino/bin/narwhal-rhino +68 -0
  77. data/engines/rhino/bin/narwhal-rhino.cmd +34 -0
  78. data/engines/rhino/bootstrap.js +119 -0
  79. data/engines/rhino/jars/jline.jar +0 -0
  80. data/engines/rhino/jars/jna.jar +0 -0
  81. data/engines/rhino/jars/js.jar +0 -0
  82. data/engines/rhino/lib/binary-engine.js +83 -0
  83. data/engines/rhino/lib/concurrency.js +6 -0
  84. data/engines/rhino/lib/event-queue.js +18 -0
  85. data/engines/rhino/lib/file-engine.js +216 -0
  86. data/engines/rhino/lib/http-client-engine.js +90 -0
  87. data/engines/rhino/lib/http-engine.js +10 -0
  88. data/engines/rhino/lib/io-engine.js +347 -0
  89. data/engines/rhino/lib/md5-engine.js +40 -0
  90. data/engines/rhino/lib/os-engine.js +150 -0
  91. data/engines/rhino/lib/packages-engine.js +71 -0
  92. data/engines/rhino/lib/sandbox-engine.js +70 -0
  93. data/engines/rhino/lib/system.js +38 -0
  94. data/engines/rhino/lib/worker-engine.js +23 -0
  95. data/engines/rhino/lib/zip.js +78 -0
  96. data/engines/rhino/package.json +4 -0
  97. data/engines/secure/lib/file.js +6 -0
  98. data/engines/secure/lib/system.js +6 -0
  99. data/engines/template/bin/narwhal-engine-name +32 -0
  100. data/engines/template/bootstrap.js +40 -0
  101. data/engines/template/lib/file-engine.js +118 -0
  102. data/engines/template/lib/system.js +17 -0
  103. data/examples/browser-deployment-jackconfig.js +35 -0
  104. data/examples/fibonacci-worker.js +35 -0
  105. data/examples/fibonacci.js +19 -0
  106. data/examples/hello +2 -0
  107. data/examples/narwhal +3 -0
  108. data/examples/not-quite-a-quine.js +1 -0
  109. data/extconf.rb +44 -0
  110. data/gem_bin/narwhal +5 -0
  111. data/gem_bin/sea +4 -0
  112. data/gem_bin/tusk +4 -0
  113. data/lib/args.js +849 -0
  114. data/lib/base16.js +16 -0
  115. data/lib/base64.js +120 -0
  116. data/lib/codec/base64.js +8 -0
  117. data/lib/crc32.js +60 -0
  118. data/lib/file-bootstrap.js +187 -0
  119. data/lib/file.js +659 -0
  120. data/lib/hash.js +28 -0
  121. data/lib/hashp.js +65 -0
  122. data/lib/html.js +16 -0
  123. data/lib/http-client.js +134 -0
  124. data/lib/http.js +17 -0
  125. data/lib/io.js +98 -0
  126. data/lib/jsmin.js +315 -0
  127. data/lib/jsonpath.js +89 -0
  128. data/lib/logger.js +55 -0
  129. data/lib/md4.js +146 -0
  130. data/lib/md5.js +164 -0
  131. data/lib/mime.js +166 -0
  132. data/lib/narwhal.js +102 -0
  133. data/lib/narwhal/client.js +261 -0
  134. data/lib/narwhal/compile.js +99 -0
  135. data/lib/narwhal/env.js +140 -0
  136. data/lib/narwhal/inline.js +106 -0
  137. data/lib/narwhal/json.js +324 -0
  138. data/lib/narwhal/json.md +178 -0
  139. data/lib/narwhal/repl.js +96 -0
  140. data/lib/narwhal/server-test.js +6 -0
  141. data/lib/narwhal/server.js +270 -0
  142. data/lib/narwhal/tusk.js +170 -0
  143. data/lib/narwhal/tusk/bin.js +13 -0
  144. data/lib/narwhal/tusk/bundle.js +0 -0
  145. data/lib/narwhal/tusk/catalog.js +22 -0
  146. data/lib/narwhal/tusk/clone.js +66 -0
  147. data/lib/narwhal/tusk/consolidate.js +25 -0
  148. data/lib/narwhal/tusk/create-catalog.js +80 -0
  149. data/lib/narwhal/tusk/engine.js +42 -0
  150. data/lib/narwhal/tusk/freeze.js +0 -0
  151. data/lib/narwhal/tusk/init.js +56 -0
  152. data/lib/narwhal/tusk/install.js +288 -0
  153. data/lib/narwhal/tusk/list.js +20 -0
  154. data/lib/narwhal/tusk/orphans.js +0 -0
  155. data/lib/narwhal/tusk/reheat.js +15 -0
  156. data/lib/narwhal/tusk/remove.js +15 -0
  157. data/lib/narwhal/tusk/search.js +145 -0
  158. data/lib/narwhal/tusk/update.js +21 -0
  159. data/lib/narwhal/tusk/upgrade.js +0 -0
  160. data/lib/os.js +33 -0
  161. data/lib/packages.js +423 -0
  162. data/lib/printf.js +169 -0
  163. data/lib/promise.js +352 -0
  164. data/lib/querystring.js +176 -0
  165. data/lib/ref-send.js +257 -0
  166. data/lib/regexp.js +12 -0
  167. data/lib/sandbox.js +422 -0
  168. data/lib/sha.js +112 -0
  169. data/lib/sha256.js +102 -0
  170. data/lib/struct.js +228 -0
  171. data/lib/term.js +179 -0
  172. data/lib/test/assert.js +95 -0
  173. data/lib/test/equiv.js +188 -0
  174. data/lib/test/jsdump.js +165 -0
  175. data/lib/test/runner.js +129 -0
  176. data/lib/unload.js +13 -0
  177. data/lib/uri.js +378 -0
  178. data/lib/url.js +5 -0
  179. data/lib/utf8.js +64 -0
  180. data/lib/util.js +985 -0
  181. data/lib/uuid.js +89 -0
  182. data/lib/xregexp.js +521 -0
  183. data/local.json.template +1 -0
  184. data/narwhal.gemspec +105 -0
  185. data/narwhal.js +213 -0
  186. data/package.json +26 -0
  187. data/packages/readline/engines/default/lib/readline.js +4 -0
  188. data/packages/readline/engines/rhino/lib/readline.js +6 -0
  189. data/packages/readline/package.json +5 -0
  190. data/sources.json +207 -0
  191. data/tests/all-tests.js +17 -0
  192. data/tests/args.js +31 -0
  193. data/tests/args/domain.js +215 -0
  194. data/tests/args/options.js +36 -0
  195. data/tests/args/shifting.js +92 -0
  196. data/tests/args/validation.js +31 -0
  197. data/tests/base64.js +23 -0
  198. data/tests/commonjs.js +3 -0
  199. data/tests/commonjs/all-tests.js +12 -0
  200. data/tests/commonjs/bytearray-encodings-tests.js +69 -0
  201. data/tests/commonjs/bytearray-tests.js +465 -0
  202. data/tests/commonjs/bytestring-encodings-tests.js +89 -0
  203. data/tests/commonjs/bytestring-tests.js +263 -0
  204. data/tests/commonjs/es5/all-tests.js +3 -0
  205. data/tests/commonjs/es5/bind.js +29 -0
  206. data/tests/commonjs/file-tests.js +315 -0
  207. data/tests/commonjs/file/dirname.js +31 -0
  208. data/tests/commonjs/file/extension.js +45 -0
  209. data/tests/commonjs/file/is-absolute.js +11 -0
  210. data/tests/commonjs/file/iterator.js +101 -0
  211. data/tests/commonjs/file/normal.js +27 -0
  212. data/tests/commonjs/file/path.js +17 -0
  213. data/tests/commonjs/file/relative.js +42 -0
  214. data/tests/commonjs/file/resolve.js +44 -0
  215. data/tests/commonjs/module-tests.js +9 -0
  216. data/tests/commonjs/modules/absolute/b.js +1 -0
  217. data/tests/commonjs/modules/absolute/program.js +5 -0
  218. data/tests/commonjs/modules/absolute/submodule/a.js +3 -0
  219. data/tests/commonjs/modules/absolute/test.js +9 -0
  220. data/tests/commonjs/modules/all-tests.js +47 -0
  221. data/tests/commonjs/modules/config.js +11 -0
  222. data/tests/commonjs/modules/cyclic/a.js +4 -0
  223. data/tests/commonjs/modules/cyclic/b.js +4 -0
  224. data/tests/commonjs/modules/cyclic/program.js +10 -0
  225. data/tests/commonjs/modules/cyclic/test.js +9 -0
  226. data/tests/commonjs/modules/determinism/program.js +3 -0
  227. data/tests/commonjs/modules/determinism/submodule/a.js +8 -0
  228. data/tests/commonjs/modules/determinism/submodule/b.js +2 -0
  229. data/tests/commonjs/modules/determinism/test.js +9 -0
  230. data/tests/commonjs/modules/exactExports/a.js +3 -0
  231. data/tests/commonjs/modules/exactExports/program.js +4 -0
  232. data/tests/commonjs/modules/exactExports/test.js +9 -0
  233. data/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js +0 -0
  234. data/tests/commonjs/modules/hasOwnProperty/program.js +3 -0
  235. data/tests/commonjs/modules/hasOwnProperty/test.js +9 -0
  236. data/tests/commonjs/modules/hasOwnProperty/toString.js +0 -0
  237. data/tests/commonjs/modules/method/a.js +12 -0
  238. data/tests/commonjs/modules/method/program.js +8 -0
  239. data/tests/commonjs/modules/method/test.js +9 -0
  240. data/tests/commonjs/modules/missing/program.js +8 -0
  241. data/tests/commonjs/modules/missing/test.js +9 -0
  242. data/tests/commonjs/modules/monkeys/a.js +1 -0
  243. data/tests/commonjs/modules/monkeys/program.js +4 -0
  244. data/tests/commonjs/modules/monkeys/test.js +9 -0
  245. data/tests/commonjs/modules/nested/a/b/c/d.js +3 -0
  246. data/tests/commonjs/modules/nested/program.js +3 -0
  247. data/tests/commonjs/modules/nested/test.js +9 -0
  248. data/tests/commonjs/modules/relative/program.js +5 -0
  249. data/tests/commonjs/modules/relative/submodule/a.js +1 -0
  250. data/tests/commonjs/modules/relative/submodule/b.js +2 -0
  251. data/tests/commonjs/modules/relative/test.js +9 -0
  252. data/tests/commonjs/modules/transitive/a.js +1 -0
  253. data/tests/commonjs/modules/transitive/b.js +1 -0
  254. data/tests/commonjs/modules/transitive/c.js +3 -0
  255. data/tests/commonjs/modules/transitive/program.js +3 -0
  256. data/tests/commonjs/modules/transitive/test.js +9 -0
  257. data/tests/file/all-tests.js +61 -0
  258. data/tests/file/fnmatch.js +102 -0
  259. data/tests/file/glob.js +466 -0
  260. data/tests/file/match.js +102 -0
  261. data/tests/global.js +6 -0
  262. data/tests/global/array.js +19 -0
  263. data/tests/hashes.js +94 -0
  264. data/tests/html.js +13 -0
  265. data/tests/io/stringio.js +21 -0
  266. data/tests/os/all-tests.js +4 -0
  267. data/tests/os/popen.js +41 -0
  268. data/tests/os/system.js +22 -0
  269. data/tests/printf.js +123 -0
  270. data/tests/query-string.js +87 -0
  271. data/tests/sandbox/byte-io.js +20 -0
  272. data/tests/sandbox/fileName.js +3 -0
  273. data/tests/sandbox/foo.js +0 -0
  274. data/tests/sandbox/reload.js +79 -0
  275. data/tests/string.js +35 -0
  276. data/tests/uri.js +41 -0
  277. data/tests/util/all-tests.js +79 -0
  278. data/tests/util/array.js +207 -0
  279. data/tests/util/array/is-arguments.js +29 -0
  280. data/tests/util/array/is-array-like.js +29 -0
  281. data/tests/util/case.js +9 -0
  282. data/tests/util/collection.js +104 -0
  283. data/tests/util/eq.js +57 -0
  284. data/tests/util/expand.js +45 -0
  285. data/tests/util/object.js +125 -0
  286. data/tests/util/operator.js +25 -0
  287. data/tests/util/range.js +19 -0
  288. data/tests/util/repr.js +26 -0
  289. data/tests/util/string.js +34 -0
  290. data/tests/util/unique.js +12 -0
  291. metadata +434 -0
@@ -0,0 +1,89 @@
1
+ var assert = require("test/assert");
2
+
3
+ var Binary = require("binary").Binary,
4
+ ByteString = require("binary").ByteString,
5
+ ByteArray = require("binary").ByteArray;
6
+
7
+ exports.testByteStringConstructorEncodings = function() {
8
+ // ByteString(string, charset)
9
+ // Convert a string. The ByteString will contain string encoded with charset.
10
+ var testString = "hello world";
11
+ var b4 = new ByteString(testString, "ASCII");
12
+ assert.isEqual(testString.length, b4.length, "6543");
13
+ b4.length = 123;
14
+ assert.isEqual(testString.length, b4.length, "asdf");
15
+ assert.isEqual(testString.charCodeAt(0), b4.get(0), "234");
16
+ assert.isEqual(testString.charCodeAt(testString.length-1), b4.get(testString.length-1), "zxcv");
17
+ };
18
+
19
+ exports.testToByteStringConstructorUnicode = function() {
20
+ var testString = "I ♥ JS";
21
+ var b = new ByteString(testString, "UTF-8");
22
+
23
+ assert.isEqual(8, b.length, "length");
24
+
25
+ assert.isEqual(0x49, b.get(0), "expected I");
26
+ assert.isEqual(0x20, b.get(1), "expected [space]");
27
+ assert.isEqual(0xE2, b.get(2), "expected heart byte 1");
28
+ assert.isEqual(0x99, b.get(3), "expected heart byte 1");
29
+ assert.isEqual(0xA5, b.get(4), "expected heart byte 1");
30
+ assert.isEqual(0x20, b.get(5), "expected [space]");
31
+ assert.isEqual(0x4A, b.get(6), "expected J");
32
+ assert.isEqual(0x53, b.get(7), "expected S");
33
+ }
34
+
35
+ exports.testToByteArrayEncodings = function() {
36
+ var testString = "I ♥ JS";
37
+ assert.isEqual(testString, new ByteString(testString, "UTF-8").toByteArray("UTF-8", "UTF-16").decodeToString("UTF-16"));
38
+ };
39
+
40
+ exports.testToByteStringEncodings = function() {
41
+ var testString = "I ♥ JS";
42
+ assert.isEqual(testString, new ByteString(testString, "UTF-8").toByteString("UTF-8", "UTF-16").decodeToString("UTF-16"));
43
+ };
44
+
45
+ exports.testToArrayEncodings = function() {
46
+ var a1;
47
+
48
+ a1 = new ByteString("\u0024\u00A2\u20AC", "UTF-8").toArray("UTF-8");
49
+ assert.isEqual(3, a1.length);
50
+ assert.isEqual(0x24, a1[0]);
51
+ assert.isEqual(0xA2, a1[1]);
52
+ assert.isEqual(0x20AC, a1[2]);
53
+
54
+ a1 = new ByteString("\u0024\u00A2\u20AC", "UTF-16").toArray("UTF-16");
55
+ assert.isEqual(3, a1.length);
56
+ assert.isEqual(0x24, a1[0]);
57
+ assert.isEqual(0xA2, a1[1]);
58
+ assert.isEqual(0x20AC, a1[2]);
59
+ };
60
+
61
+ exports.testDecodeToString = function() {
62
+ assert.isEqual("hello world", new ByteString("hello world", "US-ASCII").decodeToString("US-ASCII"));
63
+
64
+ assert.isEqual("I ♥ JS", new ByteString("I ♥ JS", "UTF-8").decodeToString("UTF-8"));
65
+
66
+ assert.isEqual("\u0024", new ByteString([0x24]).decodeToString("UTF-8"));
67
+ assert.isEqual("\u00A2", new ByteString([0xC2,0xA2]).decodeToString("UTF-8"));
68
+ assert.isEqual("\u20AC", new ByteString([0xE2,0x82,0xAC]).decodeToString("UTF-8"));
69
+ // FIXME:
70
+ //assert.isEqual("\u10ABCD", (new ByteString([0xF4,0x8A,0xAF,0x8D])).decodeToString("UTF-8"));
71
+
72
+ assert.isEqual("\u0024", new ByteString("\u0024", "UTF-8").decodeToString("UTF-8"));
73
+ assert.isEqual("\u00A2", new ByteString("\u00A2", "UTF-8").decodeToString("UTF-8"));
74
+ assert.isEqual("\u20AC", new ByteString("\u20AC", "UTF-8").decodeToString("UTF-8"));
75
+ assert.isEqual("\u10ABCD", new ByteString("\u10ABCD", "UTF-8").decodeToString("UTF-8"));
76
+
77
+ assert.isEqual("\u0024", new ByteString("\u0024", "UTF-16").decodeToString("UTF-16"));
78
+ assert.isEqual("\u00A2", new ByteString("\u00A2", "UTF-16").decodeToString("UTF-16"));
79
+ assert.isEqual("\u20AC", new ByteString("\u20AC", "UTF-16").decodeToString("UTF-16"));
80
+ assert.isEqual("\u10ABCD", new ByteString("\u10ABCD", "UTF-16").decodeToString("UTF-16"));
81
+ };
82
+
83
+ exports.testStringToByteString = function() {
84
+ assert.isEqual("hello world", "hello world".toByteString("US-ASCII").decodeToString("US-ASCII"));
85
+ assert.isEqual("I ♥ JS", "I ♥ JS".toByteString("UTF-8").decodeToString("UTF-8"));
86
+ };
87
+
88
+ if (require.main === module.id)
89
+ require("os").exit(require("test/runner").run(exports));
@@ -0,0 +1,263 @@
1
+ var assert = require("test/assert");
2
+
3
+ var Binary = require("binary").Binary,
4
+ ByteString = require("binary").ByteString,
5
+ ByteArray = require("binary").ByteArray;
6
+
7
+ exports.testByteStringConstructor = function() {
8
+ var testArray = [1,2,3,4];
9
+
10
+ // ByteString()
11
+ // Construct an empty byte string.
12
+ var b1 = new ByteString();
13
+ //assert.isTrue(b1 instanceof Binary, "not instanceof Binary");
14
+ assert.isTrue(b1 instanceof ByteString, "not instanceof ByteString");
15
+ assert.isEqual(0, b1.length);
16
+ b1.length = 123;
17
+ assert.isEqual(0, b1.length);
18
+
19
+ // ByteString(byteString)
20
+ // Copies byteString.
21
+ var b2 = new ByteString(new ByteString(testArray));
22
+ assert.isEqual(testArray.length, b2.length);
23
+ b2.length = 123;
24
+ assert.isEqual(testArray.length, b2.length);
25
+ assert.isEqual(1, b2.get(0));
26
+ assert.isEqual(4, b2.get(3));
27
+
28
+ // ByteString(byteArray)
29
+ // Use the contents of byteArray.
30
+ var b2 = new ByteString(new ByteArray(testArray));
31
+ assert.isEqual(testArray.length, b2.length);
32
+ b2.length = 123;
33
+ assert.isEqual(testArray.length, b2.length);
34
+ assert.isEqual(1, b2.get(0));
35
+ assert.isEqual(4, b2.get(3));
36
+
37
+ // ByteString(arrayOfNumbers)
38
+ // Use the numbers in arrayOfNumbers as the bytes.
39
+ // If any element is outside the range 0...255, an exception (TODO) is thrown.
40
+ var b3 = new ByteString(testArray);
41
+ assert.isEqual(testArray.length, b3.length);
42
+ b3.length = 123;
43
+ assert.isEqual(testArray.length, b3.length);
44
+ assert.isEqual(1, b3.get(0));
45
+ assert.isEqual(4, b3.get(3));
46
+ };
47
+
48
+ //exports.testByteStringJoin = function() {
49
+ //}
50
+
51
+ exports.testToByteArray = function() {
52
+ var b1 = new ByteString([1,2,3]),
53
+ b2 = b1.toByteArray();
54
+
55
+ assert.isTrue(b2 instanceof ByteArray, "not instanceof ByteArray");
56
+ assert.isEqual(b1.length, b2.length);
57
+ assert.isEqual(b1.get(0), b2.get(0));
58
+ assert.isEqual(b1.get(2), b2.get(2));
59
+ };
60
+
61
+ exports.testToByteString = function() {
62
+ var b1 = new ByteString([1,2,3]),
63
+ b2 = b1.toByteString();
64
+
65
+ assert.isEqual(b1.length, b2.length);
66
+ assert.isEqual(b1.get(0), b2.get(0));
67
+ assert.isEqual(b1.get(2), b2.get(2));
68
+ };
69
+
70
+ exports.testToArray = function() {
71
+ var testArray = [0,1,254,255],
72
+ b1 = new ByteString(testArray),
73
+ a1 = b1.toArray();
74
+
75
+ assert.isEqual(testArray.length, a1.length);
76
+ for (var i = 0; i < testArray.length; i++)
77
+ assert.isEqual(testArray[i], a1[i]);
78
+ };
79
+
80
+ exports.testToString = function() {
81
+ // the format of the resulting string isn't specified, but it shouldn't be the decoded string
82
+ // TODO: is this an ok test?
83
+
84
+ var testString = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
85
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
86
+ testArray = [];
87
+ for (var i = 0; i < 128; i++) testArray.push(65);
88
+
89
+ var resultString = new ByteString(testArray).toString();
90
+
91
+ assert.isTrue(resultString.length < 100);
92
+ assert.isTrue(resultString !== testString);
93
+ };
94
+
95
+ exports.testIndexOf = function() {
96
+ var b1 = new ByteString([0,1,2,3,4,5,0,1,2,3,4,5]);
97
+
98
+ assert.isEqual(-1, b1.indexOf(-1));
99
+
100
+ assert.isEqual(0, b1.indexOf(0));
101
+ assert.isEqual(5, b1.indexOf(5));
102
+ assert.isEqual(-1, b1.indexOf(12));
103
+
104
+ assert.isEqual(6, b1.indexOf(0, 6));
105
+ assert.isEqual(11, b1.indexOf(5, 6));
106
+ assert.isEqual(-1, b1.indexOf(12, 6));
107
+
108
+ assert.isEqual(0, b1.indexOf(0, 0, 3));
109
+ assert.isEqual(-1, b1.indexOf(5, 0, 3));
110
+ assert.isEqual(-1, b1.indexOf(12, 0, 3));
111
+ };
112
+
113
+ exports.testLastIndexOf = function() {
114
+ var b1 = new ByteString([0,1,2,3,4,5,0,1,2,3,4,5]);
115
+
116
+ assert.isEqual(-1, b1.lastIndexOf(-1));
117
+
118
+ assert.isEqual(6, b1.lastIndexOf(0));
119
+ assert.isEqual(11, b1.lastIndexOf(5));
120
+ assert.isEqual(-1, b1.lastIndexOf(12));
121
+
122
+ assert.isEqual(0, b1.lastIndexOf(0, 0, 6));
123
+ assert.isEqual(5, b1.lastIndexOf(5, 0, 6));
124
+ assert.isEqual(-1, b1.lastIndexOf(12, 0, 6));
125
+
126
+ assert.isEqual(6, b1.lastIndexOf(0, 6, 9));
127
+ assert.isEqual(-1, b1.lastIndexOf(5, 6, 9));
128
+ assert.isEqual(-1, b1.lastIndexOf(12, 6, 9));
129
+ };
130
+
131
+ exports.testCharCodeAt = function() {
132
+ var b1 = new ByteString([0,1,2,3,4,255]);
133
+
134
+ assert.isTrue(isNaN(b1.charCodeAt(-1)));
135
+ assert.isEqual(0, b1.charCodeAt(0));
136
+ assert.isEqual(255, b1.charCodeAt(5));
137
+ assert.isTrue(isNaN(b1.charCodeAt(6)));
138
+ };
139
+
140
+ // identical to charCodeAt, test anyway?
141
+ exports.testGet = function() {
142
+ var b1 = new ByteString([0,1,2,3,4,255]);
143
+
144
+ assert.isTrue(isNaN(b1.get(-1)));
145
+ assert.isEqual(0, b1.get(0));
146
+ assert.isEqual(255, b1.get(5));
147
+ assert.isTrue(isNaN(b1.get(6)));
148
+ };
149
+
150
+ exports.testByteAt = function() {
151
+ var b1 = new ByteString([0,1,2,3,4,255]), b2;
152
+
153
+ b2 = b1.byteAt(-1);
154
+ assert.isEqual(0, b2.length);
155
+ b2 = b1.byteAt(0);
156
+ assert.isEqual(1, b2.length);
157
+ assert.isEqual(0, b2.get(0));
158
+ b2 = b1.byteAt(5);
159
+ assert.isEqual(1, b2.length);
160
+ assert.isEqual(255, b2.get(0));
161
+ b2 = b1.byteAt(6);
162
+ assert.isEqual(0, b2.length);
163
+ };
164
+
165
+ // identical to byteAt, test anyway?
166
+ exports.testCharAt = function() {
167
+ var b1 = new ByteString([0,1,2,3,4,255]), b2;
168
+
169
+ b2 = b1.charAt(-1);
170
+ assert.isEqual(0, b2.length);
171
+ b2 = b1.charAt(0);
172
+ assert.isEqual(1, b2.length);
173
+ assert.isEqual(0, b2.get(0));
174
+ b2 = b1.charAt(5);
175
+ assert.isEqual(1, b2.length);
176
+ assert.isEqual(255, b2.get(0));
177
+ b2 = b1.charAt(6);
178
+ assert.isEqual(0, b2.length);
179
+ };
180
+
181
+ exports.testSplit = function() {
182
+ var b1 = new ByteString([0,1,2,3,4,5]), a1;
183
+
184
+ a1 = b1.split([]);
185
+ assert.isEqual(1, a1.length);
186
+ assert.isTrue(a1[0] instanceof ByteString);
187
+ assert.isEqual(6, a1[0].length);
188
+ assert.isEqual(0, a1[0].get(0));
189
+ assert.isEqual(5, a1[0].get(5));
190
+
191
+ a1 = b1.split([2]);
192
+ assert.isEqual(2, a1.length);
193
+ assert.isTrue(a1[0] instanceof ByteString);
194
+ assert.isEqual(2, a1[0].length);
195
+ assert.isEqual(0, a1[0].get(0));
196
+ assert.isEqual(1, a1[0].get(1));
197
+ assert.isEqual(3, a1[1].length);
198
+ assert.isEqual(3, a1[1].get(0));
199
+ assert.isEqual(5, a1[1].get(2));
200
+
201
+ a1 = b1.split([2], { includeDelimiter : true });
202
+ assert.isEqual(3, a1.length);
203
+ assert.isTrue(a1[0] instanceof ByteString);
204
+ assert.isEqual(2, a1[0].length);
205
+ assert.isEqual(0, a1[0].get(0));
206
+ assert.isEqual(1, a1[0].get(1));
207
+ assert.isEqual(1, a1[1].length);
208
+ assert.isEqual(2, a1[1].get(0));
209
+ assert.isEqual(3, a1[2].length);
210
+ assert.isEqual(3, a1[2].get(0));
211
+ assert.isEqual(5, a1[2].get(2));
212
+
213
+ a1 = b1.split(new ByteString([2,3]));
214
+ assert.isEqual(2, a1.length);
215
+ assert.isTrue(a1[0] instanceof ByteString);
216
+ assert.isEqual(2, a1[0].length);
217
+ assert.isEqual(0, a1[0].get(0));
218
+ assert.isEqual(1, a1[0].get(1));
219
+ assert.isEqual(2, a1[1].length);
220
+ assert.isEqual(4, a1[1].get(0));
221
+ assert.isEqual(5, a1[1].get(1));
222
+ };
223
+
224
+ exports.testSlice = function() {
225
+ var b1 = new ByteString([0,1,2,3,4,5]), b2;
226
+
227
+ b2 = b1.slice();
228
+ assert.isEqual(6, b2.length);
229
+ assert.isEqual(0, b2.get(0));
230
+ assert.isEqual(5, b2.get(5));
231
+
232
+ b2 = b1.slice(0);
233
+ assert.isEqual(6, b2.length);
234
+ assert.isEqual(0, b2.get(0));
235
+ assert.isEqual(5, b2.get(5));
236
+
237
+ b2 = b1.slice(1, 4);
238
+ assert.isEqual(3, b2.length);
239
+ assert.isEqual(1, b2.get(0));
240
+ assert.isEqual(3, b2.get(2));
241
+
242
+ b2 = b1.slice(0, -1);
243
+ assert.isEqual(5, b2.length);
244
+ assert.isEqual(0, b2.get(0));
245
+ assert.isEqual(4, b2.get(4));
246
+
247
+ b2 = b1.slice(-3, -1);
248
+ assert.isEqual(2, b2.length);
249
+ assert.isEqual(3, b2.get(0));
250
+ assert.isEqual(4, b2.get(1));
251
+
252
+ b2 = b1.slice(9, 10);
253
+ assert.isEqual(0, b2.length);
254
+ };
255
+
256
+ exports.testByteStringNewless = function () {
257
+ assert.isEqual(1, ByteString([0]).length);
258
+ assert.isEqual(2, ByteString([0, 1], 0, 2).length);
259
+ };
260
+
261
+ if (require.main === module.id)
262
+ require("os").exit(require("test/runner").run(exports));
263
+
@@ -0,0 +1,3 @@
1
+ exports.testFunctionBind = require("./bind");
2
+ if (require.main === module.id)
3
+ require("os").exit(require("test/runner").run(exports));
@@ -0,0 +1,29 @@
1
+
2
+ var assert = require("test/assert");
3
+
4
+ exports.testThis = function () {
5
+ var foo = function (y) {
6
+ return this.x + y;
7
+ };
8
+ assert.eq(20, foo.bind({x:10})(10));
9
+ };
10
+
11
+ exports.testPartial = function () {
12
+ var foo = function (y) {
13
+ return this.x + y;
14
+ };
15
+ assert.eq(20, foo.bind({x:10}, 10)());
16
+ };
17
+
18
+ exports.testConstructor = function () {
19
+ var Foo = function (x, y) {
20
+ this.a = x + y;
21
+ };
22
+ assert.eq(30, new (Foo.bind())(10, 20).a);
23
+ assert.eq(30, new (Foo.bind(10))(20).a);
24
+ assert.eq(30, new (Foo.bind(10, 20))().a);
25
+ };
26
+
27
+ if (require.main == module.id)
28
+ require("os").exit(require("test/runner").run(exports));
29
+
@@ -0,0 +1,315 @@
1
+
2
+ var assert = require("test/assert");
3
+ var fs = require("file");
4
+ var binary = require('binary');
5
+
6
+ exports.testWriteRead = function() {
7
+ try {
8
+ var path = "testWriteRead.txt";
9
+ var content = "testWriteRead.txt\n";
10
+ fs.write(path, content);
11
+ assert.is(content, fs.read(path));
12
+ } finally {
13
+ fs.remove(path);
14
+ }
15
+ };
16
+
17
+ exports.testOpenWriteReadWrongMode = function () {
18
+ var path = "testOpenWriteReadWrongMode.txt";
19
+ var content = "testOpenWriteReadWrongMode.txt\n";
20
+ assert.throwsError(function () {
21
+ fs.open(path).write(content).flush().close();
22
+ fs.remove(path);
23
+ });
24
+ };
25
+
26
+ exports.testOpenWriteFlushRead = function () {
27
+ try {
28
+ var path = "testOpenWriteRead.txt";
29
+ var content = "testOpenWriteRead.txt\n";
30
+ fs.open(path, 'w').write(content).flush().close();
31
+ assert.is(content, fs.open(path).read());
32
+ } finally {
33
+ fs.remove(path);
34
+ }
35
+ };
36
+
37
+ exports.testOpenWriteRead = function () {
38
+ try {
39
+ var path = "testOpenWriteRead.txt";
40
+ var content = "testOpenWriteRead.txt\n";
41
+ if (fs.exists(path)) fs.remove(path);
42
+ fs.open(path, 'w').write(content);
43
+ assert.is("", fs.open(path).read());
44
+ } finally {
45
+ fs.remove(path);
46
+ }
47
+ };
48
+
49
+ exports.testOpenWriteReadFlushOnClose = function () {
50
+ try {
51
+ var path = "testOpenWriteRead.txt";
52
+ var content = "testOpenWriteRead.txt\n";
53
+ fs.open(path, 'w').write(content).close();
54
+ assert.is(content, fs.open(path).read());
55
+ } finally {
56
+ fs.remove(path);
57
+ }
58
+ };
59
+
60
+ exports.testPathWriteRead = function () {
61
+ try {
62
+ var path = "testOpenWriteRead.txt";
63
+ var content = "testOpenWriteRead.txt\n";
64
+ fs.path(path).write(content);
65
+ assert.is(content, fs.path(path).read());
66
+ } finally {
67
+ fs.remove(path);
68
+ }
69
+ };
70
+
71
+ exports.testNewPathWriteRead = function () {
72
+ try {
73
+ var path = "testNewPathWriteRead.txt";
74
+ var content = "testNewPathWriteRead.txt\n";
75
+ new fs.Path(path).write(content);
76
+ assert.is(content, fs.Path(path).read());
77
+ } finally {
78
+ fs.remove(path);
79
+ }
80
+ };
81
+
82
+ exports.testBigPathOpenWriteRead = function () {
83
+ try {
84
+ var path = "testBigPathWriteRead.txt";
85
+ var content = "testBigPathWriteRead.txt\n";
86
+ fs.Path(path).write(content);
87
+ assert.is(content, fs.Path(path).read());
88
+ } finally {
89
+ fs.remove(path);
90
+ }
91
+ };
92
+
93
+ exports.testLittlePathOpenWriteRead1 = function () {
94
+ var path = "testLittlePathWriteRead.txt";
95
+ var content = "testLittlePathWriteRead.txt\n";
96
+ assert.throwsError(function () {
97
+ fs.path(path).open().write(content).flush().close();
98
+ fs.remove(path);
99
+ });
100
+ };
101
+
102
+ exports.testLittlePathOpenWriteRead = function () {
103
+ try {
104
+ var path = "testLittlePathOpenWriteRead.txt";
105
+ var content = "testLittlePathOpenWriteRead.txt\n";
106
+ fs.path(path).open('w').write(content).flush().close();
107
+ assert.is(content, fs.path(path).open().read());
108
+ } finally {
109
+ fs.remove(path);
110
+ }
111
+ };
112
+
113
+ exports.testWriteReadNewlineNotEnforced = function() {
114
+ try {
115
+ var path = "testWriteReadNewlineNotEnforced.txt";
116
+ var content = "testWriteReadNewlineNotEnforced.txt";
117
+ fs.write(path, content);
118
+ assert.is(content, fs.read(path));
119
+ } finally {
120
+ fs.remove(path);
121
+ }
122
+ };
123
+ /*
124
+ exports.testWriteReadNewlineEnforced = function() {
125
+ try {
126
+ var path = "testWriteReadNewlineEnforced.txt";
127
+ var content = "testWriteReadNewlineEnforced.txt";
128
+ fs.write(path, content);
129
+ assert.is(content + "\n", fs.read(path));
130
+ } finally {
131
+ fs.remove(path);
132
+ }
133
+ };
134
+ */
135
+
136
+ exports.testOverwriteFile = function() {
137
+ var path = "testOverwriteFile.txt";
138
+ var a = "hello world";
139
+ var b = "hello";
140
+ try {
141
+ fs.write(path, a);
142
+ assert.is(a, fs.read(path));
143
+ assert.is(a.length, fs.size(path));
144
+ fs.write(path, b);
145
+ assert.is(b, fs.read(path));
146
+ assert.is(b.length, fs.size(path));
147
+ } finally {
148
+ if (fs.isFile(path))
149
+ fs.remove(path);
150
+ }
151
+ }
152
+
153
+ exports.testWriteReadBinaryWrongMode = function () {
154
+ var path = "testWriteReadBinaryModeWrongMode.txt";
155
+ var content = "\0\0\0".toByteString("ascii");
156
+ assert.throwsError(function () {
157
+ fs.path(path).open('b').write(content).flush().close();
158
+ fs.remove(path);
159
+ });
160
+ };
161
+
162
+ exports.testWriteReadBinary = function () {
163
+ try {
164
+ var path = "testWriteReadBinary.txt";
165
+ var content = "aaa".toByteString("ascii");
166
+ fs.path(path).open('wb').write(content).flush().close();
167
+ assert.eq(content, fs.path(path).open('b').read());
168
+ } finally {
169
+ fs.remove(path);
170
+ }
171
+ };
172
+
173
+ exports.testWriteReadBinaryNulls = function () {
174
+ try {
175
+ var path = "testWriteReadBinaryNulls.txt";
176
+ var content = "\0\0\0".toByteString("ascii");
177
+ fs.path(path).open('wb').write(content).flush().close();
178
+ assert.eq(content, fs.path(path).open('b').read());
179
+ } finally {
180
+ fs.remove(path);
181
+ }
182
+ };
183
+
184
+ exports.testPrintRead = function () {
185
+ try {
186
+ var path = "testPrintRead.txt";
187
+ fs.path(path).open('w').print("hello").print("world");
188
+ assert.is("hello\nworld\n", fs.path(path).open().read());
189
+ } finally {
190
+ fs.remove(path);
191
+ }
192
+ };
193
+
194
+ exports.testCopy = function () {
195
+ try {
196
+ fs.path("testCopyA.txt").write("testCopy\n").copy("testCopyB.txt");
197
+ assert.is("testCopy\n", fs.read("testCopyB.txt"));
198
+ } finally {
199
+ fs.remove("testCopyA.txt");
200
+ fs.remove("testCopyB.txt");
201
+ }
202
+ };
203
+
204
+ exports.testCopyChain = function () {
205
+ try {
206
+ fs.path("testCopyA.txt").write("testCopy\n").copy("testCopyB.txt").copy("testCopyC.txt");
207
+ assert.is("testCopy\n", fs.read("testCopyC.txt"));
208
+ } finally {
209
+ fs.remove("testCopyA.txt");
210
+ fs.remove("testCopyB.txt");
211
+ fs.remove("testCopyC.txt");
212
+ }
213
+ };
214
+
215
+ exports.testMoveExists = function () {
216
+ var testString = "testCopy";
217
+ try {
218
+ fs.path("testCopyA.txt").write(testString).move("testCopyB.txt");
219
+ assert.isFalse(fs.exists("testCopyA.txt"));
220
+ assert.isTrue(fs.exists("testCopyB.txt"));
221
+ assert.is(fs.size("testCopyB.txt"), testString.length);
222
+ } finally {
223
+ if (fs.exists("testCopyA.txt"))
224
+ fs.remove("testCopyA.txt");
225
+ if (fs.exists("testCopyB.txt"))
226
+ fs.remove("testCopyB.txt");
227
+ }
228
+ };
229
+
230
+ exports.testsExists = function () {
231
+ assert.isTrue(fs.exists(module.path));
232
+ assert.isTrue(fs.path(module.path).exists());
233
+ };
234
+
235
+ exports.testsIsFile = function () {
236
+ assert.isTrue(fs.isFile(module.path));
237
+ assert.isTrue(fs.path(module.path).isFile());
238
+ };
239
+
240
+ exports.testsMkdir = function () {
241
+ try {
242
+ fs.mkdir('testMkdir');
243
+ assert.isTrue(fs.exists('testMkdir'));
244
+ assert.isTrue(fs.isDirectory('testMkdir'));
245
+ assert.isFalse(fs.isFile('testMkdir'));
246
+ } finally {
247
+ fs.rmtree('testMkdir');
248
+ }
249
+ };
250
+
251
+ exports.testsIsDirectoryDirname = function () {
252
+ assert.isTrue(fs.path(module.path).dirname().isDirectory());
253
+ };
254
+
255
+ exports.testsIsDirectoryResolve = function () {
256
+ assert.isTrue(fs.path(module.path).resolve('.').isDirectory());
257
+ };
258
+
259
+ exports.testsRenameList = function () {
260
+ try {
261
+ fs.mkdir('testsRename');
262
+ fs.path('testsRename', 'A.txt').touch();
263
+ assert.eq(fs.path('testsRename').list(), ['A.txt']);
264
+ fs.path('testsRename', 'A.txt').rename('B.txt');
265
+ assert.eq(fs.path('testsRename').list(), ['B.txt']);
266
+ } finally {
267
+ fs.rmtree('testsRename');
268
+ }
269
+ };
270
+
271
+ exports.testsMtime = function () {
272
+ try {
273
+ fs.mkdir('testsMtime');
274
+
275
+ // add/subtract 1 second to account for lower precision of mtime
276
+ var before = new Date().getTime() - 1000;
277
+ fs.path('testsMtime', 'A.txt').touch();
278
+ var after = new Date().getTime() + 1000;
279
+
280
+ var mtime = fs.path('testsMtime', 'A.txt').mtime().getTime();
281
+
282
+ assert.isTrue(before <= mtime, "Expected " + before + " <= " + mtime);
283
+ assert.isTrue(mtime <= after, "Expected " + mtime + " <= " + after);
284
+ } finally {
285
+ fs.rmtree('testsMtime');
286
+ }
287
+ };
288
+
289
+ exports.testEmptyStringIsDirectory = function() {
290
+ assert.isTrue(fs.isDirectory(""), "'' should be a directory");
291
+ }
292
+ exports.testDotIsDirectory = function() {
293
+ assert.isTrue(fs.isDirectory("."), "'.' should be a directory");
294
+ }
295
+ exports.testCwdIsDirectory = function() {
296
+ assert.isTrue(fs.isDirectory(fs.cwd()), fs.cwd() + " should be a directory");
297
+ }
298
+ exports.testIsNotDirectory = function() {
299
+ assert.isFalse(fs.isDirectory("hopefully-not-a-directory"), "'hopefully-not-a-directory' shouldn't be a directory");
300
+ }
301
+
302
+ exports.testCwd = function() {
303
+ assert.eq(system.env["PWD"], fs.cwd(), "Ensure the PWD environment variable is set!");
304
+ }
305
+
306
+ exports.testIterator = require('./file/iterator');
307
+ exports.testExtension = require('./file/extension');
308
+ exports.testResolve = require('./file/resolve');
309
+ exports.testNormal = require('./file/normal');
310
+ exports.testDirname = require('./file/dirname');
311
+ exports.testIsAbsolute = require('./file/is-absolute');
312
+
313
+ if (require.main === module.id)
314
+ require("os").exit(require("test/runner").run(exports));
315
+