diff --git a/path/glob_test.ts b/path/glob_to_regexp_test.ts similarity index 82% rename from path/glob_test.ts rename to path/glob_to_regexp_test.ts index ac9b2ed63320..8281c6cb84bb 100644 --- a/path/glob_test.ts +++ b/path/glob_to_regexp_test.ts @@ -1,10 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals } from "../assert/mod.ts"; import { globToRegExp, GlobToRegExpOptions } from "./glob_to_regexp.ts"; -import { isGlob } from "./is_glob.ts"; -import { joinGlobs } from "./join_globs.ts"; -import { normalizeGlob } from "./normalize_glob.ts"; -import { SEP } from "./mod.ts"; function match( glob: string, @@ -523,118 +519,3 @@ Deno.test({ assertEquals("foo\\bar".match(pattern2)?.[0], "foo\\bar"); }, }); - -Deno.test({ - name: "isGlob()", - fn() { - // should be true if valid glob pattern - assert(isGlob("!foo.js")); - assert(isGlob("*.js")); - assert(isGlob("f?o.js")); - assert(isGlob("!*.js")); - assert(isGlob("!foo")); - assert(isGlob("!foo.js")); - assert(isGlob("**/abc.js")); - assert(isGlob("abc/*.js")); - assert(isGlob("@.(?:abc)")); - assert(isGlob("@.(?!abc)")); - - // should be false if invalid glob pattern - assert(!isGlob("")); - assert(!isGlob("~/abc")); - assert(!isGlob("~/abc")); - assert(!isGlob("~/(abc)")); - assert(!isGlob("+~(abc)")); - assert(!isGlob(".")); - assert(!isGlob("@.(abc)")); - assert(!isGlob("aa")); - assert(!isGlob("abc!/def/!ghi.js")); - assert(!isGlob("abc.js")); - assert(!isGlob("abc/def/!ghi.js")); - assert(!isGlob("abc/def/ghi.js")); - - // Should be true if path has regex capture group - assert(isGlob("abc/(?!foo).js")); - assert(isGlob("abc/(?:foo).js")); - assert(isGlob("abc/(?=foo).js")); - assert(isGlob("abc/(a|b).js")); - assert(isGlob("abc/(a|b|c).js")); - assert(isGlob("abc/(foo bar)/*.js")); - - // Should be false if the path has parens but is not a valid capture group - assert(!isGlob("abc/(a b c).js")); - assert(!isGlob("abc/(ab).js")); - assert(!isGlob("abc/(abc).js")); - assert(!isGlob("abc/(foo bar).js")); - - // should be false if the capture group is imbalanced - assert(!isGlob("abc/(ab.js")); - assert(!isGlob("abc/(a|b.js")); - assert(!isGlob("abc/(a|b|c.js")); - - // should be true if the path has a regex character class - assert(isGlob("abc/[abc].js")); - assert(isGlob("abc/[^abc].js")); - assert(isGlob("abc/[1-3].js")); - - // should be false if the character class is not balanced - assert(!isGlob("abc/[abc.js")); - assert(!isGlob("abc/[^abc.js")); - assert(!isGlob("abc/[1-3.js")); - - // should be false if the character class is escaped - assert(!isGlob("abc/\\[abc].js")); - assert(!isGlob("abc/\\[^abc].js")); - assert(!isGlob("abc/\\[1-3].js")); - - // should be true if the path has brace characters - assert(isGlob("abc/{a,b}.js")); - assert(isGlob("abc/{a..z}.js")); - assert(isGlob("abc/{a..z..2}.js")); - - // should be false if (basic) braces are not balanced - assert(!isGlob("abc/\\{a,b}.js")); - assert(!isGlob("abc/\\{a..z}.js")); - assert(!isGlob("abc/\\{a..z..2}.js")); - - // should be true if the path has regex characters - assert(isGlob("!&(abc)")); - assert(isGlob("!*.js")); - assert(isGlob("!foo")); - assert(isGlob("!foo.js")); - assert(isGlob("**/abc.js")); - assert(isGlob("*.js")); - assert(isGlob("*z(abc)")); - assert(isGlob("[1-10].js")); - assert(isGlob("[^abc].js")); - assert(isGlob("[a-j]*[^c]b/c")); - assert(isGlob("[abc].js")); - assert(isGlob("a/b/c/[a-z].js")); - assert(isGlob("abc/(aaa|bbb).js")); - assert(isGlob("abc/*.js")); - assert(isGlob("abc/{a,b}.js")); - assert(isGlob("abc/{a..z..2}.js")); - assert(isGlob("abc/{a..z}.js")); - - assert(!isGlob("$(abc)")); - assert(!isGlob("&(abc)")); - - // should be false if regex characters are escaped - assert(!isGlob("\\?.js")); - assert(!isGlob("\\[1-10\\].js")); - assert(!isGlob("\\[^abc\\].js")); - assert(!isGlob("\\[a-j\\]\\*\\[^c\\]b/c")); - assert(!isGlob("\\[abc\\].js")); - assert(!isGlob("\\a/b/c/\\[a-z\\].js")); - assert(!isGlob("abc/\\(aaa|bbb).js")); - assert(!isGlob("abc/\\?.js")); - }, -}); - -Deno.test("normalizeGlob() checks options.globstar", function () { - assertEquals(normalizeGlob(`**${SEP}..`, { globstar: true }), `**${SEP}..`); -}); - -Deno.test("joinGlobs() checks options.globstar", function () { - assertEquals(joinGlobs(["**", ".."], { globstar: true }), `**${SEP}..`); -}); diff --git a/path/is_glob_test.ts b/path/is_glob_test.ts new file mode 100644 index 000000000000..4e5b75b7747c --- /dev/null +++ b/path/is_glob_test.ts @@ -0,0 +1,110 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { assert } from "../assert/mod.ts"; +import { isGlob } from "./is_glob.ts"; + +Deno.test({ + name: "isGlob()", + fn() { + // should be true if valid glob pattern + assert(isGlob("!foo.js")); + assert(isGlob("*.js")); + assert(isGlob("f?o.js")); + assert(isGlob("!*.js")); + assert(isGlob("!foo")); + assert(isGlob("!foo.js")); + assert(isGlob("**/abc.js")); + assert(isGlob("abc/*.js")); + assert(isGlob("@.(?:abc)")); + assert(isGlob("@.(?!abc)")); + + // should be false if invalid glob pattern + assert(!isGlob("")); + assert(!isGlob("~/abc")); + assert(!isGlob("~/abc")); + assert(!isGlob("~/(abc)")); + assert(!isGlob("+~(abc)")); + assert(!isGlob(".")); + assert(!isGlob("@.(abc)")); + assert(!isGlob("aa")); + assert(!isGlob("abc!/def/!ghi.js")); + assert(!isGlob("abc.js")); + assert(!isGlob("abc/def/!ghi.js")); + assert(!isGlob("abc/def/ghi.js")); + + // Should be true if path has regex capture group + assert(isGlob("abc/(?!foo).js")); + assert(isGlob("abc/(?:foo).js")); + assert(isGlob("abc/(?=foo).js")); + assert(isGlob("abc/(a|b).js")); + assert(isGlob("abc/(a|b|c).js")); + assert(isGlob("abc/(foo bar)/*.js")); + + // Should be false if the path has parens but is not a valid capture group + assert(!isGlob("abc/(a b c).js")); + assert(!isGlob("abc/(ab).js")); + assert(!isGlob("abc/(abc).js")); + assert(!isGlob("abc/(foo bar).js")); + + // should be false if the capture group is imbalanced + assert(!isGlob("abc/(ab.js")); + assert(!isGlob("abc/(a|b.js")); + assert(!isGlob("abc/(a|b|c.js")); + + // should be true if the path has a regex character class + assert(isGlob("abc/[abc].js")); + assert(isGlob("abc/[^abc].js")); + assert(isGlob("abc/[1-3].js")); + + // should be false if the character class is not balanced + assert(!isGlob("abc/[abc.js")); + assert(!isGlob("abc/[^abc.js")); + assert(!isGlob("abc/[1-3.js")); + + // should be false if the character class is escaped + assert(!isGlob("abc/\\[abc].js")); + assert(!isGlob("abc/\\[^abc].js")); + assert(!isGlob("abc/\\[1-3].js")); + + // should be true if the path has brace characters + assert(isGlob("abc/{a,b}.js")); + assert(isGlob("abc/{a..z}.js")); + assert(isGlob("abc/{a..z..2}.js")); + + // should be false if (basic) braces are not balanced + assert(!isGlob("abc/\\{a,b}.js")); + assert(!isGlob("abc/\\{a..z}.js")); + assert(!isGlob("abc/\\{a..z..2}.js")); + + // should be true if the path has regex characters + assert(isGlob("!&(abc)")); + assert(isGlob("!*.js")); + assert(isGlob("!foo")); + assert(isGlob("!foo.js")); + assert(isGlob("**/abc.js")); + assert(isGlob("*.js")); + assert(isGlob("*z(abc)")); + assert(isGlob("[1-10].js")); + assert(isGlob("[^abc].js")); + assert(isGlob("[a-j]*[^c]b/c")); + assert(isGlob("[abc].js")); + assert(isGlob("a/b/c/[a-z].js")); + assert(isGlob("abc/(aaa|bbb).js")); + assert(isGlob("abc/*.js")); + assert(isGlob("abc/{a,b}.js")); + assert(isGlob("abc/{a..z..2}.js")); + assert(isGlob("abc/{a..z}.js")); + + assert(!isGlob("$(abc)")); + assert(!isGlob("&(abc)")); + + // should be false if regex characters are escaped + assert(!isGlob("\\?.js")); + assert(!isGlob("\\[1-10\\].js")); + assert(!isGlob("\\[^abc\\].js")); + assert(!isGlob("\\[a-j\\]\\*\\[^c\\]b/c")); + assert(!isGlob("\\[abc\\].js")); + assert(!isGlob("\\a/b/c/\\[a-z\\].js")); + assert(!isGlob("abc/\\(aaa|bbb).js")); + assert(!isGlob("abc/\\?.js")); + }, +}); diff --git a/path/join_globs_test.ts b/path/join_globs_test.ts new file mode 100644 index 000000000000..f6d6a068bbca --- /dev/null +++ b/path/join_globs_test.ts @@ -0,0 +1,8 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { assertEquals } from "../assert/mod.ts"; +import { joinGlobs } from "./join_globs.ts"; +import { SEP } from "./mod.ts"; + +Deno.test("joinGlobs() checks options.globstar", function () { + assertEquals(joinGlobs(["**", ".."], { globstar: true }), `**${SEP}..`); +}); diff --git a/path/normalize_glob_test.ts b/path/normalize_glob_test.ts new file mode 100644 index 000000000000..cba9df8c8dd6 --- /dev/null +++ b/path/normalize_glob_test.ts @@ -0,0 +1,8 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { assertEquals } from "../assert/mod.ts"; +import { normalizeGlob } from "./normalize_glob.ts"; +import { SEP } from "./mod.ts"; + +Deno.test("normalizeGlob() checks options.globstar", function () { + assertEquals(normalizeGlob(`**${SEP}..`, { globstar: true }), `**${SEP}..`); +});