2019-03-02 14:56:19 -05:00
|
|
|
// This file is ported from globrex@0.1.2
|
|
|
|
// MIT License
|
|
|
|
// Copyright (c) 2018 Terkel Gjervig Nielsen
|
2019-03-06 19:42:24 -05:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2020-05-09 08:34:47 -04:00
|
|
|
import { GlobrexOptions, globrex } from "./_globrex.ts";
|
2019-03-02 14:56:19 -05:00
|
|
|
|
2020-04-28 12:35:23 -04:00
|
|
|
const isWin = Deno.build.os === "windows";
|
2019-03-06 19:42:24 -05:00
|
|
|
const t = { equal: assertEquals, is: assertEquals };
|
2019-03-02 14:56:19 -05:00
|
|
|
|
2019-05-30 08:59:30 -04:00
|
|
|
function match(
|
|
|
|
glob: string,
|
|
|
|
strUnix: string,
|
|
|
|
strWin?: string | object,
|
2020-07-14 15:24:17 -04:00
|
|
|
opts: GlobrexOptions = {},
|
2019-05-30 08:59:30 -04:00
|
|
|
): boolean {
|
2019-03-02 14:56:19 -05:00
|
|
|
if (typeof strWin === "object") {
|
|
|
|
opts = strWin;
|
2019-05-30 08:59:30 -04:00
|
|
|
strWin = "";
|
2019-03-02 14:56:19 -05:00
|
|
|
}
|
2020-02-06 17:25:39 -05:00
|
|
|
const { regex } = globrex(glob, opts);
|
|
|
|
const match = (isWin && strWin ? strWin : strUnix).match(regex);
|
|
|
|
if (match && !regex.flags.includes("g")) {
|
|
|
|
assertEquals(match.length, 1);
|
|
|
|
}
|
|
|
|
return !!match;
|
2019-03-02 14:56:19 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: standard",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-10-05 12:02:34 -04:00
|
|
|
const res = globrex("*.js");
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(typeof globrex, "function", "constructor is a typeof function");
|
|
|
|
t.equal(res instanceof Object, true, "returns object");
|
|
|
|
t.equal(res.regex.toString(), "/^.*\\.js$/", "returns regex object");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: Standard * matching",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("*", "foo"), true, "match everything");
|
|
|
|
t.equal(match("*", "foo", { flags: "g" }), true, "match everything");
|
|
|
|
t.equal(match("f*", "foo"), true, "match the end");
|
|
|
|
t.equal(match("f*", "foo", { flags: "g" }), true, "match the end");
|
|
|
|
t.equal(match("*o", "foo"), true, "match the start");
|
|
|
|
t.equal(match("*o", "foo", { flags: "g" }), true, "match the start");
|
|
|
|
t.equal(match("u*orn", "unicorn"), true, "match the middle");
|
|
|
|
t.equal(
|
|
|
|
match("u*orn", "unicorn", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"match the middle",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("ico", "unicorn"), false, "do not match without g");
|
|
|
|
t.equal(
|
|
|
|
match("ico", "unicorn", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'match anywhere with RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("u*nicorn", "unicorn"), true, "match zero characters");
|
|
|
|
t.equal(
|
|
|
|
match("u*nicorn", "unicorn", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"match zero characters",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: advance * matching",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match("*.min.js", "http://example.com/jquery.min.js", {
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: false,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"complex match",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*.min.*", "http://example.com/jquery.min.js", { globstar: false }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"complex match",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*/js/*.js", "http://example.com/js/jquery.min.js", {
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: false,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"complex match",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*.min.*", "http://example.com/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"complex match global",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*.min.js", "http://example.com/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"complex match global",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*/js/*.js", "http://example.com/js/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"complex match global",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
const str = "\\/$^+?.()=!|{},[].*";
|
|
|
|
t.equal(match(str, str), true, "battle test complex string - strict");
|
|
|
|
t.equal(
|
|
|
|
match(str, str, { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
"battle test complex string - strict",
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
t.equal(
|
|
|
|
match(".min.", "http://example.com/jquery.min.js"),
|
|
|
|
false,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*.min.*", "http://example.com/jquery.min.js"),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(".min.", "http://example.com/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("http:", "http://example.com/jquery.min.js"),
|
|
|
|
false,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("http:*", "http://example.com/jquery.min.js"),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("http:", "http://example.com/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("min.js", "http://example.com/jquery.min.js"),
|
|
|
|
false,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*.min.js", "http://example.com/jquery.min.js"),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("min.js", "http://example.com/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'matches without/with using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("min", "http://example.com/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'match anywhere (globally) using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("/js/", "http://example.com/js/jquery.min.js", { flags: "g" }),
|
|
|
|
true,
|
2020-07-14 15:24:17 -04:00
|
|
|
'match anywhere (globally) using RegExp "g"',
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("/js*jq*.js", "http://example.com/js/jquery.min.js"), false);
|
|
|
|
t.equal(
|
|
|
|
match("/js*jq*.js", "http://example.com/js/jquery.min.js", {
|
2020-03-28 13:03:49 -04:00
|
|
|
flags: "g",
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: ? match one character, no more and no less",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("f?o", "foo", { extended: true }), true);
|
|
|
|
t.equal(match("f?o", "fooo", { extended: true }), false);
|
|
|
|
t.equal(match("f?oo", "foo", { extended: true }), false);
|
|
|
|
|
2019-05-30 08:59:30 -04:00
|
|
|
const tester = (globstar: boolean): void => {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match("f?o", "foo", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("f?o", "fooo", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("f?o?", "fooo", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
t.equal(
|
|
|
|
match("?fo", "fooo", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("f?oo", "foo", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("foo?", "foo", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
tester(true);
|
|
|
|
tester(false);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: [] match a character range",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("fo[oz]", "foo", { extended: true }), true);
|
|
|
|
t.equal(match("fo[oz]", "foz", { extended: true }), true);
|
|
|
|
t.equal(match("fo[oz]", "fog", { extended: true }), false);
|
|
|
|
t.equal(match("fo[a-z]", "fob", { extended: true }), true);
|
|
|
|
t.equal(match("fo[a-d]", "fot", { extended: true }), false);
|
|
|
|
t.equal(match("fo[!tz]", "fot", { extended: true }), false);
|
|
|
|
t.equal(match("fo[!tz]", "fob", { extended: true }), true);
|
|
|
|
|
2019-05-30 08:59:30 -04:00
|
|
|
const tester = (globstar: boolean): void => {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match("fo[oz]", "foo", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("fo[oz]", "foz", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("fo[oz]", "fog", { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
tester(true);
|
|
|
|
tester(false);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: [] extended character ranges",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match("[[:alnum:]]/bar.txt", "a/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@([[:alnum:]abc]|11)/bar.txt", "11/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@([[:alnum:]abc]|11)/bar.txt", "a/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@([[:alnum:]abc]|11)/bar.txt", "b/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@([[:alnum:]abc]|11)/bar.txt", "c/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@([[:alnum:]abc]|11)/bar.txt", "abc/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@([[:alnum:]abc]|11)/bar.txt", "3/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]]/bar.txt", "1/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]b]/bar.txt", "b/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[![:digit:]b]/bar.txt", "a/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:alnum:]]/bar.txt", "!/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]]/bar.txt", "a/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]b]/bar.txt", "a/bar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: {} match a choice of different substrings",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("foo{bar,baaz}", "foobaaz", { extended: true }), true);
|
|
|
|
t.equal(match("foo{bar,baaz}", "foobar", { extended: true }), true);
|
|
|
|
t.equal(match("foo{bar,baaz}", "foobuzz", { extended: true }), false);
|
|
|
|
t.equal(match("foo{bar,b*z}", "foobuzz", { extended: true }), true);
|
|
|
|
|
2019-05-30 08:59:30 -04:00
|
|
|
const tester = (globstar: boolean): void => {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match("foo{bar,baaz}", "foobaaz", {
|
|
|
|
extended: true,
|
|
|
|
globstar,
|
2020-03-28 13:03:49 -04:00
|
|
|
flag: "g",
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("foo{bar,baaz}", "foobar", {
|
|
|
|
extended: true,
|
|
|
|
globstar,
|
2020-03-28 13:03:49 -04:00
|
|
|
flag: "g",
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("foo{bar,baaz}", "foobuzz", {
|
|
|
|
extended: true,
|
|
|
|
globstar,
|
2020-03-28 13:03:49 -04:00
|
|
|
flag: "g",
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("foo{bar,b*z}", "foobuzz", {
|
|
|
|
extended: true,
|
|
|
|
globstar,
|
2020-03-28 13:03:49 -04:00
|
|
|
flag: "g",
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
tester(true);
|
|
|
|
tester(false);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: complex extended matches",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://foo.baaz.com/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://moz.buzz.com/index.html",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://moz.buzz.com/index.htm",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://moz.bar.com/index.html",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://flozz.buzz.com/index.html",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
|
2019-05-30 08:59:30 -04:00
|
|
|
const tester = (globstar: boolean): void => {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://foo.baaz.com/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true, globstar, flags: "g" },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://moz.buzz.com/index.html",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true, globstar, flags: "g" },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://moz.buzz.com/index.htm",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true, globstar, flags: "g" },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://moz.bar.com/index.html",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true, globstar, flags: "g" },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://?o[oz].b*z.com/{*.js,*.html}",
|
|
|
|
"http://flozz.buzz.com/index.html",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true, globstar, flags: "g" },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
tester(true);
|
|
|
|
tester(false);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: standard globstar",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-05-30 08:59:30 -04:00
|
|
|
const tester = (globstar: boolean): void => {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://foo.com/**/{*.js,*.html}",
|
|
|
|
"http://foo.com/bar/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true, globstar, flags: "g" },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://foo.com/**/{*.js,*.html}",
|
|
|
|
"http://foo.com/bar/baz/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ extended: true, globstar, flags: "g" },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("http://foo.com/**", "http://foo.com/bar/baz/jquery.min.js", {
|
|
|
|
extended: true,
|
|
|
|
globstar,
|
2020-03-28 13:03:49 -04:00
|
|
|
flags: "g",
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
tester(true);
|
|
|
|
tester(false);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: remaining chars should match themself",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-05-30 08:59:30 -04:00
|
|
|
const tester = (globstar: boolean): void => {
|
2019-03-02 14:56:19 -05:00
|
|
|
const testExtStr = "\\/$^+.()=!|,.*";
|
|
|
|
t.equal(match(testExtStr, testExtStr, { extended: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match(testExtStr, testExtStr, { extended: true, globstar, flags: "g" }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
tester(true);
|
|
|
|
tester(false);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: globstar advance testing",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("/foo/*", "/foo/bar.txt", { globstar: true }), true);
|
|
|
|
t.equal(match("/foo/**", "/foo/bar.txt", { globstar: true }), true);
|
|
|
|
t.equal(match("/foo/**", "/foo/bar/baz.txt", { globstar: true }), true);
|
|
|
|
t.equal(match("/foo/**", "/foo/bar/baz.txt", { globstar: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/*/*.txt", "/foo/bar/baz.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/**/*.txt", "/foo/bar/baz.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/**/*.txt", "/foo/bar/baz/qux.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("/foo/**/bar.txt", "/foo/bar.txt", { globstar: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/**/**/bar.txt", "/foo/bar.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/**/*/baz.txt", "/foo/bar/baz.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("/foo/**/*.txt", "/foo/bar.txt", { globstar: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/**/**/*.txt", "/foo/bar.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/**/*/*.txt", "/foo/bar/baz.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("**/*.txt", "/foo/bar/baz/qux.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("**/foo.txt", "foo.txt", { globstar: true }), true);
|
|
|
|
t.equal(match("**/*.txt", "foo.txt", { globstar: true }), true);
|
|
|
|
t.equal(match("/foo/*", "/foo/bar/baz.txt", { globstar: true }), false);
|
|
|
|
t.equal(match("/foo/*.txt", "/foo/bar/baz.txt", { globstar: true }), false);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/*/*.txt", "/foo/bar/baz/qux.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("/foo/*/bar.txt", "/foo/bar.txt", { globstar: true }), false);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/*/*/baz.txt", "/foo/bar/baz.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/**.txt", "/foo/bar/baz/qux.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("/foo/bar**/*.txt", "/foo/bar/baz/qux.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("/foo/bar**", "/foo/bar/baz.txt", { globstar: true }), false);
|
|
|
|
t.equal(
|
|
|
|
match("**/.txt", "/foo/bar/baz/qux.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*/*.txt", "/foo/bar/baz/qux.txt", { globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("*/*.txt", "foo.txt", { globstar: true }), false);
|
|
|
|
t.equal(
|
|
|
|
match("http://foo.com/*", "http://foo.com/bar/baz/jquery.min.js", {
|
|
|
|
extended: true,
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: true,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("http://foo.com/*", "http://foo.com/bar/baz/jquery.min.js", {
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: true,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("http://foo.com/*", "http://foo.com/bar/baz/jquery.min.js", {
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: false,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("http://foo.com/**", "http://foo.com/bar/baz/jquery.min.js", {
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: true,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://foo.com/*/*/jquery.min.js",
|
|
|
|
"http://foo.com/bar/baz/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ globstar: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://foo.com/**/jquery.min.js",
|
|
|
|
"http://foo.com/bar/baz/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ globstar: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://foo.com/*/*/jquery.min.js",
|
|
|
|
"http://foo.com/bar/baz/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ globstar: false },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://foo.com/*/jquery.min.js",
|
|
|
|
"http://foo.com/bar/baz/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ globstar: false },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match(
|
|
|
|
"http://foo.com/*/jquery.min.js",
|
|
|
|
"http://foo.com/bar/baz/jquery.min.js",
|
2020-07-14 15:24:17 -04:00
|
|
|
{ globstar: true },
|
2019-03-02 14:56:19 -05:00
|
|
|
),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: extended extglob ?",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("(foo).txt", "(foo).txt", { extended: true }), true);
|
|
|
|
t.equal(match("?(foo).txt", "foo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("?(foo).txt", ".txt", { extended: true }), true);
|
|
|
|
t.equal(match("?(foo|bar)baz.txt", "foobaz.txt", { extended: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba[zr]|qux)baz.txt", "bazbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba[zr]|qux)baz.txt", "barbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba[zr]|qux)baz.txt", "quxbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba[!zr]|qux)baz.txt", "batbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("?(ba*|qux)baz.txt", "batbaz.txt", { extended: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba*|qux)baz.txt", "batttbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("?(ba*|qux)baz.txt", "quxbaz.txt", { extended: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba?(z|r)|qux)baz.txt", "bazbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba?(z|?(r))|qux)baz.txt", "bazbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(match("?(foo).txt", "foo.txt", { extended: false }), false);
|
|
|
|
t.equal(
|
|
|
|
match("?(foo|bar)baz.txt", "foobarbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba[zr]|qux)baz.txt", "bazquxbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("?(ba[!zr]|qux)baz.txt", "bazbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: extended extglob *",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("*(foo).txt", "foo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*foo.txt", "bofoo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo).txt", "foofoo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo).txt", ".txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(fooo).txt", ".txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(fooo).txt", "foo.txt", { extended: true }), false);
|
|
|
|
t.equal(match("*(foo|bar).txt", "foobar.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo|bar).txt", "barbar.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo|bar).txt", "barfoobar.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo|bar).txt", ".txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo|ba[rt]).txt", "bat.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo|b*[rt]).txt", "blat.txt", { extended: true }), true);
|
|
|
|
t.equal(match("*(foo|b*[rt]).txt", "tlat.txt", { extended: true }), false);
|
|
|
|
t.equal(
|
|
|
|
match("*(*).txt", "whatever.txt", { extended: true, globstar: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*(foo|bar)/**/*.txt", "foo/hello/world/bar.txt", {
|
|
|
|
extended: true,
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: true,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("*(foo|bar)/**/*.txt", "foo/world/bar.txt", {
|
|
|
|
extended: true,
|
2020-03-28 13:03:49 -04:00
|
|
|
globstar: true,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: extended extglob +",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("+(foo).txt", "foo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("+foo.txt", "+foo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("+(foo).txt", ".txt", { extended: true }), false);
|
|
|
|
t.equal(match("+(foo|bar).txt", "foobar.txt", { extended: true }), true);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: extended extglob @",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("@(foo).txt", "foo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("@foo.txt", "@foo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("@(foo|baz)bar.txt", "foobar.txt", { extended: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("@(foo|baz)bar.txt", "foobazbar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@(foo|baz)bar.txt", "foofoobar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("@(foo|baz)bar.txt", "toofoobar.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: extended extglob !",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("!(boo).txt", "foo.txt", { extended: true }), true);
|
|
|
|
t.equal(match("!(foo|baz)bar.txt", "buzbar.txt", { extended: true }), true);
|
|
|
|
t.equal(match("!bar.txt", "!bar.txt", { extended: true }), true);
|
|
|
|
t.equal(
|
|
|
|
match("!({foo,bar})baz.txt", "notbaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("!({foo,bar})baz.txt", "foobaz.txt", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: strict",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(match("foo//bar.txt", "foo/bar.txt"), true);
|
|
|
|
t.equal(match("foo///bar.txt", "foo/bar.txt"), true);
|
|
|
|
t.equal(match("foo///bar.txt", "foo/bar.txt", { strict: true }), false);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-03-02 14:56:19 -05:00
|
|
|
name: "globrex: stress testing",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-02 14:56:19 -05:00
|
|
|
t.equal(
|
|
|
|
match("**/*/?yfile.{md,js,txt}", "foo/bar/baz/myfile.md", {
|
2020-03-28 13:03:49 -04:00
|
|
|
extended: true,
|
2019-03-02 14:56:19 -05:00
|
|
|
}),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("**/*/?yfile.{md,js,txt}", "foo/baz/myfile.md", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("**/*/?yfile.{md,js,txt}", "foo/baz/tyfile.js", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]_.]/file.js", "1/file.js", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]_.]/file.js", "2/file.js", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]_.]/file.js", "_/file.js", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]_.]/file.js", "./file.js", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
true,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
|
|
|
t.equal(
|
|
|
|
match("[[:digit:]_.]/file.js", "z/file.js", { extended: true }),
|
2020-07-14 15:24:17 -04:00
|
|
|
false,
|
2019-03-02 14:56:19 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-03-02 14:56:19 -05:00
|
|
|
});
|