2024-04-26 19:28:39 +00:00
|
|
|
|
import { strict as assert } from "assert";
|
2021-12-11 14:45:21 +00:00
|
|
|
|
import { JSDOM } from "jsdom";
|
2021-11-07 05:58:51 +00:00
|
|
|
|
import * as misc from "../src/misc";
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:13:40 +00:00
|
|
|
|
describe("Misc: hidden file", () => {
|
2021-11-07 04:14:14 +00:00
|
|
|
|
it("should find hidden file correctly", () => {
|
2021-11-07 05:58:51 +00:00
|
|
|
|
let item = "";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.isHiddenPath(item));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = ".";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.isHiddenPath(item));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = "..";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.isHiddenPath(item));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = "/x/y/z/../././../a/b/c";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.isHiddenPath(item));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = ".hidden";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(misc.isHiddenPath(item));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = "_hidden_loose";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(misc.isHiddenPath(item));
|
|
|
|
|
assert.ok(!misc.isHiddenPath(item, true, false));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = "/sdd/_hidden_loose";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(misc.isHiddenPath(item));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = "what/../_hidden_loose/what/what/what";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(misc.isHiddenPath(item));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = "what/../_hidden_loose/what/what/what";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.isHiddenPath(item, true, false));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
|
2021-11-07 05:58:51 +00:00
|
|
|
|
item = "what/../_hidden_loose/../.hidden/what/what/what";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(misc.isHiddenPath(item, true, false));
|
2022-03-13 14:42:16 +00:00
|
|
|
|
|
|
|
|
|
item = "what/../_hidden_loose/../.hidden/what/what/what";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.isHiddenPath(item, false, true));
|
2022-03-13 14:42:16 +00:00
|
|
|
|
|
|
|
|
|
item = "what/_hidden_loose/what/what/what";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(misc.isHiddenPath(item, false, true));
|
|
|
|
|
assert.ok(!misc.isHiddenPath(item, true, false));
|
2022-03-13 14:42:16 +00:00
|
|
|
|
|
|
|
|
|
item = "what/.hidden/what/what/what";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.isHiddenPath(item, false, true));
|
|
|
|
|
assert.ok(misc.isHiddenPath(item, true, false));
|
2021-11-07 04:14:14 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2021-11-07 05:58:51 +00:00
|
|
|
|
|
|
|
|
|
describe("Misc: get folder levels", () => {
|
|
|
|
|
it("should ignore empty path", () => {
|
|
|
|
|
const item = "";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.getFolderLevels(item).length, 0);
|
2021-11-07 05:58:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should ignore single file", () => {
|
|
|
|
|
const item = "xxx";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.getFolderLevels(item).length, 0);
|
2021-11-07 05:58:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should detect path ending with /", () => {
|
|
|
|
|
const item = "xxx/";
|
|
|
|
|
const res = ["xxx"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item), res);
|
2021-11-07 05:58:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should correctly split folders and files", () => {
|
|
|
|
|
const item = "xxx/yyy/zzz.md";
|
|
|
|
|
const res = ["xxx", "xxx/yyy"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item), res);
|
2021-11-07 05:58:51 +00:00
|
|
|
|
|
|
|
|
|
const item2 = "xxx/yyy/zzz";
|
|
|
|
|
const res2 = ["xxx", "xxx/yyy"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item2), res2);
|
2021-11-07 05:58:51 +00:00
|
|
|
|
|
|
|
|
|
const item3 = "xxx/yyy/zzz/";
|
|
|
|
|
const res3 = ["xxx", "xxx/yyy", "xxx/yyy/zzz"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item3), res3);
|
2021-11-07 05:58:51 +00:00
|
|
|
|
});
|
2021-11-28 02:45:46 +00:00
|
|
|
|
|
2022-02-27 09:54:31 +00:00
|
|
|
|
it("should correctly add ending slash if required", () => {
|
|
|
|
|
const item = "xxx/yyy/zzz.md";
|
|
|
|
|
const res = ["xxx/", "xxx/yyy/"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item, true), res);
|
2022-02-27 09:54:31 +00:00
|
|
|
|
|
|
|
|
|
const item2 = "xxx/yyy/zzz";
|
|
|
|
|
const res2 = ["xxx/", "xxx/yyy/"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item2, true), res2);
|
2022-02-27 09:54:31 +00:00
|
|
|
|
|
|
|
|
|
const item3 = "xxx/yyy/zzz/";
|
|
|
|
|
const res3 = ["xxx/", "xxx/yyy/", "xxx/yyy/zzz/"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item3, true), res3);
|
2022-02-27 09:54:31 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-11-28 04:18:44 +00:00
|
|
|
|
it("should treat path starting with / correctly", () => {
|
2021-11-28 02:45:46 +00:00
|
|
|
|
const item = "/xxx/yyy/zzz.md";
|
|
|
|
|
const res = ["/xxx", "/xxx/yyy"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item), res);
|
2021-11-28 02:45:46 +00:00
|
|
|
|
|
|
|
|
|
const item2 = "/xxx/yyy/zzz";
|
|
|
|
|
const res2 = ["/xxx", "/xxx/yyy"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item2), res2);
|
2021-11-28 02:45:46 +00:00
|
|
|
|
|
|
|
|
|
const item3 = "/xxx/yyy/zzz/";
|
|
|
|
|
const res3 = ["/xxx", "/xxx/yyy", "/xxx/yyy/zzz"];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item3), res3);
|
2021-11-28 02:45:46 +00:00
|
|
|
|
|
|
|
|
|
const item4 = "/xxx";
|
|
|
|
|
const res4 = [] as string[];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item4), res4);
|
2021-11-28 02:45:46 +00:00
|
|
|
|
|
|
|
|
|
const item5 = "/";
|
|
|
|
|
const res5 = [] as string[];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.getFolderLevels(item5), res5);
|
2021-11-28 02:45:46 +00:00
|
|
|
|
});
|
2021-11-07 05:58:51 +00:00
|
|
|
|
});
|
2021-11-09 02:00:44 +00:00
|
|
|
|
|
2022-02-27 09:54:31 +00:00
|
|
|
|
describe("Misc: get parent folder", () => {
|
|
|
|
|
it("should treat empty path correctly", () => {
|
|
|
|
|
const item = "";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.getParentFolder(item), "/");
|
2022-02-27 09:54:31 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should treat one level path correctly", () => {
|
|
|
|
|
let item = "abc/";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.getParentFolder(item), "/");
|
2022-02-27 09:54:31 +00:00
|
|
|
|
item = "/efg/";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.getParentFolder(item), "/");
|
2022-02-27 09:54:31 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should treat more levels path correctly", () => {
|
|
|
|
|
let item = "abc/efg";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.getParentFolder(item), "abc/");
|
2022-02-27 09:54:31 +00:00
|
|
|
|
item = "/hij/klm/";
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.getParentFolder(item), "/hij/");
|
2022-02-27 09:54:31 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-09 02:00:44 +00:00
|
|
|
|
describe("Misc: vaild file name tests", () => {
|
|
|
|
|
it("should treat no ascii correctly", async () => {
|
|
|
|
|
const x = misc.isVaildText("😄🍎 apple 苹果");
|
|
|
|
|
// console.log(x)
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(x);
|
2021-11-09 02:00:44 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should find not-printable chars correctly", async () => {
|
|
|
|
|
const x = misc.isVaildText("😄🍎 apple 苹果\u0000");
|
|
|
|
|
// console.log(x)
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!x);
|
2021-11-09 02:00:44 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should allow spaces/slashes/...", async () => {
|
|
|
|
|
const x = misc.isVaildText("😄🍎 apple 苹果/-_=/\\*%^&@#$`");
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(x);
|
2021-11-09 02:00:44 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2021-11-21 07:31:20 +00:00
|
|
|
|
|
|
|
|
|
describe("Misc: get dirname", () => {
|
|
|
|
|
it("should return itself for folder", async () => {
|
|
|
|
|
const x = misc.getPathFolder("ssss/");
|
|
|
|
|
// console.log(x)
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(x, "ssss/");
|
2021-11-21 07:31:20 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return folder for file", async () => {
|
|
|
|
|
const x = misc.getPathFolder("sss/yyy");
|
|
|
|
|
// console.log(x)
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(x, "sss/");
|
2021-11-21 07:31:20 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should treat / specially", async () => {
|
|
|
|
|
const x = misc.getPathFolder("/");
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(x, "/");
|
2021-11-21 07:31:20 +00:00
|
|
|
|
|
|
|
|
|
const y = misc.getPathFolder("/abc");
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(y, "/");
|
2021-11-21 07:31:20 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2021-12-11 14:45:21 +00:00
|
|
|
|
|
|
|
|
|
describe("Misc: extract svg", () => {
|
2024-05-07 16:20:15 +00:00
|
|
|
|
beforeEach(() => {
|
2021-12-11 14:45:21 +00:00
|
|
|
|
const fakeBrowser = new JSDOM("");
|
|
|
|
|
global.window = fakeBrowser.window as any;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should extract rect from svg correctly", () => {
|
|
|
|
|
const x = "<svg><rect/><g/></svg>";
|
|
|
|
|
const y = misc.extractSvgSub(x);
|
|
|
|
|
// console.log(x)
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(y, "<rect/><g/>");
|
2021-12-11 14:45:21 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2022-03-10 15:54:35 +00:00
|
|
|
|
|
|
|
|
|
describe("Misc: get split ranges", () => {
|
|
|
|
|
it("should deal with big parts", () => {
|
|
|
|
|
const k = misc.getSplitRanges(10, 20);
|
|
|
|
|
const k2: misc.SplitRange[] = [
|
|
|
|
|
{
|
|
|
|
|
partNum: 1,
|
|
|
|
|
start: 0,
|
|
|
|
|
end: 10,
|
|
|
|
|
},
|
|
|
|
|
];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(k, k2);
|
2022-03-10 15:54:35 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should deal with 0 remainder", () => {
|
|
|
|
|
const k = misc.getSplitRanges(20, 10);
|
|
|
|
|
const k2: misc.SplitRange[] = [
|
|
|
|
|
{
|
|
|
|
|
partNum: 1,
|
|
|
|
|
start: 0,
|
|
|
|
|
end: 10,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
partNum: 2,
|
|
|
|
|
start: 10,
|
|
|
|
|
end: 20,
|
|
|
|
|
},
|
|
|
|
|
];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(k, k2);
|
2022-03-10 15:54:35 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should deal with not-0 remainder", () => {
|
|
|
|
|
const k = misc.getSplitRanges(25, 10);
|
|
|
|
|
const k2: misc.SplitRange[] = [
|
|
|
|
|
{
|
|
|
|
|
partNum: 1,
|
|
|
|
|
start: 0,
|
|
|
|
|
end: 10,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
partNum: 2,
|
|
|
|
|
start: 10,
|
|
|
|
|
end: 20,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
partNum: 3,
|
|
|
|
|
start: 20,
|
|
|
|
|
end: 25,
|
|
|
|
|
},
|
|
|
|
|
];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(k, k2);
|
2022-03-10 15:54:35 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2022-03-18 17:21:22 +00:00
|
|
|
|
|
|
|
|
|
describe("Misc: at which level", () => {
|
|
|
|
|
it("should throw error on some parameters", () => {
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.throws(() => misc.atWhichLevel(undefined));
|
|
|
|
|
assert.throws(() => misc.atWhichLevel(""));
|
|
|
|
|
assert.throws(() => misc.atWhichLevel(".."));
|
|
|
|
|
assert.throws(() => misc.atWhichLevel("."));
|
|
|
|
|
assert.throws(() => misc.atWhichLevel("/"));
|
|
|
|
|
assert.throws(() => misc.atWhichLevel("/xxyy"));
|
2022-03-18 17:21:22 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should treat folders correctly", () => {
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.atWhichLevel("x/"), 1);
|
|
|
|
|
assert.equal(misc.atWhichLevel("x/y/"), 2);
|
2022-03-18 17:21:22 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should treat files correctly", () => {
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.atWhichLevel("x.md"), 1);
|
|
|
|
|
assert.equal(misc.atWhichLevel("x/y.md"), 2);
|
|
|
|
|
assert.equal(misc.atWhichLevel("x/y/z.md"), 3);
|
2022-03-18 17:21:22 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2022-03-28 16:12:58 +00:00
|
|
|
|
|
|
|
|
|
describe("Misc: special char for dir", () => {
|
|
|
|
|
it("should return false for normal string", () => {
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(!misc.checkHasSpecialCharForDir(""));
|
|
|
|
|
assert.ok(!misc.checkHasSpecialCharForDir("xxx"));
|
|
|
|
|
assert.ok(!misc.checkHasSpecialCharForDir("yyy_xxx"));
|
|
|
|
|
assert.ok(!misc.checkHasSpecialCharForDir("yyy.xxx"));
|
|
|
|
|
assert.ok(!misc.checkHasSpecialCharForDir("yyy?xxx"));
|
2022-03-28 16:12:58 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return true for special cases", () => {
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.ok(misc.checkHasSpecialCharForDir("?"));
|
|
|
|
|
assert.ok(misc.checkHasSpecialCharForDir("/"));
|
|
|
|
|
assert.ok(misc.checkHasSpecialCharForDir("\\"));
|
|
|
|
|
assert.ok(misc.checkHasSpecialCharForDir("xxx/yyy"));
|
|
|
|
|
assert.ok(misc.checkHasSpecialCharForDir("xxx\\yyy"));
|
|
|
|
|
assert.ok(misc.checkHasSpecialCharForDir("xxx?yyy"));
|
2022-03-28 16:12:58 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2024-03-30 06:52:54 +00:00
|
|
|
|
|
2024-05-19 13:41:01 +00:00
|
|
|
|
describe("Misc: split chunk ranges", () => {
|
|
|
|
|
it("should fail on negative numner", () => {
|
|
|
|
|
assert.throws(() => misc.splitFileSizeToChunkRanges(-1, 2));
|
|
|
|
|
assert.throws(() => misc.splitFileSizeToChunkRanges(1, -1));
|
|
|
|
|
assert.throws(() => misc.splitFileSizeToChunkRanges(1, 0));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return nothing for 0 input", () => {
|
|
|
|
|
let input: [number, number] = [0, 1];
|
|
|
|
|
let output: any = [];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
|
|
|
|
|
input = [0, 100];
|
|
|
|
|
output = [];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return single item for 1 input", () => {
|
|
|
|
|
let input: [number, number] = [1, 1];
|
|
|
|
|
let output = [{ start: 0, end: 0 }];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
|
|
|
|
|
input = [1, 100];
|
|
|
|
|
output = [{ start: 0, end: 0 }];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return single item for larger or equal input", () => {
|
|
|
|
|
let input: [number, number] = [10, 10];
|
|
|
|
|
let output = [{ start: 0, end: 9 }];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
|
|
|
|
|
input = [10, 21];
|
|
|
|
|
output = [{ start: 0, end: 9 }];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return correct items for normal input", () => {
|
|
|
|
|
let input: [number, number] = [10, 9];
|
|
|
|
|
let output = [
|
|
|
|
|
{ start: 0, end: 8 },
|
|
|
|
|
{ start: 9, end: 9 },
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
|
|
|
|
|
input = [10, 5];
|
|
|
|
|
output = [
|
|
|
|
|
{ start: 0, end: 4 },
|
|
|
|
|
{ start: 5, end: 9 },
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
|
|
|
|
|
input = [3, 1];
|
|
|
|
|
output = [
|
|
|
|
|
{ start: 0, end: 0 },
|
|
|
|
|
{ start: 1, end: 1 },
|
|
|
|
|
{ start: 2, end: 2 },
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
|
|
|
|
|
input = [15, 5];
|
|
|
|
|
output = [
|
|
|
|
|
{ start: 0, end: 4 },
|
|
|
|
|
{ start: 5, end: 9 },
|
|
|
|
|
{ start: 10, end: 14 },
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
|
|
|
|
|
input = [1024, 578];
|
|
|
|
|
output = [
|
|
|
|
|
{ start: 0, end: 577 },
|
|
|
|
|
{ start: 578, end: 1023 },
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(output, misc.splitFileSizeToChunkRanges(...input));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-03-30 06:52:54 +00:00
|
|
|
|
describe("Misc: Dropbox: should fix the folder name cases", () => {
|
|
|
|
|
it("should do nothing on empty folders", () => {
|
|
|
|
|
const input: any[] = [];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.equal(misc.fixEntityListCasesInplace(input).length, 0);
|
2024-03-30 06:52:54 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should sort folders by length by side effect", () => {
|
|
|
|
|
const input = [
|
|
|
|
|
{ keyRaw: "aaaa/" },
|
|
|
|
|
{ keyRaw: "bbb/" },
|
|
|
|
|
{ keyRaw: "c/" },
|
|
|
|
|
{ keyRaw: "dd/" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const output = [
|
|
|
|
|
{ keyRaw: "c/" },
|
|
|
|
|
{ keyRaw: "dd/" },
|
|
|
|
|
{ keyRaw: "bbb/" },
|
|
|
|
|
{ keyRaw: "aaaa/" },
|
|
|
|
|
];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.fixEntityListCasesInplace(input), output);
|
2024-03-30 06:52:54 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should fix folder names", () => {
|
|
|
|
|
const input = [
|
|
|
|
|
{ keyRaw: "AAA/" },
|
|
|
|
|
{ keyRaw: "aaa/bbb/CCC.md" },
|
|
|
|
|
{ keyRaw: "aaa/BBB/" },
|
|
|
|
|
|
|
|
|
|
{ keyRaw: "ddd/" },
|
|
|
|
|
{ keyRaw: "DDD/EEE/fff.md" },
|
|
|
|
|
{ keyRaw: "DDD/eee/" },
|
|
|
|
|
|
|
|
|
|
{ keyRaw: "Ggg/" },
|
|
|
|
|
{ keyRaw: "ggG/hHH你好/Fff世界.md" },
|
|
|
|
|
{ keyRaw: "ggG/Hhh你好/" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const output = [
|
|
|
|
|
{ keyRaw: "AAA/" },
|
|
|
|
|
{ keyRaw: "ddd/" },
|
|
|
|
|
{ keyRaw: "Ggg/" },
|
|
|
|
|
{ keyRaw: "AAA/BBB/" },
|
|
|
|
|
{ keyRaw: "ddd/eee/" },
|
|
|
|
|
{ keyRaw: "Ggg/Hhh你好/" },
|
|
|
|
|
{ keyRaw: "AAA/BBB/CCC.md" },
|
|
|
|
|
{ keyRaw: "ddd/eee/fff.md" },
|
|
|
|
|
{ keyRaw: "Ggg/Hhh你好/Fff世界.md" },
|
|
|
|
|
];
|
2024-04-26 19:28:39 +00:00
|
|
|
|
assert.deepEqual(misc.fixEntityListCasesInplace(input), output);
|
2024-03-30 06:52:54 +00:00
|
|
|
|
});
|
|
|
|
|
});
|