import path from "path"; describe("path.matchesGlob(path, glob)", () => { const stringLikeObject = { toString() { return "hi"; }, }; it.each([ // line break null, undefined, 123, stringLikeObject, Symbol("hi"), ])("throws if `path` is not a string", (notAString: any) => { expect(() => path.matchesGlob(notAString, "*")).toThrow(TypeError); }); it.each([ // line break null, undefined, 123, stringLikeObject, Symbol("hi"), ])("throws if `glob` is not a string", (notAString: any) => { expect(() => path.matchesGlob("hi", notAString)).toThrow(TypeError); }); }); describe("path.posix.matchesGlob(path, glob)", () => { it.each([ // line break ["foo.js", "*.js"], ["foo.js", "*.[tj]s"], ["foo.ts", "*.[tj]s"], ["foo.js", "**/*.js"], ["src/bar/foo.js", "**/*.js"], ["foo/bar/baz", "foo/[bcr]ar/baz"], ])("path '%s' matches pattern '%s'", (pathname, glob) => { expect(path.posix.matchesGlob(pathname, glob)).toBeTrue(); }); it.each([ // line break ["foo.js", "*.ts"], ["src/foo.js", "*.js"], ["foo.js", "src/*.js"], ["foo/bar", "*"], ])("path '%s' does not match pattern '%s'", (pathname, glob) => { expect(path.posix.matchesGlob(pathname, glob)).toBeFalse(); }); }); describe("path.win32.matchesGlob(path, glob)", () => { it.each([ // line break ["foo.js", "*.js"], ["foo.js", "*.[tj]s"], ["foo.ts", "*.[tj]s"], ["foo.js", "**\\*.js"], ["src\\bar\\foo.js", "**\\*.js"], ["src\\bar\\foo.js", "**/*.js"], ["foo\\bar\\baz", "foo\\[bcr]ar\\baz"], ["foo\\bar\\baz", "foo/[bcr]ar/baz"], ])("path '%s' matches gattern '%s'", (pathname, glob) => { expect(path.win32.matchesGlob(pathname, glob)).toBeTrue(); }); it.each([ // line break ["foo.js", "*.ts"], ["foo.js", "src\\*.js"], ["foo/bar", "*"], ])("path '%s' does not match pattern '%s'", (pathname, glob) => { expect(path.win32.matchesGlob(pathname, glob)).toBeFalse(); }); });