Skip to content

Commit 9511188

Browse files
248369: Adding tests to verify path transformation logic works correctly
1 parent 06c1b71 commit 9511188

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import 'mocha';
7+
import assert from 'assert';
8+
import path from 'path';
9+
import { isWindows } from '../util';
10+
11+
suite('Repository path handling', () => {
12+
// Skip all tests if not on Windows, as these tests are for Windows-specific path handling
13+
suiteSetup(function () {
14+
if (!isWindows) {
15+
this.skip();
16+
}
17+
});
18+
19+
// Test the path manipulation logic directly for subst drives
20+
test('subst drive path correction', () => {
21+
const root = 'X:\\repo';
22+
const rootRealPath = 'C:\\real\\path\\repo';
23+
const fsPath = 'X:\\repo\\file.txt';
24+
25+
// This is the logic from the fix we implemented
26+
const realPath = fsPath.startsWith(root)
27+
? path.join(rootRealPath, fsPath.substring(root.length))
28+
: fsPath;
29+
30+
// Verify the path is correctly transformed
31+
assert.strictEqual(realPath, 'C:\\real\\path\\repo\\file.txt');
32+
});
33+
34+
test('non-subst path should remain unchanged', () => {
35+
const root = 'C:\\repo';
36+
const rootRealPath = 'C:\\repo';
37+
const fsPath = 'C:\\repo\\file.txt';
38+
39+
// Same logic as implemented in the fix
40+
const realPath = fsPath.startsWith(root)
41+
? path.join(rootRealPath, fsPath.substring(root.length))
42+
: fsPath;
43+
44+
// Path should remain unchanged
45+
assert.strictEqual(realPath, 'C:\\repo\\file.txt');
46+
});
47+
48+
test('path outside repository should remain unchanged', () => {
49+
const root = 'X:\\repo';
50+
const rootRealPath = 'C:\\real\\path\\repo';
51+
const fsPath = 'D:\\other\\file.txt';
52+
53+
// Same logic as implemented in the fix
54+
const realPath = fsPath.startsWith(root)
55+
? path.join(rootRealPath, fsPath.substring(root.length))
56+
: fsPath;
57+
58+
// Path should remain unchanged
59+
assert.strictEqual(realPath, 'D:\\other\\file.txt');
60+
});
61+
});

0 commit comments

Comments
 (0)