This commit is contained in:
vcoppe committed 2026-10-18 00:24:16 +02:00
1 parent 5373d0f0d4
commit 3012f6bf73
8 files changed
+138 -69

No files matched your search

+9
View File
@@ -6,6 +6,7 @@ import {
folderName,
isWithin,
parentOf,
relocated,
subfolder,
} from '$lib/engine/workspace';
@@ -62,6 +63,14 @@ describe('parentOf', () => {
});
});
describe('relocated', () => {
it('is where a path is once moved or renamed', () => {
assert.equal(relocated('/me/tracks/a.gpx', '/me/trips'), '/me/trips/a.gpx');
assert.equal(relocated('/me/tracks', '/me', 'rides'), '/me/rides');
assert.equal(relocated('C:\\me\\tracks', 'C:\\me', 'rides'), 'C:\\me\\rides');
});
});
describe('isWithin', () => {
it('is the folder itself or what is in it', () => {
assert.ok(isWithin('/home/me/tracks', '/home/me/tracks'));
+6
View File
@@ -41,6 +41,12 @@ export function parentOf(path: string): string {
return index > 0 ? path.slice(0, index) : path;
}
/** Where `path` is once moved into `folder`, renamed `name` if it is given. */
export function relocated(path: string, folder: string, name?: string): string {
const parent = parentOf(path);
return `${folder}${path[parent.length]}${name ?? path.slice(parent.length + 1)}`;
}
/** Whether `path` is `folder` or something in it. */
export function isWithin(path: string, folder: string): boolean {
return path === folder || (path.startsWith(folder) && /[\\/]/.test(path[folder.length]));