ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
76 lines (74 loc) • 4.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const os = require("os");
const utils_1 = require("./../../utils");
describe("FileUtils", () => {
describe("getAbsoluteOrRelativePathFromPath", () => {
const isWindows = os.platform() === "win32";
// too lazy to abstract this out because I'm pretty sure it works... my machine will get the windows tests and
// the CI linux machine will get the other tests
if (isWindows) {
// uses forward slashes in result because that's what the ts compiler does
it("should get the absolute path when absolute on windows", () => {
chai_1.expect(utils_1.FileUtils.getAbsoluteOrRelativePathFromPath("C:\\absolute\\path", "C:\\basedir")).to.equal("C:/absolute/path");
});
it("should get the relative path when relative on windows", () => {
chai_1.expect(utils_1.FileUtils.getAbsoluteOrRelativePathFromPath("relative\\path", "C:\\basedir")).to.equal("C:/basedir/relative/path");
});
it("should get the relative path without dots on windows", () => {
chai_1.expect(utils_1.FileUtils.getAbsoluteOrRelativePathFromPath("..\\relative\\path", "C:\\basedir")).to.equal("C:/relative/path");
});
}
else {
it("should get the absolute path when absolute on linux", () => {
chai_1.expect(utils_1.FileUtils.getAbsoluteOrRelativePathFromPath("/absolute/path", "/basedir")).to.equal("/absolute/path");
});
it("should get the relative path when relative on linux", () => {
chai_1.expect(utils_1.FileUtils.getAbsoluteOrRelativePathFromPath("relative/path", "/basedir")).to.equal("/basedir/relative/path");
});
it("should get the relative path without dots on linux", () => {
chai_1.expect(utils_1.FileUtils.getAbsoluteOrRelativePathFromPath("../relative/path", "/basedir")).to.equal("/relative/path");
});
}
});
describe("filePathMatches", () => {
it("should return false for a null path", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches(null, "test.ts")).to.be.false;
});
it("should return false for an empty path", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("", "test.ts")).to.be.false;
});
it("should return true when both are null", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches(null, null)).to.be.true;
});
it("should return true when both are empty", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("", "")).to.be.true;
});
it("should return false for empty search", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/tests.ts", "")).to.be.false;
});
it("should return false for null search", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/tests.ts", null)).to.be.false;
});
it("should return true for a file name only", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/test.ts", "test.ts")).to.be.true;
});
it("should return true for a file name and dir", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/test.ts", "dir/test.ts")).to.be.true;
});
it("should return true for a file name and dir with a slash at the front", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/test.ts", "/dir/test.ts")).to.be.true;
});
it("should return true for a full match", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/test.ts", "V:/dir/test.ts")).to.be.true;
});
it("should not error when the file path being searched for is longer", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/test.ts", "V:/dir/dir/test.ts")).to.be.false;
});
it("should return false when the directory name doesn't exactly match", () => {
chai_1.expect(utils_1.FileUtils.filePathMatches("V:/dir/test.ts", "ir/test.ts")).to.be.false;
});
});
});
//# sourceMappingURL=fileUtilsTests.js.map