summaryrefslogtreecommitdiff
path: root/fs/utils_test.ts
diff options
context:
space:
mode:
authorAxetroy <troy450409405@gmail.com>2019-03-18 00:34:55 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-03-17 12:34:55 -0400
commit942df0be0d8bb37862195c438017df7746b0f3f0 (patch)
tree8d52e754c60944c7cc4fc825558b5f6d64deadc0 /fs/utils_test.ts
parent8acdecd72da494044065cb0615d9db3ce0a39a1c (diff)
extract internal method isSubdir to fs/utils.ts (denoland/deno_std#285)
Original: https://github.com/denoland/deno_std/commit/da4abcd9a3a5775939c3941a884d1c6f4d287d0f
Diffstat (limited to 'fs/utils_test.ts')
-rw-r--r--fs/utils_test.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/fs/utils_test.ts b/fs/utils_test.ts
new file mode 100644
index 000000000..9d6959de5
--- /dev/null
+++ b/fs/utils_test.ts
@@ -0,0 +1,31 @@
+// Copyright the Browserify authors. MIT License.
+
+import { test } from "../testing/mod.ts";
+import { assertEquals } from "../testing/asserts.ts";
+import { isSubdir } from "./utils.ts";
+import * as path from "./path/mod.ts";
+
+test(function _isSubdir() {
+ 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) {
+ 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}'`
+ );
+ });
+});