sproutit-narwhal 0.1.106
Sign up to get free protection for your applications and to get access to all the features.
- data/DISTRIBUTION.yml +15 -0
- data/README.md +86 -0
- data/Rakefile +349 -0
- data/VERSION.yml +7 -0
- data/bin/activate +50 -0
- data/bin/activate.bash +50 -0
- data/bin/activate.cmd +3 -0
- data/bin/js +67 -0
- data/bin/json +2 -0
- data/bin/narwhal +67 -0
- data/bin/narwhal.cmd +29 -0
- data/bin/sea +45 -0
- data/bin/sea.cmd +25 -0
- data/bin/tusk +2 -0
- data/bin/tusk.cmd +5 -0
- data/catalog.json +902 -0
- data/docs/available-packages.md +32 -0
- data/docs/browser-api-plan.md +290 -0
- data/docs/browser-api.md +153 -0
- data/docs/download.md +25 -0
- data/docs/engines.md +32 -0
- data/docs/json-tool.md +121 -0
- data/docs/lib/binary.wiki +242 -0
- data/docs/lib/file.wiki +325 -0
- data/docs/lib/os/popen.md +70 -0
- data/docs/modules.md +38 -0
- data/docs/narwhal.md +487 -0
- data/docs/packages-howto.md +32 -0
- data/docs/packages.md +30 -0
- data/docs/posts/2009-07-29-hello-0.1.md +19 -0
- data/docs/quick-start.md +69 -0
- data/docs/sea.md +49 -0
- data/engines/browser/lib/binary.js +2 -0
- data/engines/browser/lib/reactor.js +21 -0
- data/engines/browser/lib/system.js +3 -0
- data/engines/default/lib/array.js +164 -0
- data/engines/default/lib/binary-engine.js +53 -0
- data/engines/default/lib/binary.js +755 -0
- data/engines/default/lib/date.js +8 -0
- data/engines/default/lib/file-engine.js +119 -0
- data/engines/default/lib/function.js +119 -0
- data/engines/default/lib/global.js +11 -0
- data/engines/default/lib/io-engine.js +26 -0
- data/engines/default/lib/json.js +488 -0
- data/engines/default/lib/object.js +69 -0
- data/engines/default/lib/os-engine.js +3 -0
- data/engines/default/lib/reactor.js +12 -0
- data/engines/default/lib/string.js +84 -0
- data/engines/default/lib/system.js +20 -0
- data/engines/default/lib/worker.js +133 -0
- data/engines/jsc/README.md +18 -0
- data/engines/jsc/bootstrap.js +53 -0
- data/engines/jsc/deps/http-parser/LICENSE +77 -0
- data/engines/jsc/deps/http-parser/README.md +145 -0
- data/engines/jsc/deps/http-parser/http_parser.c +6087 -0
- data/engines/jsc/deps/http-parser/http_parser.h +141 -0
- data/engines/jsc/deps/http-parser/http_parser.rl +500 -0
- data/engines/jsc/deps/http-parser/test.c +858 -0
- data/engines/jsc/include/binary-engine.h +11 -0
- data/engines/jsc/include/io-engine.h +23 -0
- data/engines/jsc/include/narwhal.h +427 -0
- data/engines/jsc/lib/file-engine.js +31 -0
- data/engines/jsc/lib/http.js +1 -0
- data/engines/jsc/lib/io-engine.js +202 -0
- data/engines/jsc/lib/os-engine.js +25 -0
- data/engines/jsc/lib/system.js +18 -0
- data/engines/jsc/lib/zip.js +1 -0
- data/engines/jsc/narwhal-jsc.c +273 -0
- data/engines/jsc/narwhal.c +29 -0
- data/engines/jsc/package.json +8 -0
- data/engines/jsc/src/binary-engine.cc +290 -0
- data/engines/jsc/src/file-engine.cc +405 -0
- data/engines/jsc/src/io-engine.cc +423 -0
- data/engines/jsc/src/jack/handler/jill.cc +710 -0
- data/engines/jsc/src/os-engine.cc +210 -0
- data/engines/rhino/bin/narwhal-rhino +68 -0
- data/engines/rhino/bin/narwhal-rhino.cmd +34 -0
- data/engines/rhino/bootstrap.js +119 -0
- data/engines/rhino/jars/jline.jar +0 -0
- data/engines/rhino/jars/jna.jar +0 -0
- data/engines/rhino/jars/js.jar +0 -0
- data/engines/rhino/lib/binary-engine.js +83 -0
- data/engines/rhino/lib/concurrency.js +6 -0
- data/engines/rhino/lib/event-queue.js +18 -0
- data/engines/rhino/lib/file-engine.js +216 -0
- data/engines/rhino/lib/http-client-engine.js +90 -0
- data/engines/rhino/lib/http-engine.js +10 -0
- data/engines/rhino/lib/io-engine.js +347 -0
- data/engines/rhino/lib/md5-engine.js +40 -0
- data/engines/rhino/lib/os-engine.js +150 -0
- data/engines/rhino/lib/packages-engine.js +71 -0
- data/engines/rhino/lib/sandbox-engine.js +70 -0
- data/engines/rhino/lib/system.js +38 -0
- data/engines/rhino/lib/worker-engine.js +23 -0
- data/engines/rhino/lib/zip.js +78 -0
- data/engines/rhino/package.json +4 -0
- data/engines/secure/lib/file.js +6 -0
- data/engines/secure/lib/system.js +6 -0
- data/engines/template/bin/narwhal-engine-name +32 -0
- data/engines/template/bootstrap.js +40 -0
- data/engines/template/lib/file-engine.js +118 -0
- data/engines/template/lib/system.js +17 -0
- data/examples/browser-deployment-jackconfig.js +35 -0
- data/examples/fibonacci-worker.js +35 -0
- data/examples/fibonacci.js +19 -0
- data/examples/hello +2 -0
- data/examples/narwhal +3 -0
- data/examples/not-quite-a-quine.js +1 -0
- data/extconf.rb +44 -0
- data/gem_bin/narwhal +5 -0
- data/gem_bin/sea +4 -0
- data/gem_bin/tusk +4 -0
- data/lib/args.js +849 -0
- data/lib/base16.js +16 -0
- data/lib/base64.js +120 -0
- data/lib/codec/base64.js +8 -0
- data/lib/crc32.js +60 -0
- data/lib/file-bootstrap.js +187 -0
- data/lib/file.js +659 -0
- data/lib/hash.js +28 -0
- data/lib/hashp.js +65 -0
- data/lib/html.js +16 -0
- data/lib/http-client.js +134 -0
- data/lib/http.js +17 -0
- data/lib/io.js +98 -0
- data/lib/jsmin.js +315 -0
- data/lib/jsonpath.js +89 -0
- data/lib/logger.js +55 -0
- data/lib/md4.js +146 -0
- data/lib/md5.js +164 -0
- data/lib/mime.js +166 -0
- data/lib/narwhal.js +102 -0
- data/lib/narwhal/client.js +261 -0
- data/lib/narwhal/compile.js +99 -0
- data/lib/narwhal/env.js +140 -0
- data/lib/narwhal/inline.js +106 -0
- data/lib/narwhal/json.js +324 -0
- data/lib/narwhal/json.md +178 -0
- data/lib/narwhal/repl.js +96 -0
- data/lib/narwhal/server-test.js +6 -0
- data/lib/narwhal/server.js +270 -0
- data/lib/narwhal/tusk.js +170 -0
- data/lib/narwhal/tusk/bin.js +13 -0
- data/lib/narwhal/tusk/bundle.js +0 -0
- data/lib/narwhal/tusk/catalog.js +22 -0
- data/lib/narwhal/tusk/clone.js +66 -0
- data/lib/narwhal/tusk/consolidate.js +25 -0
- data/lib/narwhal/tusk/create-catalog.js +80 -0
- data/lib/narwhal/tusk/engine.js +42 -0
- data/lib/narwhal/tusk/freeze.js +0 -0
- data/lib/narwhal/tusk/init.js +56 -0
- data/lib/narwhal/tusk/install.js +288 -0
- data/lib/narwhal/tusk/list.js +20 -0
- data/lib/narwhal/tusk/orphans.js +0 -0
- data/lib/narwhal/tusk/reheat.js +15 -0
- data/lib/narwhal/tusk/remove.js +15 -0
- data/lib/narwhal/tusk/search.js +145 -0
- data/lib/narwhal/tusk/update.js +21 -0
- data/lib/narwhal/tusk/upgrade.js +0 -0
- data/lib/os.js +33 -0
- data/lib/packages.js +423 -0
- data/lib/printf.js +169 -0
- data/lib/promise.js +352 -0
- data/lib/querystring.js +176 -0
- data/lib/ref-send.js +257 -0
- data/lib/regexp.js +12 -0
- data/lib/sandbox.js +422 -0
- data/lib/sha.js +112 -0
- data/lib/sha256.js +102 -0
- data/lib/struct.js +228 -0
- data/lib/term.js +179 -0
- data/lib/test/assert.js +95 -0
- data/lib/test/equiv.js +188 -0
- data/lib/test/jsdump.js +165 -0
- data/lib/test/runner.js +129 -0
- data/lib/unload.js +13 -0
- data/lib/uri.js +378 -0
- data/lib/url.js +5 -0
- data/lib/utf8.js +64 -0
- data/lib/util.js +985 -0
- data/lib/uuid.js +89 -0
- data/lib/xregexp.js +521 -0
- data/local.json.template +1 -0
- data/narwhal.gemspec +105 -0
- data/narwhal.js +213 -0
- data/package.json +26 -0
- data/packages/readline/engines/default/lib/readline.js +4 -0
- data/packages/readline/engines/rhino/lib/readline.js +6 -0
- data/packages/readline/package.json +5 -0
- data/sources.json +207 -0
- data/tests/all-tests.js +17 -0
- data/tests/args.js +31 -0
- data/tests/args/domain.js +215 -0
- data/tests/args/options.js +36 -0
- data/tests/args/shifting.js +92 -0
- data/tests/args/validation.js +31 -0
- data/tests/base64.js +23 -0
- data/tests/commonjs.js +3 -0
- data/tests/commonjs/all-tests.js +12 -0
- data/tests/commonjs/bytearray-encodings-tests.js +69 -0
- data/tests/commonjs/bytearray-tests.js +465 -0
- data/tests/commonjs/bytestring-encodings-tests.js +89 -0
- data/tests/commonjs/bytestring-tests.js +263 -0
- data/tests/commonjs/es5/all-tests.js +3 -0
- data/tests/commonjs/es5/bind.js +29 -0
- data/tests/commonjs/file-tests.js +315 -0
- data/tests/commonjs/file/dirname.js +31 -0
- data/tests/commonjs/file/extension.js +45 -0
- data/tests/commonjs/file/is-absolute.js +11 -0
- data/tests/commonjs/file/iterator.js +101 -0
- data/tests/commonjs/file/normal.js +27 -0
- data/tests/commonjs/file/path.js +17 -0
- data/tests/commonjs/file/relative.js +42 -0
- data/tests/commonjs/file/resolve.js +44 -0
- data/tests/commonjs/module-tests.js +9 -0
- data/tests/commonjs/modules/absolute/b.js +1 -0
- data/tests/commonjs/modules/absolute/program.js +5 -0
- data/tests/commonjs/modules/absolute/submodule/a.js +3 -0
- data/tests/commonjs/modules/absolute/test.js +9 -0
- data/tests/commonjs/modules/all-tests.js +47 -0
- data/tests/commonjs/modules/config.js +11 -0
- data/tests/commonjs/modules/cyclic/a.js +4 -0
- data/tests/commonjs/modules/cyclic/b.js +4 -0
- data/tests/commonjs/modules/cyclic/program.js +10 -0
- data/tests/commonjs/modules/cyclic/test.js +9 -0
- data/tests/commonjs/modules/determinism/program.js +3 -0
- data/tests/commonjs/modules/determinism/submodule/a.js +8 -0
- data/tests/commonjs/modules/determinism/submodule/b.js +2 -0
- data/tests/commonjs/modules/determinism/test.js +9 -0
- data/tests/commonjs/modules/exactExports/a.js +3 -0
- data/tests/commonjs/modules/exactExports/program.js +4 -0
- data/tests/commonjs/modules/exactExports/test.js +9 -0
- data/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js +0 -0
- data/tests/commonjs/modules/hasOwnProperty/program.js +3 -0
- data/tests/commonjs/modules/hasOwnProperty/test.js +9 -0
- data/tests/commonjs/modules/hasOwnProperty/toString.js +0 -0
- data/tests/commonjs/modules/method/a.js +12 -0
- data/tests/commonjs/modules/method/program.js +8 -0
- data/tests/commonjs/modules/method/test.js +9 -0
- data/tests/commonjs/modules/missing/program.js +8 -0
- data/tests/commonjs/modules/missing/test.js +9 -0
- data/tests/commonjs/modules/monkeys/a.js +1 -0
- data/tests/commonjs/modules/monkeys/program.js +4 -0
- data/tests/commonjs/modules/monkeys/test.js +9 -0
- data/tests/commonjs/modules/nested/a/b/c/d.js +3 -0
- data/tests/commonjs/modules/nested/program.js +3 -0
- data/tests/commonjs/modules/nested/test.js +9 -0
- data/tests/commonjs/modules/relative/program.js +5 -0
- data/tests/commonjs/modules/relative/submodule/a.js +1 -0
- data/tests/commonjs/modules/relative/submodule/b.js +2 -0
- data/tests/commonjs/modules/relative/test.js +9 -0
- data/tests/commonjs/modules/transitive/a.js +1 -0
- data/tests/commonjs/modules/transitive/b.js +1 -0
- data/tests/commonjs/modules/transitive/c.js +3 -0
- data/tests/commonjs/modules/transitive/program.js +3 -0
- data/tests/commonjs/modules/transitive/test.js +9 -0
- data/tests/file/all-tests.js +61 -0
- data/tests/file/fnmatch.js +102 -0
- data/tests/file/glob.js +466 -0
- data/tests/file/match.js +102 -0
- data/tests/global.js +6 -0
- data/tests/global/array.js +19 -0
- data/tests/hashes.js +94 -0
- data/tests/html.js +13 -0
- data/tests/io/stringio.js +21 -0
- data/tests/os/all-tests.js +4 -0
- data/tests/os/popen.js +41 -0
- data/tests/os/system.js +22 -0
- data/tests/printf.js +123 -0
- data/tests/query-string.js +87 -0
- data/tests/sandbox/byte-io.js +20 -0
- data/tests/sandbox/fileName.js +3 -0
- data/tests/sandbox/foo.js +0 -0
- data/tests/sandbox/reload.js +79 -0
- data/tests/string.js +35 -0
- data/tests/uri.js +41 -0
- data/tests/util/all-tests.js +79 -0
- data/tests/util/array.js +207 -0
- data/tests/util/array/is-arguments.js +29 -0
- data/tests/util/array/is-array-like.js +29 -0
- data/tests/util/case.js +9 -0
- data/tests/util/collection.js +104 -0
- data/tests/util/eq.js +57 -0
- data/tests/util/expand.js +45 -0
- data/tests/util/object.js +125 -0
- data/tests/util/operator.js +25 -0
- data/tests/util/range.js +19 -0
- data/tests/util/repr.js +26 -0
- data/tests/util/string.js +34 -0
- data/tests/util/unique.js +12 -0
- 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,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
|
+
|