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,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1,3 @@
1
+ var test = require('test');
2
+ require('submodule/a');
3
+ print('DONE', 'info');
@@ -0,0 +1,8 @@
1
+ var pass = false;
2
+ var test = require('test');
3
+ try {
4
+ require('a');
5
+ } catch (exception) {
6
+ pass = true;
7
+ }
8
+ test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.')
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1,3 @@
1
+ exports.program = function () {
2
+ return require('program');
3
+ };
@@ -0,0 +1,4 @@
1
+ var test = require('test');
2
+ var a = require('a');
3
+ test.assert(a.program() === exports, 'exact exports');
4
+ print('DONE', 'info');
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1,3 @@
1
+ var hasOwnProperty = require('hasOwnProperty');
2
+ var toString = require('toString');
3
+ print('DONE', 'info');
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
File without changes
@@ -0,0 +1,12 @@
1
+ exports.foo = function () {
2
+ return this;
3
+ };
4
+ exports.set = function (x) {
5
+ this.x = x;
6
+ };
7
+ exports.get = function () {
8
+ return this.x;
9
+ };
10
+ exports.getClosed = function () {
11
+ return exports.x;
12
+ };
@@ -0,0 +1,8 @@
1
+ var test = require('test');
2
+ var a = require('a');
3
+ var foo = a.foo;
4
+ test.assert(a.foo() == a, 'calling a module member');
5
+ test.assert(foo() == (function (){return this})(), 'members not implicitly bound');
6
+ a.set(10);
7
+ test.assert(a.get() == 10, 'get and set')
8
+ print('DONE', 'info');
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1,8 @@
1
+ var test = require('test');
2
+ try {
3
+ require('bogus');
4
+ print('FAIL require throws error when module missing', 'fail');
5
+ } catch (exception) {
6
+ print('PASS require throws error when module missing', 'pass');
7
+ }
8
+ print('DONE', 'info');
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1 @@
1
+ require('program').monkey = 10;
@@ -0,0 +1,4 @@
1
+ var a = require('a');
2
+ var test = require('test');
3
+ test.assert(exports.monkey == 10, 'monkeys permitted');
4
+ print('DONE', 'info');
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1,3 @@
1
+ exports.foo = function () {
2
+ return 1;
3
+ };
@@ -0,0 +1,3 @@
1
+ var test = require('test');
2
+ test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier');
3
+ print('DONE', 'info');
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1,5 @@
1
+ var test = require('test');
2
+ var a = require('submodule/a');
3
+ var b = require('submodule/b');
4
+ test.assert(a.foo == b.foo, 'a and b share foo through a relative require');
5
+ print('DONE', 'info');
@@ -0,0 +1 @@
1
+ exports.foo = require('./b').foo;
@@ -0,0 +1,2 @@
1
+ exports.foo = function () {
2
+ };
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1 @@
1
+ exports.foo = require('b').foo;
@@ -0,0 +1 @@
1
+ exports.foo = require('c').foo;
@@ -0,0 +1,3 @@
1
+ exports.foo = function () {
2
+ return 1;
3
+ };
@@ -0,0 +1,3 @@
1
+ var test = require('test');
2
+ test.assert(require('a').foo() == 1, 'transitive');
3
+ print('DONE', 'info');
@@ -0,0 +1,9 @@
1
+
2
+ exports.assert = function (guard, message) {
3
+ if (guard) {
4
+ print('PASS ' + message, 'pass');
5
+ } else {
6
+ print('FAIL ' + message, 'fail');
7
+ }
8
+ };
9
+
@@ -0,0 +1,61 @@
1
+ var assert = require("test/assert");
2
+ var fs = require("file");
3
+
4
+ exports.testIsLink = function () {
5
+
6
+ var here = fs.path(module.path).dirname().join("_test");
7
+ if (here.exists()) {
8
+ here.rmtree();
9
+ }
10
+ here.mkdirs();
11
+ try {
12
+ var dir1 = here.join("dir1");
13
+ dir1.mkdirs();
14
+ var dir2 = here.join("dir2");
15
+ dir2.mkdirs();
16
+ dir2.join("file2").touch();
17
+
18
+ dir2.symlink(dir1.join("linkToDir2"));
19
+
20
+ assert.isFalse(dir2.isLink());
21
+ assert.isTrue(dir1.join("linkToDir2").isLink());
22
+
23
+ dir2.join("file2").symlink(dir1.join("linkToFile1"));
24
+
25
+ assert.isFalse(dir2.join("file2").isLink());
26
+ assert.isTrue(dir1.join("linkToFile1").isLink());
27
+ } finally {
28
+ here.rmtree();
29
+ }
30
+ }
31
+
32
+ exports.testRmtreeDoesNotFollowSymlinks = function () {
33
+ var here = fs.path(module.path).dirname().join("_test");
34
+ if (here.exists()) {
35
+ here.rmtree();
36
+ }
37
+ here.mkdirs();
38
+ try {
39
+ var dir1 = here.join("dir1");
40
+ dir1.mkdirs();
41
+ var dir2 = here.join("dir2");
42
+ dir2.mkdirs();
43
+ dir2.symlink(dir1.join("linkToDir2"));
44
+ dir2.join("file2").touch();
45
+
46
+ dir1.rmtree();
47
+
48
+ assert.isFalse(dir1.exists());
49
+ assert.isTrue(dir2.exists());
50
+ assert.isTrue(dir2.join("file2").exists());
51
+ } finally {
52
+ here.rmtree();
53
+ }
54
+ };
55
+
56
+ exports.testFileFNMatch = require("./fnmatch");
57
+ exports.testFileMatch = require("./match");
58
+ exports.testFileMatch = require("./glob");
59
+
60
+ if (require.main === module.id)
61
+ require("os").exit(require("test/runner").run(exports));
@@ -0,0 +1,102 @@
1
+ var assert = require("test/assert");
2
+ var fs = require("file");
3
+ var util = require("util");
4
+
5
+ var tests = [
6
+ [true, 'cat', 'cat'],
7
+ [false, 'cat', 'category'],
8
+
9
+ //[false, 'c{at,ub}s', 'cats'],
10
+ //[false, 'c{at,ub}s', 'cubs'],
11
+ [true, 'c{at,ub}s', 'cats'],
12
+ [true, 'c{at,ub}s', 'cubs'],
13
+ [false, 'c{at,ub}s', 'cat'],
14
+
15
+ [true, 'c?t', 'cat'],
16
+ [false, 'c\\?t', 'cat'],
17
+ [false, 'c??t', 'cat'],
18
+ [true, 'c*', 'cats'],
19
+ [true, 'c/*/t', 'c/a/b/c/t'],
20
+ [true, 'c\at', 'cat'],
21
+ [false, 'c\\at', 'cat', fs.FNM_NOESCAPE],
22
+
23
+ [true, 'a?b', 'a/b'],
24
+ [false, 'a?b', 'a/b', fs.FNM_PATHNAME],
25
+
26
+ [false, '*', '.profile'],
27
+ [false, '.*', 'profile'],
28
+ [true, '.*', '.profile'],
29
+ [true, '*', '.profile', fs.FNM_PERIOD],
30
+
31
+ [true, '*', 'dave/.profile'],
32
+ [true, '*', 'dave/.profile', fs.FNM_PERIOD],
33
+ [true, '*', 'dave/profile'],
34
+ [false, '*', 'dave/profile', fs.FNM_PATHNAME],
35
+ [false, '*', 'dave/.profile', fs.FNM_PATHNAME],
36
+ [true, '*/*', 'dave/profile', fs.FNM_PATHNAME],
37
+ [false, '*/*', 'dave/.profile', fs.FNM_PATHNAME],
38
+ [true, '*/*', 'dave/.profile', fs.FNM_PATHNAME | fs.FNM_PERIOD],
39
+
40
+ [true, 'ca[a-z]', 'cat'],
41
+ [false, '[a-z]', 'D'],
42
+ [true, '[^a-z]', 'D'],
43
+ [false, '[A-Z]', 'd'],
44
+ [true, '[^A-Z]', 'd'],
45
+ [true, '[a-z]', 'D', fs.FNM_CASEFOLD],
46
+ [true, '[A-Z]', 'd', fs.FNM_CASEFOLD],
47
+ [false, '/ca[s][s-t]/rul[a-b]/[z]he/[x-Z]orld', '/cats/rule/the/World'],
48
+ [true, '/ca[t][s-t]/rul[a-e]/[t]he/[A-Z]orld', '/cats/rule/the/World'],
49
+
50
+ [false, 'cat', 'CAT'],
51
+ [true, 'cat', 'CAT', fs.FNM_CASEFOLD],
52
+
53
+ [false, 'ca[!t]', 'cat'],
54
+ [false, 'ca[^t]', 'cat'],
55
+
56
+ [false, '?', '/', fs.FNM_PATHNAME],
57
+ [false, '*', '/', fs.FNM_PATHNAME],
58
+
59
+ [true, '\\?', '?'],
60
+ [false, '\\?', 'a'],
61
+ [true, '\\*', '*'],
62
+ [false, '\\*', 'a'],
63
+ [true, '\\a', 'a'],
64
+ [true, 'this\\b', 'thisb'],
65
+ [true, '\\a', '\\a', fs.FNM_NOESCAPE],
66
+ [false, '\\a', 'a', fs.FNM_NOESCAPE],
67
+ [false, '\\[foo\\]\\[bar\\]', '[foo][bar]', fs.FNM_NOESCAPE],
68
+ [true, '\\[foo\\]\\[bar\\]', '[foo][bar]'],
69
+ [true, '[\\?]', '?'],
70
+ [true, '[\\*]', '*'],
71
+
72
+ [false, '**/*.j', 'main.j'],
73
+ [false, '**/*.j', './main.j'],
74
+ [true, '**/*.j', 'lib/main.j'],
75
+ [true, '**.j', 'main.j'],
76
+ [false, '**.j', './main.j'],
77
+ [true, '**.j', 'lib/main.j'],
78
+ [true, '*', 'dave/.profile'],
79
+
80
+ [true, '**/*.j', 'main.j', fs.FNM_PATHNAME],
81
+ [true, '**/*.j', 'one/two/three/main.j', fs.FNM_PATHNAME],
82
+ [false, '**/*.j', './main.j', fs.FNM_PATHNAME],
83
+
84
+ [true, '**/*.j', './main.j', fs.FNM_PATHNAME|fs.FNM_DOTMATCH],
85
+ [true, '**/*.j', 'one/two/.main.j', fs.FNM_PATHNAME|fs.FNM_DOTMATCH],
86
+ [true, '**/best/*', 'lib/my/best/song.j'],
87
+
88
+ [false, '**/foo', 'a/.b/c/foo', fs.FNM_PATHNAME],
89
+ [true, '**/foo', 'a/b/c/foo', fs.FNM_PATHNAME],
90
+ [true, '**/foo', '/a/b/c/foo', fs.FNM_PATHNAME],
91
+ [true, '**/foo', 'a/.b/c/foo', fs.FNM_PATHNAME|fs.FNM_PERIOD]
92
+ ];
93
+
94
+ tests.forEach(function(test, n) {
95
+ exports["test "+util.repr(test)] = function() {
96
+ assert.eq(test[0], fs.fnmatch.apply(fs, test.slice(1)),
97
+ "expect '"+test[1]+"' "+(test[0] ? "matches" : "doesn't match" )+" '"+test[2]+"'");
98
+ }
99
+ });
100
+
101
+ if (require.main === module.id)
102
+ require("os").exit(require("test/runner").run(exports));
@@ -0,0 +1,466 @@
1
+ var FILE = require("file"),
2
+ assert = require("test/assert");
3
+
4
+ // note: need doubled \\ to properly escape in JS
5
+
6
+ // from RubySpec
7
+ function create_mock_dirs(mock_dir) {
8
+ mock_dir = FILE.path(mock_dir);
9
+ var files = [
10
+ ".dotfile",
11
+ ".dotsubdir/.dotfile",
12
+ ".dotsubdir/nondotfile",
13
+
14
+ "deeply/.dotfile",
15
+ "deeply/nested/.dotfile.ext",
16
+ "deeply/nested/directory/structure/.ext",
17
+ "deeply/nested/directory/structure/bar",
18
+ "deeply/nested/directory/structure/baz",
19
+ "deeply/nested/directory/structure/file_one",
20
+ "deeply/nested/directory/structure/file_one.ext",
21
+ "deeply/nested/directory/structure/foo",
22
+ "deeply/nondotfile",
23
+
24
+ "file_one.ext",
25
+ "file_two.ext",
26
+
27
+ "dir_filename_ordering",
28
+ "dir/filename_ordering",
29
+
30
+ "nondotfile",
31
+
32
+ "subdir_one/.dotfile",
33
+ "subdir_one/nondotfile",
34
+ "subdir_two/nondotfile",
35
+ "subdir_two/nondotfile.ext",
36
+
37
+ "special/+",
38
+
39
+ "special/^",
40
+ "special/$",
41
+
42
+ "special/(",
43
+ "special/)",
44
+ "special/[",
45
+ "special/]",
46
+ "special/{",
47
+ "special/}",
48
+
49
+ // these three (and corresponding tests) aren't valid on Windows
50
+ "special/*",
51
+ "special/?",
52
+ "special/|"
53
+ ];
54
+
55
+ files.forEach(function(file) {
56
+ var file = mock_dir.join(file);
57
+
58
+ file.dirname().mkdirs();
59
+ file.touch();
60
+ });
61
+ }
62
+
63
+ function mockDirs(test) {
64
+ try {
65
+ create_mock_dirs("testGlob");
66
+ test(FILE.path("testGlob"));
67
+ } finally {
68
+ FILE.rmtree("testGlob")
69
+ }
70
+ }
71
+
72
+ var expected_paths = [
73
+ ".",
74
+ "..",
75
+ ".dotfile",
76
+ ".dotsubdir",
77
+ "deeply",
78
+ "dir",
79
+ "dir_filename_ordering",
80
+ "file_one.ext",
81
+ "file_two.ext",
82
+ "nondotfile",
83
+ "special",
84
+ "subdir_one",
85
+ "subdir_two"
86
+ ];
87
+
88
+ exports["tests matches both dot and non-dotfiles with '*' and option File::FNM_DOTMATCH"] = function() {
89
+ var expected = [
90
+ ".",
91
+ "..",
92
+ ".dotfile",
93
+ ".dotsubdir",
94
+ "deeply",
95
+ "dir",
96
+ "dir_filename_ordering",
97
+ "file_one.ext",
98
+ "file_two.ext",
99
+ "nondotfile",
100
+ "special",
101
+ "subdir_one",
102
+ "subdir_two"
103
+ ];
104
+
105
+ mockDirs(function(dir) {
106
+ assert.eq(expected, dir.glob("*", FILE.FNM_DOTMATCH).sort());
107
+ });
108
+ }
109
+
110
+ exports["tests matches files with any beginning with '*<non-special characters>' and option File::FNM_DOTMATCH"] = function() {
111
+ var expected = [".dotfile", "nondotfile"];
112
+
113
+ mockDirs(function(dir) {
114
+ assert.eq(expected, dir.glob("*file", FILE.FNM_DOTMATCH).sort());
115
+ });
116
+ }
117
+
118
+ exports["tests matches any files in the current directory with '**' and option File::FNM_DOTMATCH"] = function() {
119
+ mockDirs(function(dir) {
120
+ assert.eq(expected_paths, dir.glob("**", FILE.FNM_DOTMATCH).sort());
121
+ });
122
+ }
123
+
124
+ exports["tests recursively matches any subdirectories except './' or '../' with '**/' and option File::FNM_DOTMATCH"] = function() {
125
+ var expected = [
126
+ ".dotsubdir/",
127
+ "deeply/",
128
+ "deeply/nested/",
129
+ "deeply/nested/directory/",
130
+ "deeply/nested/directory/structure/",
131
+ "dir/",
132
+ "special/",
133
+ "subdir_one/",
134
+ "subdir_two/"
135
+ ];
136
+
137
+ mockDirs(function(dir) {
138
+ assert.eq(expected, dir.glob("**/", FILE.FNM_DOTMATCH).sort());
139
+ });
140
+ }
141
+
142
+ exports["tests matches the literal character '\\' with option File::FNM_NOESCAPE"] = function() {
143
+ FILE.mkdirs('foo?bar');
144
+ try {
145
+ assert.eq(["foo?bar"], FILE.glob('foo?bar', FILE.FNM_NOESCAPE));
146
+ assert.eq([], FILE.glob('foo\\?bar', FILE.FNM_NOESCAPE));
147
+ } finally {
148
+ FILE.rmdir('foo?bar');
149
+ }
150
+
151
+ FILE.mkdir('foo\\?bar');
152
+ try {
153
+ assert.eq(["foo\\?bar"], FILE.glob('foo\\?bar', FILE.FNM_NOESCAPE));
154
+ } finally {
155
+ FILE.rmdir('foo\\?bar');
156
+ }
157
+ }
158
+
159
+ exports["tests returns nil for directories current user has no permission to read"] = function() {
160
+ FILE.mkdirs('no_permission');
161
+ FILE.chmod('no_permission', 0);
162
+
163
+ try {
164
+ assert.eq(null, FILE.glob('no_permission/*'));
165
+ } finally {
166
+ FILE.rmdir('no_permission')
167
+ }
168
+ }
169
+
170
+ // exports["tests converts patterns with to_str"] = function() {
171
+ // obj = mock('file_one.ext')
172
+ // obj.should_receive(:to_str).and_return('file_one.ext')
173
+ //
174
+ // Dir.send(@method, obj).should == %w[file_one.ext]
175
+ // }
176
+
177
+ exports["tests matches non-dotfiles with '*'"] = function() {
178
+ var expected = [
179
+ "deeply",
180
+ "dir",
181
+ "dir_filename_ordering",
182
+ "file_one.ext",
183
+ "file_two.ext",
184
+ "nondotfile",
185
+ "special",
186
+ "subdir_one",
187
+ "subdir_two"
188
+ ];
189
+
190
+ mockDirs(function(dir) {
191
+ assert.eq(expected, dir.glob("**").sort());
192
+ });
193
+ }
194
+
195
+ exports["tests returns empty array when empty pattern provided"] = function() {
196
+ mockDirs(function(dir) {
197
+ assert.eq([], dir.glob("").sort());
198
+ });
199
+ }
200
+
201
+ exports["tests matches regexp special +"] = function() {
202
+ mockDirs(function(dir) {
203
+ assert.eq(['special/+'], dir.glob('special/+').sort());
204
+ });
205
+ }
206
+
207
+ exports["tests matches regexp special *"] = function() {
208
+ mockDirs(function(dir) {
209
+ assert.eq(['special/*'], dir.glob("special/\\*").sort());
210
+ });
211
+ }
212
+
213
+ exports["tests matches regexp special ?"] = function() {
214
+ mockDirs(function(dir) {
215
+ assert.eq(['special/?'], dir.glob("special/\\?").sort());
216
+ });
217
+ }
218
+
219
+ exports["tests matches regexp special |"] = function() {
220
+ mockDirs(function(dir) {
221
+ assert.eq(['special/|'], dir.glob("special/|").sort());
222
+ });
223
+ }
224
+
225
+ exports["tests matches regexp special ^"] = function() {
226
+ mockDirs(function(dir) {
227
+ assert.eq(['special/^'], dir.glob("special/^").sort());
228
+ });
229
+ }
230
+
231
+ exports["tests matches regexp special $"] = function() {
232
+ mockDirs(function(dir) {
233
+ assert.eq(['special/$'], dir.glob("special/$").sort());
234
+ });
235
+ }
236
+
237
+ exports["tests matches regexp special ("] = function() {
238
+ mockDirs(function(dir) {
239
+ assert.eq(['special/('], dir.glob("special/(").sort());
240
+ });
241
+ }
242
+
243
+ exports["tests matches regexp special )"] = function() {
244
+ mockDirs(function(dir) {
245
+ assert.eq(['special/)'], dir.glob("special/)").sort());
246
+ });
247
+ }
248
+
249
+ exports["tests matches regexp special ["] = function() {
250
+ mockDirs(function(dir) {
251
+ assert.eq(['special/['], dir.glob("special/\\[").sort());
252
+ });
253
+ }
254
+
255
+ exports["tests matches regexp special ]"] = function() {
256
+ mockDirs(function(dir) {
257
+ assert.eq(['special/]'], dir.glob('special/]').sort());
258
+ });
259
+ }
260
+
261
+ exports["tests matches regexp special {"] = function() {
262
+ mockDirs(function(dir) {
263
+ assert.eq(['special/{'], dir.glob("special/\\{").sort());
264
+ });
265
+ }
266
+
267
+ exports["tests matches regexp special }"] = function() {
268
+ mockDirs(function(dir) {
269
+ assert.eq(['special/}'], dir.glob("special/\\}").sort());
270
+ });
271
+ }
272
+
273
+ exports["tests matches dotfiles with '.*'"] = function() {
274
+ mockDirs(function(dir) {
275
+ assert.eq(['.','..','.dotfile','.dotsubdir'], dir.glob('.*').sort());
276
+ });
277
+ }
278
+
279
+ exports["tests matches non-dotfiles with '*<non-special characters>'"] = function() {
280
+ mockDirs(function(dir) {
281
+ assert.eq(['nondotfile'], dir.glob('*file').sort());
282
+ });
283
+ }
284
+
285
+ exports["tests matches dotfiles with '.*<non-special characters>'"] = function() {
286
+ mockDirs(function(dir) {
287
+ assert.eq(['.dotfile'], dir.glob('.*file').sort());
288
+ });
289
+ }
290
+
291
+ exports["tests matches files with any ending with '<non-special characters>*'"] = function() {
292
+ mockDirs(function(dir) {
293
+ assert.eq(['file_one.ext','file_two.ext'], dir.glob('file*').sort());
294
+ });
295
+ }
296
+
297
+ exports["tests matches files with any middle with '<non-special characters>*<non-special characters>'"] = function() {
298
+ mockDirs(function(dir) {
299
+ assert.eq(['subdir_one'], dir.glob('sub*_one').sort());
300
+ });
301
+ }
302
+
303
+ exports["tests matches files with multiple '*' special characters"] = function() {
304
+ mockDirs(function(dir) {
305
+ assert.eq(['dir_filename_ordering','nondotfile','file_one.ext','file_two.ext'].sort(), dir.glob('*fi*e*').sort());
306
+ });
307
+ }
308
+
309
+ exports["tests matches non-dotfiles in the current directory with '**'"] = function() {
310
+ var expected = [
311
+ "deeply",
312
+ "dir",
313
+ "dir_filename_ordering",
314
+ "file_one.ext",
315
+ "file_two.ext",
316
+ "nondotfile",
317
+ "special",
318
+ "subdir_one",
319
+ "subdir_two"
320
+ ];
321
+
322
+ mockDirs(function(dir) {
323
+ assert.eq(expected, dir.glob('**').sort());
324
+ });
325
+ }
326
+
327
+ exports["tests matches dotfiles in the current directory with '.**'"] = function() {
328
+ mockDirs(function(dir) {
329
+ assert.eq(['.','..','.dotfile','.dotsubdir'], dir.glob('.**').sort());
330
+ });
331
+ }
332
+
333
+ exports["tests recursively matches any nondot subdirectories with '**/'"] = function() {
334
+ var expected = [
335
+ "deeply/",
336
+ "deeply/nested/",
337
+ "deeply/nested/directory/",
338
+ "deeply/nested/directory/structure/",
339
+ "dir/",
340
+ "special/",
341
+ "subdir_one/",
342
+ "subdir_two/"
343
+ ]
344
+ mockDirs(function(dir) {
345
+ assert.eq(expected, dir.glob('**/').sort());
346
+ });
347
+ }
348
+
349
+ exports["tests recursively matches any subdirectories including ./ and ../ with '.**/'"] = function() {
350
+ mockDirs(function(dir) {
351
+ var dir = dir.join("subdir_one");
352
+ assert.eq(['./','../'], dir.glob('.**/').sort());
353
+ });
354
+ }
355
+
356
+ exports["tests matches a single character except leading '.' with '?'"] = function() {
357
+ mockDirs(function(dir) {
358
+ assert.eq(['subdir_one'], dir.glob('?ubdir_one').sort());
359
+ });
360
+ }
361
+
362
+ exports["tests accepts multiple '?' characters in a pattern"] = function() {
363
+ mockDirs(function(dir) {
364
+ assert.eq(['subdir_one','subdir_two'], dir.glob('subdir_???').sort());
365
+ });
366
+ }
367
+
368
+ exports["tests matches any characters in a set with '[<characters>]'"] = function() {
369
+ mockDirs(function(dir) {
370
+ assert.eq(['subdir_one'], dir.glob('[stfu]ubdir_one').sort());
371
+ });
372
+ }
373
+
374
+ exports["tests matches any characters in a range with '[<character>-<character>]'"] = function() {
375
+ mockDirs(function(dir) {
376
+ assert.eq(['subdir_one'], dir.glob('[a-zA-Z]ubdir_one').sort());
377
+ });
378
+ }
379
+
380
+ exports["tests matches any characters except those in a set with '[^<characters>]'"] = function() {
381
+ mockDirs(function(dir) {
382
+ assert.eq(['subdir_one'], dir.glob('[^wtf]ubdir_one').sort());
383
+ });
384
+ }
385
+
386
+ exports["tests matches any characters except those in a range with '[^<character>-<character]'"] = function() {
387
+ mockDirs(function(dir) {
388
+ assert.eq(['subdir_one'], dir.glob('[^0-9]ubdir_one').sort());
389
+ });
390
+ }
391
+
392
+ exports["tests matches any one of the strings in a set with '{<string>,<other>,...}'"] = function() {
393
+ mockDirs(function(dir) {
394
+ assert.eq(["subdir_one", "subdir_two"], dir.glob('subdir_{one,two,three}').sort());
395
+ });
396
+ }
397
+
398
+ exports["tests accepts string sets with empty strings with {<string>,,<other>}"] = function() {
399
+ var expected = [
400
+ "deeply/nested/directory/structure/file_one.ext",
401
+ "deeply/nested/directory/structure/file_one"
402
+ ].sort();
403
+
404
+ mockDirs(function(dir) {
405
+ assert.eq(expected, dir.glob('deeply/nested/directory/structure/file_one{.ext,}').sort());
406
+ });
407
+ }
408
+
409
+ exports["tests matches dot or non-dotfiles with '{,.}*'"] = function() {
410
+ mockDirs(function(dir) {
411
+ assert.eq(expected_paths, dir.glob('{,.}*').sort());
412
+ });
413
+ }
414
+
415
+ exports["tests matches special characters by escaping with a backslash with '\\<character>'"] = function() {
416
+ mockDirs(function(dir) {
417
+ dir.join('foo^bar').mkdir();
418
+ assert.eq(["foo^bar"], dir.glob('foo?bar'));
419
+ assert.eq([], dir.glob('foo\\?bar'));
420
+ assert.eq(["nondotfile"], dir.glob('nond\\otfile'));
421
+ });
422
+ }
423
+
424
+ exports["tests recursively matches directories with '**/<characters>'"] = function() {
425
+ var expected = [
426
+ "deeply/nested/directory/structure/file_one",
427
+ "deeply/nested/directory/structure/file_one.ext",
428
+ "deeply/nondotfile",
429
+
430
+ "dir/filename_ordering",
431
+ "dir_filename_ordering",
432
+
433
+ "file_one.ext",
434
+ "file_two.ext",
435
+
436
+ "nondotfile",
437
+
438
+ "subdir_one/nondotfile",
439
+ "subdir_two/nondotfile",
440
+ "subdir_two/nondotfile.ext"
441
+ ]
442
+
443
+ mockDirs(function(dir) {
444
+ assert.eq(expected, dir.glob('**/*fil?{,.}*').sort());
445
+ });
446
+ }
447
+
448
+ exports["tests '**/*.ext'"] = function() {
449
+ // FIXME: exclude .dotfile?
450
+ var expected = [
451
+ "deeply/nested/.dotfile.ext",
452
+ "deeply/nested/directory/structure/.ext",
453
+ "deeply/nested/directory/structure/file_one.ext",
454
+ "file_one.ext",
455
+ "file_two.ext",
456
+ "subdir_two/nondotfile.ext"
457
+ ]
458
+
459
+ mockDirs(function(dir) {
460
+ assert.eq(expected, dir.glob('**/*.ext').sort());
461
+ });
462
+ }
463
+
464
+ if (require.main === module.id)
465
+ require("os").exit(require("test/runner").run(exports));
466
+