summaryrefslogtreecommitdiff
path: root/std/fs/utils_test.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-10-09 17:10:09 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-10-09 17:10:09 -0400
commit151ce0266eb4de2c8fc600c81c192a5f791b6169 (patch)
tree7cb04016a1c7ee88adde83814548d7a9409dcde3 /std/fs/utils_test.ts
parenta355f7c807686918734416d91b79c26c21effba9 (diff)
Move everything into std subdir
Diffstat (limited to 'std/fs/utils_test.ts')
-rw-r--r--std/fs/utils_test.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/std/fs/utils_test.ts b/std/fs/utils_test.ts
new file mode 100644
index 000000000..5b33842ad
--- /dev/null
+++ b/std/fs/utils_test.ts
@@ -0,0 +1,64 @@
+// Copyright the Browserify authors. MIT License.
+
+import { test } from "../testing/mod.ts";
+import { assertEquals } from "../testing/asserts.ts";
+import { isSubdir, getFileInfoType, PathType } from "./utils.ts";
+import * as path from "./path/mod.ts";
+import { ensureFileSync } from "./ensure_file.ts";
+import { ensureDirSync } from "./ensure_dir.ts";
+
+const testdataDir = path.resolve("fs", "testdata");
+
+test(function _isSubdir(): void {
+ const pairs = [
+ ["", "", false, path.posix.sep],
+ ["/first/second", "/first", false, path.posix.sep],
+ ["/first", "/first", false, path.posix.sep],
+ ["/first", "/first/second", true, path.posix.sep],
+ ["first", "first/second", true, path.posix.sep],
+ ["../first", "../first/second", true, path.posix.sep],
+ ["c:\\first", "c:\\first", false, path.win32.sep],
+ ["c:\\first", "c:\\first\\second", true, path.win32.sep]
+ ];
+
+ pairs.forEach(function(p): void {
+ const src = p[0] as string;
+ const dest = p[1] as string;
+ const expected = p[2] as boolean;
+ const sep = p[3] as string;
+ assertEquals(
+ isSubdir(src, dest, sep),
+ expected,
+ `'${src}' should ${expected ? "" : "not"} be parent dir of '${dest}'`
+ );
+ });
+});
+
+test(function _getFileInfoType(): void {
+ const pairs = [
+ [path.join(testdataDir, "file_type_1"), "file"],
+ [path.join(testdataDir, "file_type_dir_1"), "dir"]
+ ];
+
+ pairs.forEach(function(p): void {
+ const filePath = p[0] as string;
+ const type = p[1] as PathType;
+ switch (type) {
+ case "file":
+ ensureFileSync(filePath);
+ break;
+ case "dir":
+ ensureDirSync(filePath);
+ break;
+ case "symlink":
+ // TODO(axetroy): test symlink
+ break;
+ }
+
+ const stat = Deno.statSync(filePath);
+
+ Deno.removeSync(filePath, { recursive: true });
+
+ assertEquals(getFileInfoType(stat), type);
+ });
+});