|
| 1 | +import * as assert from 'node:assert'; |
| 2 | +import { FileType, Uri, workspace } from 'vscode'; |
| 3 | +import { isDescendant, isFolderGlobUri, isFolderUri } from '../path'; |
| 4 | + |
| 5 | +suite('Path Test Suite', () => { |
| 6 | + suite('isDescendant Tests', () => { |
| 7 | + test('string paths - basic functionality', () => { |
| 8 | + // Basic case |
| 9 | + assert.strictEqual(isDescendant('/path/to/file', '/path'), true); |
| 10 | + assert.strictEqual(isDescendant('/path/to/file', '/other'), false); |
| 11 | + |
| 12 | + // Root path |
| 13 | + assert.strictEqual(isDescendant('/anything', '/'), true); |
| 14 | + |
| 15 | + // Trailing slashes in base |
| 16 | + assert.strictEqual(isDescendant('/path/to/file', '/path/'), true); |
| 17 | + // Folder glob in base |
| 18 | + assert.strictEqual(isDescendant('/path/to/file', '/path/*'), true); |
| 19 | + |
| 20 | + // Exact match should not match |
| 21 | + assert.strictEqual(isDescendant('/path', '/path'), false); |
| 22 | + // Partial path segment should not match |
| 23 | + assert.strictEqual(isDescendant('/pathExtra/to/file', '/path'), false); |
| 24 | + }); |
| 25 | + |
| 26 | + test('URI paths - basic functionality', () => { |
| 27 | + const baseUri = Uri.parse('file:///path'); |
| 28 | + const fileUri = Uri.parse('file:///path/to/file'); |
| 29 | + const otherUri = Uri.parse('file:///other/path'); |
| 30 | + |
| 31 | + assert.strictEqual(isDescendant(fileUri, baseUri), true); |
| 32 | + assert.strictEqual(isDescendant(otherUri, baseUri), false); |
| 33 | + |
| 34 | + // Different schemes |
| 35 | + const httpUri = Uri.parse('http:///path/to/file'); |
| 36 | + assert.strictEqual(isDescendant(httpUri, baseUri), false); |
| 37 | + |
| 38 | + // Different authorities |
| 39 | + const diffAuthorityUri = Uri.parse('file://server1/path/to/file'); |
| 40 | + const baseAuthorityUri = Uri.parse('file://server2/path'); |
| 41 | + assert.strictEqual(isDescendant(diffAuthorityUri, baseAuthorityUri), false); |
| 42 | + }); |
| 43 | + |
| 44 | + test('mixed string and URI paths', () => { |
| 45 | + const baseUri = Uri.parse('file:///base/path'); |
| 46 | + |
| 47 | + assert.strictEqual(isDescendant('/base/path/to/file', baseUri), true); |
| 48 | + assert.strictEqual(isDescendant('/other/path', baseUri), false); |
| 49 | + |
| 50 | + assert.strictEqual(isDescendant(Uri.parse('file:///base/path/file'), '/base/path'), true); |
| 51 | + assert.strictEqual(isDescendant(Uri.parse('file:///other/path'), '/base/path'), false); |
| 52 | + }); |
| 53 | + |
| 54 | + test('edge cases', () => { |
| 55 | + // Empty paths |
| 56 | + assert.strictEqual(isDescendant('', '/'), true); |
| 57 | + assert.strictEqual(isDescendant('/', ''), true); |
| 58 | + |
| 59 | + // URI with query parameters |
| 60 | + const baseUri = Uri.parse('file:///base/path'); |
| 61 | + const uriWithQuery = Uri.parse('file:///base/path/file?query=value'); |
| 62 | + |
| 63 | + assert.strictEqual(isDescendant(uriWithQuery, baseUri), true); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + suite('isFolderGlobUri Tests', () => { |
| 68 | + test('URI with glob pattern', () => { |
| 69 | + assert.strictEqual(isFolderGlobUri(Uri.parse('file:///path/*')), true); |
| 70 | + assert.strictEqual(isFolderGlobUri(Uri.parse('file:///path/to/*')), true); |
| 71 | + }); |
| 72 | + |
| 73 | + test('URI without glob pattern', () => { |
| 74 | + assert.strictEqual(isFolderGlobUri(Uri.parse('file:///path')), false); |
| 75 | + assert.strictEqual(isFolderGlobUri(Uri.parse('file:///path/file.txt')), false); |
| 76 | + assert.strictEqual(isFolderGlobUri(Uri.parse('file:///path/dir/')), false); |
| 77 | + }); |
| 78 | + |
| 79 | + test('Edge cases', () => { |
| 80 | + assert.strictEqual(isFolderGlobUri(Uri.parse('file:///*')), true); |
| 81 | + assert.strictEqual(isFolderGlobUri(Uri.parse('http:///path/*')), true); |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments