7
7
using System . Runtime . InteropServices ;
8
8
using Microsoft . Extensions . Logging . Abstractions ;
9
9
using Microsoft . PowerShell . EditorServices . Services ;
10
- using Microsoft . PowerShell . EditorServices . Test . Shared ;
11
10
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
12
11
using Xunit ;
13
12
using Microsoft . PowerShell . EditorServices . Utility ;
@@ -27,6 +26,8 @@ public class WorkspaceTests
27
26
28
27
internal static ScriptFile CreateScriptFile ( string path ) => new ( path , "" , VersionUtils . PSVersion ) ;
29
28
29
+ // Remember that LSP does weird stuff to the drive letter, so it has to be lower case.
30
+ private static readonly string s_workspacePath = Path . GetFullPath ( "Fixtures/Workspace" ) . Replace ( "C:\\ " , "c:\\ " ) ;
30
31
31
32
[ Fact ]
32
33
public void CanResolveWorkspaceRelativePath ( )
@@ -76,16 +77,21 @@ internal static WorkspaceService FixturesWorkspace()
76
77
{
77
78
return new WorkspaceService ( NullLoggerFactory . Instance )
78
79
{
79
- InitialWorkingDirectory = TestUtilities . NormalizePath ( "Fixtures/Workspace" )
80
+ WorkspaceFolders =
81
+ {
82
+ new WorkspaceFolder { Uri = DocumentUri . FromFileSystemPath ( s_workspacePath ) }
83
+ }
80
84
} ;
81
85
}
82
86
83
87
[ Fact ]
84
88
public void HasDefaultForWorkspacePaths ( )
85
89
{
86
90
WorkspaceService workspace = FixturesWorkspace ( ) ;
87
- string actual = Assert . Single ( workspace . WorkspacePaths ) ;
88
- Assert . Equal ( workspace . InitialWorkingDirectory , actual ) ;
91
+ string workspacePath = Assert . Single ( workspace . WorkspacePaths ) ;
92
+ Assert . Equal ( s_workspacePath , workspacePath ) ;
93
+ // We shouldn't assume an initial working directory since none was given.
94
+ Assert . Null ( workspace . InitialWorkingDirectory ) ;
89
95
}
90
96
91
97
// These are the default values for the EnumeratePSFiles() method
@@ -129,18 +135,18 @@ public void CanRecurseDirectoryTree()
129
135
130
136
List < string > expected = new ( )
131
137
{
132
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "donotfind.ps1" ) ,
133
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "nestedmodule.psd1" ) ,
134
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "nestedmodule.psm1" ) ,
135
- Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" )
138
+ Path . Combine ( s_workspacePath , "nested" , "donotfind.ps1" ) ,
139
+ Path . Combine ( s_workspacePath , "nested" , "nestedmodule.psd1" ) ,
140
+ Path . Combine ( s_workspacePath , "nested" , "nestedmodule.psm1" ) ,
141
+ Path . Combine ( s_workspacePath , "rootfile.ps1" )
136
142
} ;
137
143
138
144
// .NET Core doesn't appear to use the same three letter pattern matching rule although the docs
139
145
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
140
146
// ref https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netcore-2.1#System_IO_Directory_GetFiles_System_String_System_String_System_IO_EnumerationOptions_
141
147
if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" ) )
142
148
{
143
- expected . Insert ( 3 , Path . Combine ( workspace . InitialWorkingDirectory , "other" , "other.ps1xml" ) ) ;
149
+ expected . Insert ( 3 , Path . Combine ( s_workspacePath , "other" , "other.ps1xml" ) ) ;
144
150
}
145
151
146
152
Assert . Equal ( expected , actual ) ;
@@ -157,7 +163,7 @@ public void CanRecurseDirectoryTreeWithLimit()
157
163
maxDepth : 1 ,
158
164
ignoreReparsePoints : s_defaultIgnoreReparsePoints
159
165
) ;
160
- Assert . Equal ( new [ ] { Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" ) } , actual ) ;
166
+ Assert . Equal ( new [ ] { Path . Combine ( s_workspacePath , "rootfile.ps1" ) } , actual ) ;
161
167
}
162
168
163
169
[ Fact ]
@@ -173,16 +179,16 @@ public void CanRecurseDirectoryTreeWithGlobs()
173
179
) ;
174
180
175
181
Assert . Equal ( new [ ] {
176
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "nestedmodule.psd1" ) ,
177
- Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" )
182
+ Path . Combine ( s_workspacePath , "nested" , "nestedmodule.psd1" ) ,
183
+ Path . Combine ( s_workspacePath , "rootfile.ps1" )
178
184
} , actual ) ;
179
185
}
180
186
181
187
[ Fact ]
182
188
public void CanOpenAndCloseFile ( )
183
189
{
184
190
WorkspaceService workspace = FixturesWorkspace ( ) ;
185
- string filePath = Path . GetFullPath ( Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" ) ) ;
191
+ string filePath = Path . GetFullPath ( Path . Combine ( s_workspacePath , "rootfile.ps1" ) ) ;
186
192
187
193
ScriptFile file = workspace . GetFile ( filePath ) ;
188
194
Assert . Equal ( workspace . GetOpenedFiles ( ) , new [ ] { file } ) ;
0 commit comments