10
10
using Microsoft . PowerShell . EditorServices . Test . Shared ;
11
11
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
12
12
using Xunit ;
13
+ using Microsoft . PowerShell . EditorServices . Utility ;
14
+ using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
15
+ using OmniSharp . Extensions . LanguageServer . Protocol ;
13
16
14
17
namespace PowerShellEditorServices . Test . Session
15
18
{
@@ -22,27 +25,51 @@ public class WorkspaceTests
22
25
? s_lazyDriveLetter . Value
23
26
: string . Empty ;
24
27
28
+ internal static ScriptFile CreateScriptFile ( string path ) => new ( path , "" , VersionUtils . PSVersion ) ;
29
+
30
+
25
31
[ Fact ]
26
32
public void CanResolveWorkspaceRelativePath ( )
27
33
{
28
- string workspacePath = TestUtilities . NormalizePath ( "c:/Test/Workspace/" ) ;
29
- string testPathInside = TestUtilities . NormalizePath ( "c:/Test/Workspace/SubFolder/FilePath.ps1" ) ;
30
- string testPathOutside = TestUtilities . NormalizePath ( "c:/Test/PeerPath/FilePath.ps1" ) ;
31
- string testPathAnotherDrive = TestUtilities . NormalizePath ( "z:/TryAndFindMe/FilePath.ps1" ) ;
34
+ string workspacePath = "c:/Test/Workspace/" ;
35
+ ScriptFile testPathInside = CreateScriptFile ( "c:/Test/Workspace/SubFolder/FilePath.ps1" ) ;
36
+ ScriptFile testPathOutside = CreateScriptFile ( "c:/Test/PeerPath/FilePath.ps1" ) ;
37
+ ScriptFile testPathAnotherDrive = CreateScriptFile ( "z:/TryAndFindMe/FilePath.ps1" ) ;
32
38
33
39
WorkspaceService workspace = new ( NullLoggerFactory . Instance ) ;
34
40
35
- // Test without a workspace path
36
- Assert . Equal ( testPathOutside , workspace . GetRelativePath ( testPathOutside ) ) ;
41
+ // Test with zero workspace folders
42
+ Assert . Equal (
43
+ testPathOutside . DocumentUri . ToUri ( ) . AbsolutePath ,
44
+ workspace . GetRelativePath ( testPathOutside ) ) ;
37
45
38
- string expectedInsidePath = TestUtilities . NormalizePath ( "SubFolder/FilePath.ps1" ) ;
39
- string expectedOutsidePath = TestUtilities . NormalizePath ( "../PeerPath/FilePath.ps1" ) ;
46
+ string expectedInsidePath = "SubFolder/FilePath.ps1" ;
47
+ string expectedOutsidePath = "../PeerPath/FilePath.ps1" ;
48
+
49
+ // Test with a single workspace folder
50
+ workspace . WorkspaceFolders . Add ( new WorkspaceFolder
51
+ {
52
+ Uri = DocumentUri . FromFileSystemPath ( workspacePath )
53
+ } ) ;
40
54
41
- // Test with a workspace path
42
- workspace . InitialWorkingDirectory = workspacePath ;
43
55
Assert . Equal ( expectedInsidePath , workspace . GetRelativePath ( testPathInside ) ) ;
44
56
Assert . Equal ( expectedOutsidePath , workspace . GetRelativePath ( testPathOutside ) ) ;
45
- Assert . Equal ( testPathAnotherDrive , workspace . GetRelativePath ( testPathAnotherDrive ) ) ;
57
+ Assert . Equal (
58
+ testPathAnotherDrive . DocumentUri . ToUri ( ) . AbsolutePath ,
59
+ workspace . GetRelativePath ( testPathAnotherDrive ) ) ;
60
+
61
+ // Test with two workspace folders
62
+ string anotherWorkspacePath = "c:/Test/AnotherWorkspace/" ;
63
+ ScriptFile anotherTestPathInside = CreateScriptFile ( "c:/Test/AnotherWorkspace/DifferentFolder/FilePath.ps1" ) ;
64
+ string anotherExpectedInsidePath = "DifferentFolder/FilePath.ps1" ;
65
+
66
+ workspace . WorkspaceFolders . Add ( new WorkspaceFolder
67
+ {
68
+ Uri = DocumentUri . FromFileSystemPath ( anotherWorkspacePath )
69
+ } ) ;
70
+
71
+ Assert . Equal ( expectedInsidePath , workspace . GetRelativePath ( testPathInside ) ) ;
72
+ Assert . Equal ( anotherExpectedInsidePath , workspace . GetRelativePath ( anotherTestPathInside ) ) ;
46
73
}
47
74
48
75
internal static WorkspaceService FixturesWorkspace ( )
@@ -143,40 +170,6 @@ public void CanRecurseDirectoryTreeWithGlobs()
143
170
} , actual ) ;
144
171
}
145
172
146
- [ Fact ]
147
- public void CanDetermineIsPathInMemory ( )
148
- {
149
- string tempDir = Path . GetTempPath ( ) ;
150
- string shortDirPath = Path . Combine ( tempDir , "GitHub" , "PowerShellEditorServices" ) ;
151
- string shortFilePath = Path . Combine ( shortDirPath , "foo.ps1" ) ;
152
- const string shortUriForm = "git:/c%3A/Users/Keith/GitHub/dahlbyk/posh-git/src/PoshGitTypes.ps1?%7B%22path%22%3A%22c%3A%5C%5CUsers%5C%5CKeith%5C%5CGitHub%5C%5Cdahlbyk%5C%5Cposh-git%5C%5Csrc%5C%5CPoshGitTypes.ps1%22%2C%22ref%22%3A%22~%22%7D" ;
153
- const string longUriForm = "gitlens-git:c%3A%5CUsers%5CKeith%5CGitHub%5Cdahlbyk%5Cposh-git%5Csrc%5CPoshGitTypes%3Ae0022701.ps1?%7B%22fileName%22%3A%22src%2FPoshGitTypes.ps1%22%2C%22repoPath%22%3A%22c%3A%2FUsers%2FKeith%2FGitHub%2Fdahlbyk%2Fposh-git%22%2C%22sha%22%3A%22e0022701fa12e0bc22d0458673d6443c942b974a%22%7D" ;
154
-
155
- string [ ] inMemoryPaths = new [ ] {
156
- // Test short non-file paths
157
- "untitled:untitled-1" ,
158
- shortUriForm ,
159
- "inmemory://foo.ps1" ,
160
- // Test long non-file path
161
- longUriForm
162
- } ;
163
-
164
- Assert . All ( inMemoryPaths , ( p ) => Assert . True ( WorkspaceService . IsPathInMemory ( p ) ) ) ;
165
-
166
- string [ ] notInMemoryPaths = new [ ] {
167
- // Test short file absolute paths
168
- shortDirPath ,
169
- shortFilePath ,
170
- new Uri ( shortDirPath ) . ToString ( ) ,
171
- new Uri ( shortFilePath ) . ToString ( ) ,
172
- // Test short file relative paths
173
- "foo.ps1" ,
174
- Path . Combine ( new [ ] { ".." , "foo.ps1" } )
175
- } ;
176
-
177
- Assert . All ( notInMemoryPaths , ( p ) => Assert . False ( WorkspaceService . IsPathInMemory ( p ) ) ) ;
178
- }
179
-
180
173
[ Fact ]
181
174
public void CanOpenAndCloseFile ( )
182
175
{
0 commit comments