forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath.test.ts
More file actions
48 lines (40 loc) · 1.85 KB
/
Path.test.ts
File metadata and controls
48 lines (40 loc) · 1.85 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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as os from 'os';
import { Path } from '../Path';
describe('Path', () => {
describe('Test', () => {
if (os.platform() === 'win32') {
test('Windows paths', () => {
expect(Path.isUnder('C:\\a\\b.txt', 'C:\\a')).toEqual(true);
expect(Path.isUnder('C:\\a\\b.txt', 'C:\\a\\')).toEqual(true);
expect(Path.isUnder('C:\\a\\b\\c.txt', 'C:\\a')).toEqual(true);
expect(Path.isUnder('C:\\a\\b.txt', 'C:\\b')).toEqual(false);
expect(Path.isUnder('C:\\a\\b.txt', 'C:\\b\\')).toEqual(false);
expect(Path.isUnder('C:\\a\\b\\c.txt', 'C:\\b')).toEqual(false);
expect(Path.isUnder('C:\\a\\b.txt', 'D:\\a')).toEqual(false);
});
}
test('POSIX-style paths', () => {
expect(Path.isUnder('/a/b.txt', '/a')).toEqual(true);
expect(Path.isUnder('/a/b.txt', '/a/')).toEqual(true);
expect(Path.isUnder('/a/b/c.txt', '/a')).toEqual(true);
expect(Path.isUnder('/a/b.txt', '/b')).toEqual(false);
expect(Path.isUnder('/a/b.txt', '/b/')).toEqual(false);
expect(Path.isUnder('/a/b/c.txt', '/b')).toEqual(false);
});
test('Edge cases', () => {
expect(Path.isUnder('/a', '/a')).toEqual(false);
expect(Path.isUnder('.', '.')).toEqual(false);
expect(Path.isUnder('', '')).toEqual(false);
});
test('Relative paths', () => {
expect(Path.isUnder('a/b/c', 'a/b')).toEqual(true);
expect(Path.isUnder('./a/b/c', './a/b')).toEqual(true);
expect(Path.isUnder('../a/b/c', '../a/b')).toEqual(true);
expect(Path.isUnder('a/b', 'a/b/c')).toEqual(false);
expect(Path.isUnder('./a/b', './a/b/c')).toEqual(false);
expect(Path.isUnder('../a/b', '../a/b/c')).toEqual(false);
});
});
});