import { describe, expect, test } from "vitest"; import { getFileFullName, getFileExt, getFileInfo, getFileNameWithoutExt, } from "../src/commons/file-util"; describe("file-util", () => { test("getFileFullName", () => { expect(getFileFullName("foo/aaaa.txt")).toBe("aaaa.txt"); expect(getFileFullName("foo/bar/aaaa.txt")).toBe("aaaa.txt"); expect(getFileFullName("aaaa.txt")).toBe("aaaa.txt"); expect(getFileFullName("foo/bar/aaaa")).toBe("aaaa"); }); test("getFileExt", () => { expect(getFileExt("foo/aaaa.txt")).toBe("txt"); expect(getFileExt("foo/bar/aaaa.txt")).toBe("txt"); expect(getFileExt("aaaa.txt")).toBe("txt"); expect(getFileExt("foo/bar/aaaa")).toBe(""); }); test("getFileInfo", () => { expect(getFileInfo("foo/aaaa.txt", "linux")).toEqual({ fileName: "aaaa.txt", fileNameNoExt: "aaaa", fileExtName: "txt", fullPath: "foo/aaaa.txt", pathOnly: "foo/", }); expect(getFileInfo("foo\\bar\\aaaa.txt", "win32")).toEqual({ fileName: "aaaa.txt", fileNameNoExt: "aaaa", fileExtName: "txt", fullPath: "foo\\bar\\aaaa.txt", pathOnly: "foo\\bar\\", }); expect(getFileInfo("foo/bar/aaaa", "linux")).toEqual({ fileName: "aaaa", fileNameNoExt: "aaaa", fileExtName: "", fullPath: "foo/bar/aaaa", pathOnly: "foo/bar/", }); expect(getFileInfo("foo\\bar\\aaaa", "win32")).toEqual({ fileName: "aaaa", fileNameNoExt: "aaaa", fileExtName: "", fullPath: "foo\\bar\\aaaa", pathOnly: "foo\\bar\\", }); }); });