3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
- using System . IO ;
7
6
using System . Linq ;
8
7
using System . Management . Automation ;
9
8
using System . Runtime . InteropServices ;
@@ -38,7 +37,10 @@ public class SymbolsServiceTests : IDisposable
38
37
public SymbolsServiceTests ( )
39
38
{
40
39
psesHost = PsesHostFactory . Create ( NullLoggerFactory . Instance ) ;
41
- workspace = new WorkspaceService ( NullLoggerFactory . Instance ) ;
40
+ workspace = new WorkspaceService ( NullLoggerFactory . Instance )
41
+ {
42
+ WorkspacePath = TestUtilities . GetSharedPath ( "References" )
43
+ } ;
42
44
symbolsService = new SymbolsService (
43
45
NullLoggerFactory . Instance ,
44
46
psesHost ,
@@ -80,7 +82,7 @@ private Task<ParameterSetSignatures> GetParamSetSignatures(ScriptRegion scriptRe
80
82
scriptRegion . StartColumnNumber ) ;
81
83
}
82
84
83
- private async Task < SymbolReference > GetDefinition ( ScriptRegion scriptRegion )
85
+ private async Task < IEnumerable < SymbolReference > > GetDefinitions ( ScriptRegion scriptRegion )
84
86
{
85
87
ScriptFile scriptFile = GetScriptFile ( scriptRegion ) ;
86
88
@@ -92,9 +94,13 @@ private async Task<SymbolReference> GetDefinition(ScriptRegion scriptRegion)
92
94
93
95
Assert . NotNull ( symbol ) ;
94
96
95
- IEnumerable < SymbolReference > refs = await symbolsService . GetDefinitionOfSymbolAsync ( scriptFile , symbol ) . ConfigureAwait ( true ) ;
97
+ return await symbolsService . GetDefinitionOfSymbolAsync ( scriptFile , symbol ) . ConfigureAwait ( true ) ;
98
+ }
96
99
97
- return refs . FirstOrDefault ( ) ;
100
+ private async Task < SymbolReference > GetDefinition ( ScriptRegion scriptRegion )
101
+ {
102
+ IEnumerable < SymbolReference > definitions = await GetDefinitions ( scriptRegion ) . ConfigureAwait ( true ) ;
103
+ return definitions . FirstOrDefault ( ) ;
98
104
}
99
105
100
106
private async Task < List < SymbolReference > > GetReferences ( ScriptRegion scriptRegion )
@@ -156,11 +162,11 @@ public async Task FindsFunctionDefinition()
156
162
{
157
163
SymbolReference symbol = await GetDefinition ( FindsFunctionDefinitionData . SourceDetails ) . ConfigureAwait ( true ) ;
158
164
Assert . Equal ( "My-Function" , symbol . SymbolName ) ;
159
- AssertIsRegion ( symbol . NameRegion , 1 , 10 , 1 , 21 ) ;
160
- // TODO: This should pull the declaration from references.
161
- // AssertIsRegion(symbol.ScriptRegion, 1, 1, 4, 2);
165
+ Assert . Equal ( "function My-Function($myInput)" , symbol . DisplayString ) ;
162
166
Assert . Equal ( SymbolType . Function , symbol . SymbolType ) ;
163
- // Assert.True(symbol.IsDeclaration);
167
+ AssertIsRegion ( symbol . NameRegion , 1 , 10 , 1 , 21 ) ;
168
+ AssertIsRegion ( symbol . ScriptRegion , 1 , 1 , 4 , 2 ) ;
169
+ Assert . True ( symbol . IsDeclaration ) ;
164
170
}
165
171
166
172
[ Fact ]
@@ -173,11 +179,11 @@ await psesHost.ExecutePSCommandAsync(
173
179
CancellationToken . None ) . ConfigureAwait ( true ) ;
174
180
175
181
SymbolReference symbol = await GetDefinition ( FindsFunctionDefinitionOfAliasData . SourceDetails ) . ConfigureAwait ( true ) ;
176
- AssertIsRegion ( symbol . NameRegion , 1 , 10 , 1 , 21 ) ;
177
- Assert . Equal ( "My-Function" , symbol . SymbolName ) ;
182
+ Assert . Equal ( "function My-Function($myInput)" , symbol . DisplayString ) ;
178
183
Assert . Equal ( SymbolType . Function , symbol . SymbolType ) ;
179
- // TODO: This should pull the declaration from references.
180
- // Assert.True(symbol.IsDeclaration);
184
+ AssertIsRegion ( symbol . NameRegion , 1 , 10 , 1 , 21 ) ;
185
+ AssertIsRegion ( symbol . ScriptRegion , 1 , 1 , 4 , 2 ) ;
186
+ Assert . True ( symbol . IsDeclaration ) ;
181
187
}
182
188
183
189
[ Fact ]
@@ -209,37 +215,28 @@ await psesHost.ExecutePSCommandAsync(
209
215
}
210
216
211
217
[ Fact ]
212
- public async Task FindsFunctionDefinitionInDotSourceReference ( )
218
+ public async Task FindsFunctionDefinitionsInWorkspace ( )
213
219
{
214
- SymbolReference definitionResult = await GetDefinition ( FindsFunctionDefinitionInDotSourceReferenceData . SourceDetails ) . ConfigureAwait ( true ) ;
215
- Assert . True (
216
- definitionResult . FilePath . EndsWith ( FindsFunctionDefinitionData . SourceDetails . File ) ,
217
- "Unexpected reference file: " + definitionResult . FilePath ) ;
218
- Assert . Equal ( 1 , definitionResult . ScriptRegion . StartLineNumber ) ;
219
- Assert . Equal ( 10 , definitionResult . ScriptRegion . StartColumnNumber ) ;
220
- Assert . Equal ( "My-Function" , definitionResult . SymbolName ) ;
221
- }
222
-
223
- [ Fact ]
224
- public async Task FindsDotSourcedFile ( )
225
- {
226
- SymbolReference definitionResult = await GetDefinition ( FindsDotSourcedFileData . SourceDetails ) . ConfigureAwait ( true ) ;
227
- Assert . NotNull ( definitionResult ) ;
228
- Assert . True (
229
- definitionResult . FilePath . EndsWith ( Path . Combine ( "References" , "ReferenceFileE.ps1" ) ) ,
230
- "Unexpected reference file: " + definitionResult . FilePath ) ;
231
- Assert . Equal ( 1 , definitionResult . ScriptRegion . StartLineNumber ) ;
232
- Assert . Equal ( 1 , definitionResult . ScriptRegion . StartColumnNumber ) ;
233
- Assert . Equal ( "./ReferenceFileE.ps1" , definitionResult . SymbolName ) ;
220
+ IEnumerable < SymbolReference > symbols = await GetDefinitions ( FindsFunctionDefinitionInDotSourceReferenceData . SourceDetails ) . ConfigureAwait ( true ) ;
221
+ Assert . Collection ( symbols . OrderBy ( ( i ) => i . FilePath ) ,
222
+ ( i ) =>
223
+ {
224
+ Assert . Equal ( "My-Function" , i . SymbolName ) ;
225
+ Assert . EndsWith ( "ReferenceFileA.ps1" , i . FilePath ) ;
226
+ } ,
227
+ ( i ) =>
228
+ {
229
+ Assert . Equal ( "My-Function" , i . SymbolName ) ;
230
+ Assert . EndsWith ( FindsFunctionDefinitionData . SourceDetails . File , i . FilePath ) ;
231
+ } ) ;
234
232
}
235
233
236
234
[ Fact ]
237
235
public async Task FindsFunctionDefinitionInWorkspace ( )
238
236
{
239
- workspace . WorkspacePath = TestUtilities . GetSharedPath ( "References" ) ;
240
- SymbolReference definitionResult = await GetDefinition ( FindsFunctionDefinitionInWorkspaceData . SourceDetails ) . ConfigureAwait ( true ) ;
241
- Assert . EndsWith ( "ReferenceFileE.ps1" , definitionResult . FilePath ) ;
242
- Assert . Equal ( "My-FunctionInFileE" , definitionResult . SymbolName ) ;
237
+ SymbolReference symbol = await GetDefinition ( FindsFunctionDefinitionInWorkspaceData . SourceDetails ) . ConfigureAwait ( true ) ;
238
+ Assert . EndsWith ( "ReferenceFileE.ps1" , symbol . FilePath ) ;
239
+ Assert . Equal ( "My-FunctionInFileE" , symbol . SymbolName ) ;
243
240
}
244
241
245
242
[ Fact ]
0 commit comments