-
Notifications
You must be signed in to change notification settings - Fork 683
Expand file tree
/
Copy pathlockfilePath.test.ts
More file actions
57 lines (47 loc) · 2.42 KB
/
lockfilePath.test.ts
File metadata and controls
57 lines (47 loc) · 2.42 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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as lockfilePath from '../lockfilePath';
describe('lockfilePath', () => {
it('getBaseNameOf', () => {
expect(lockfilePath.getBaseNameOf('/a/b/c/d')).toBe('d');
expect(lockfilePath.getBaseNameOf('.')).toBe('.');
expect(lockfilePath.getBaseNameOf('')).toBe('');
expect(() => lockfilePath.getParentOf('/a/')).toThrow('has a trailing slash');
});
it('getParentOf', () => {
expect(lockfilePath.getParentOf('a/b/c/d')).toBe('a/b/c');
expect(lockfilePath.getParentOf('/a/b/c')).toBe('/a/b');
expect(lockfilePath.getParentOf('/a/b')).toBe('/a');
expect(lockfilePath.getParentOf('/a')).toBe('/');
expect(lockfilePath.getParentOf('a')).toBe('.');
expect(() => lockfilePath.getParentOf('')).toThrow('has no parent');
expect(() => lockfilePath.getParentOf('/')).toThrow('has no parent');
expect(() => lockfilePath.getParentOf('.')).toThrow('has no parent');
expect(() => lockfilePath.getParentOf('/a/')).toThrow('has a trailing slash');
});
it('getAbsolute', () => {
expect(lockfilePath.getAbsolute('a/b/c', 'd/e')).toBe('a/b/c/d/e');
expect(lockfilePath.getAbsolute('/a/b/c', 'd/e')).toBe('/a/b/c/d/e');
expect(lockfilePath.getAbsolute('/a/b/c', '/d/e')).toBe('/d/e');
expect(lockfilePath.getAbsolute('a/b/c', '../../f')).toBe('a/f');
expect(lockfilePath.getAbsolute('a/b/c', '.././/f')).toBe('a/b/f');
expect(lockfilePath.getAbsolute('a/b/c', '../../..')).toBe('.');
expect(lockfilePath.getAbsolute('C:/a/b', '../d')).toBe('C:/a/d');
// Error case
expect(() => lockfilePath.getAbsolute('a/b/c', '../../../..')).toThrow('goes above the root folder');
// Degenerate cases
expect(lockfilePath.getAbsolute('a/b/c/', 'd/')).toBe('a/b/c/d');
expect(lockfilePath.getAbsolute('./../c', 'd')).toBe('./../c/d');
expect(lockfilePath.getAbsolute('C:\\', '\\a')).toBe('C:\\/\\a');
});
it('join', () => {
expect(lockfilePath.join('', 'a')).toBe('a');
expect(lockfilePath.join('b', '')).toBe('b');
expect(lockfilePath.join('a', 'b')).toBe('a/b');
expect(lockfilePath.join('a/', 'b')).toBe('a/b');
expect(lockfilePath.join('a', '/b')).toBe('a/b');
expect(lockfilePath.join('a/', '/b')).toBe('a/b');
// Degenerate cases
expect(lockfilePath.join('a//', '/b')).toBe('a//b');
});
});