2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-12-21 07:39:51 +00:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
|
|
|
import { SEPARATOR as SEP_POSIX } from "@std/path/posix/constants";
|
|
|
|
import { SEPARATOR as SEP_WIN32 } from "@std/path/windows/constants";
|
2023-12-21 07:39:51 +00:00
|
|
|
import { isSubdir } from "./_is_subdir.ts";
|
|
|
|
|
|
|
|
Deno.test("isSubdir() returns a boolean indicating if dir is a subdir", function () {
|
|
|
|
const pairs = [
|
|
|
|
["", "", false, SEP_POSIX],
|
2024-06-18 21:50:14 +00:00
|
|
|
[".", "", false, SEP_POSIX],
|
2023-12-21 07:39:51 +00:00
|
|
|
["/first/second", "/first", false, SEP_POSIX],
|
|
|
|
["/first", "/first", false, SEP_POSIX],
|
|
|
|
["/first", "/first/second", true, SEP_POSIX],
|
|
|
|
["first", "first/second", true, SEP_POSIX],
|
|
|
|
["../first", "../first/second", true, SEP_POSIX],
|
|
|
|
["c:\\first", "c:\\first", false, SEP_WIN32],
|
|
|
|
["c:\\first", "c:\\first\\second", true, SEP_WIN32],
|
2024-01-18 05:54:39 +00:00
|
|
|
] as const;
|
2023-12-21 07:39:51 +00:00
|
|
|
|
2024-01-18 05:54:39 +00:00
|
|
|
pairs.forEach(function ([src, dest, expected, sep]) {
|
2023-12-21 07:39:51 +00:00
|
|
|
assertEquals(
|
|
|
|
isSubdir(src, dest, sep),
|
|
|
|
expected,
|
|
|
|
`'${src}' should ${expected ? "" : "not"} be parent dir of '${dest}'`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|