33
44using System ;
55using System . Collections . Generic ;
6- using System . IO ;
76using System . Linq ;
87using System . Management . Automation ;
98using System . Runtime . InteropServices ;
@@ -38,7 +37,10 @@ public class SymbolsServiceTests : IDisposable
3837 public SymbolsServiceTests ( )
3938 {
4039 psesHost = PsesHostFactory . Create ( NullLoggerFactory . Instance ) ;
41- workspace = new WorkspaceService ( NullLoggerFactory . Instance ) ;
40+ workspace = new WorkspaceService ( NullLoggerFactory . Instance )
41+ {
42+ WorkspacePath = TestUtilities . GetSharedPath ( "References" )
43+ } ;
4244 symbolsService = new SymbolsService (
4345 NullLoggerFactory . Instance ,
4446 psesHost ,
@@ -80,7 +82,7 @@ private Task<ParameterSetSignatures> GetParamSetSignatures(ScriptRegion scriptRe
8082 scriptRegion . StartColumnNumber ) ;
8183 }
8284
83- private async Task < SymbolReference > GetDefinition ( ScriptRegion scriptRegion )
85+ private async Task < IEnumerable < SymbolReference > > GetDefinitions ( ScriptRegion scriptRegion )
8486 {
8587 ScriptFile scriptFile = GetScriptFile ( scriptRegion ) ;
8688
@@ -92,9 +94,13 @@ private async Task<SymbolReference> GetDefinition(ScriptRegion scriptRegion)
9294
9395 Assert . NotNull ( symbol ) ;
9496
95- IEnumerable < SymbolReference > refs = await symbolsService . GetDefinitionOfSymbolAsync ( scriptFile , symbol ) . ConfigureAwait ( true ) ;
97+ return await symbolsService . GetDefinitionOfSymbolAsync ( scriptFile , symbol ) . ConfigureAwait ( true ) ;
98+ }
9699
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 ( ) ;
98104 }
99105
100106 private async Task < List < SymbolReference > > GetReferences ( ScriptRegion scriptRegion )
@@ -156,11 +162,11 @@ public async Task FindsFunctionDefinition()
156162 {
157163 SymbolReference symbol = await GetDefinition ( FindsFunctionDefinitionData . SourceDetails ) . ConfigureAwait ( true ) ;
158164 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 ) ;
162166 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 ) ;
164170 }
165171
166172 [ Fact ]
@@ -173,11 +179,11 @@ await psesHost.ExecutePSCommandAsync(
173179 CancellationToken . None ) . ConfigureAwait ( true ) ;
174180
175181 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 ) ;
178183 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 ) ;
181187 }
182188
183189 [ Fact ]
@@ -209,37 +215,28 @@ await psesHost.ExecutePSCommandAsync(
209215 }
210216
211217 [ Fact ]
212- public async Task FindsFunctionDefinitionInDotSourceReference ( )
218+ public async Task FindsFunctionDefinitionsInWorkspace ( )
213219 {
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+ } ) ;
234232 }
235233
236234 [ Fact ]
237235 public async Task FindsFunctionDefinitionInWorkspace ( )
238236 {
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 ) ;
243240 }
244241
245242 [ Fact ]
0 commit comments