forked from RunMaestro/Maestro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcue-path-utils.test.ts
More file actions
76 lines (61 loc) · 2.46 KB
/
cue-path-utils.test.ts
File metadata and controls
76 lines (61 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, it, expect } from 'vitest';
import { computeCommonAncestorPath, isDescendantOrEqual } from '../../shared/cue-path-utils';
describe('computeCommonAncestorPath', () => {
it('returns null for empty input', () => {
expect(computeCommonAncestorPath([])).toBeNull();
});
it('returns the path itself for a single-element array', () => {
expect(computeCommonAncestorPath(['/a/b/c'])).toBe('/a/b/c');
});
it('returns the common parent for sibling directories', () => {
expect(computeCommonAncestorPath(['/a/b/c', '/a/b/d'])).toBe('/a/b');
});
it('returns the parent when one path is a child of the other', () => {
expect(computeCommonAncestorPath(['/project', '/project/sub'])).toBe('/project');
});
it('returns the parent for deeply nested children', () => {
expect(computeCommonAncestorPath(['/project', '/project/sub/deep', '/project/other'])).toBe(
'/project'
);
});
it('returns filesystem root for completely unrelated paths', () => {
expect(computeCommonAncestorPath(['/a/b', '/c/d'])).toBe('/');
});
it('handles identical paths', () => {
expect(computeCommonAncestorPath(['/a/b', '/a/b'])).toBe('/a/b');
});
it('handles three paths with a shared prefix', () => {
expect(
computeCommonAncestorPath([
'/home/user/project/A',
'/home/user/project/B',
'/home/user/project/C',
])
).toBe('/home/user/project');
});
});
describe('isDescendantOrEqual', () => {
it('returns true when paths are identical', () => {
expect(isDescendantOrEqual('/a/b', '/a/b')).toBe(true);
});
it('returns true when child is a subdirectory of parent', () => {
expect(isDescendantOrEqual('/a/b/c', '/a/b')).toBe(true);
});
it('returns true for deeply nested descendant', () => {
expect(isDescendantOrEqual('/project/sub/deep/nested', '/project')).toBe(true);
});
it('returns false when child is not under parent', () => {
expect(isDescendantOrEqual('/a/b', '/c/d')).toBe(false);
});
it('returns false when parent is a subdirectory of child (reversed)', () => {
expect(isDescendantOrEqual('/a', '/a/b')).toBe(false);
});
it('returns false for partial prefix match that is not a directory boundary', () => {
// /a/bar is NOT a descendant of /a/b — the prefix match is not at a separator
expect(isDescendantOrEqual('/a/bar', '/a/b')).toBe(false);
});
it('handles trailing separators via normalization', () => {
expect(isDescendantOrEqual('/a/b/c', '/a/b/')).toBe(true);
expect(isDescendantOrEqual('/a/b/', '/a/b')).toBe(true);
});
});