6
6
using System . IO ;
7
7
using System . Linq ;
8
8
using System . Management . Automation ;
9
+ using System . Runtime . InteropServices ;
9
10
using System . Threading ;
10
11
using System . Threading . Tasks ;
11
12
using Microsoft . Extensions . Logging . Abstractions ;
@@ -32,6 +33,7 @@ public class SymbolsServiceTests : IDisposable
32
33
private readonly PsesInternalHost psesHost ;
33
34
private readonly WorkspaceService workspace ;
34
35
private readonly SymbolsService symbolsService ;
36
+ private static readonly bool s_isWindows = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
35
37
36
38
public SymbolsServiceTests ( )
37
39
{
@@ -287,6 +289,11 @@ public void FindsSymbolsInFile()
287
289
Assert . Equal ( 4 , symbolsResult . Count ( symbolReference => symbolReference . SymbolType == SymbolType . Function ) ) ;
288
290
Assert . Equal ( 3 , symbolsResult . Count ( symbolReference => symbolReference . SymbolType == SymbolType . Variable ) ) ;
289
291
Assert . Single ( symbolsResult . Where ( symbolReference => symbolReference . SymbolType == SymbolType . Workflow ) ) ;
292
+ Assert . Single ( symbolsResult . Where ( symbolReference => symbolReference . SymbolType == SymbolType . Class ) ) ;
293
+ Assert . Equal ( 2 , symbolsResult . Count ( symbolReference => symbolReference . SymbolType == SymbolType . Property ) ) ;
294
+ Assert . Single ( symbolsResult . Where ( symbolReference => symbolReference . SymbolType == SymbolType . Constructor ) ) ;
295
+ Assert . Single ( symbolsResult . Where ( symbolReference => symbolReference . SymbolType == SymbolType . Method ) ) ;
296
+ Assert . Single ( symbolsResult . Where ( symbolReference => symbolReference . SymbolType == SymbolType . Enum ) ) ;
290
297
291
298
SymbolReference firstFunctionSymbol = symbolsResult . First ( r => r . SymbolType == SymbolType . Function ) ;
292
299
Assert . Equal ( "AFunction" , firstFunctionSymbol . SymbolName ) ;
@@ -303,12 +310,44 @@ public void FindsSymbolsInFile()
303
310
Assert . Equal ( 23 , firstWorkflowSymbol . ScriptRegion . StartLineNumber ) ;
304
311
Assert . Equal ( 1 , firstWorkflowSymbol . ScriptRegion . StartColumnNumber ) ;
305
312
306
- // TODO: Bring this back when we can use AstVisitor2 again (#276)
307
- //Assert.Equal(1, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Configuration).Count());
308
- //SymbolReference firstConfigurationSymbol = symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Configuration).First();
309
- //Assert.Equal("AConfiguration", firstConfigurationSymbol.SymbolName);
310
- //Assert.Equal(25, firstConfigurationSymbol.ScriptRegion.StartLineNumber);
311
- //Assert.Equal(1, firstConfigurationSymbol.ScriptRegion.StartColumnNumber);
313
+ SymbolReference firstClassSymbol = symbolsResult . First ( r => r . SymbolType == SymbolType . Class ) ;
314
+ Assert . Equal ( "AClass" , firstClassSymbol . SymbolName ) ;
315
+ Assert . Equal ( 25 , firstClassSymbol . ScriptRegion . StartLineNumber ) ;
316
+ Assert . Equal ( 1 , firstClassSymbol . ScriptRegion . StartColumnNumber ) ;
317
+
318
+ SymbolReference firstPropertySymbol = symbolsResult . First ( r => r . SymbolType == SymbolType . Property ) ;
319
+ Assert . Equal ( "AProperty" , firstPropertySymbol . SymbolName ) ;
320
+ Assert . Equal ( 26 , firstPropertySymbol . ScriptRegion . StartLineNumber ) ;
321
+ Assert . Equal ( 5 , firstPropertySymbol . ScriptRegion . StartColumnNumber ) ;
322
+
323
+ SymbolReference firstConstructorSymbol = symbolsResult . First ( r => r . SymbolType == SymbolType . Constructor ) ;
324
+ Assert . Equal ( "AClass([string]$AParameter)" , firstConstructorSymbol . SymbolName ) ;
325
+ Assert . Equal ( 28 , firstConstructorSymbol . ScriptRegion . StartLineNumber ) ;
326
+ Assert . Equal ( 5 , firstConstructorSymbol . ScriptRegion . StartColumnNumber ) ;
327
+
328
+ SymbolReference firstMethodSymbol = symbolsResult . First ( r => r . SymbolType == SymbolType . Method ) ;
329
+ Assert . Equal ( "AMethod([string]$param1, [int]$param2, $param3)" , firstMethodSymbol . SymbolName ) ;
330
+ Assert . Equal ( 32 , firstMethodSymbol . ScriptRegion . StartLineNumber ) ;
331
+ Assert . Equal ( 5 , firstMethodSymbol . ScriptRegion . StartColumnNumber ) ;
332
+
333
+ SymbolReference firstEnumSymbol = symbolsResult . First ( r => r . SymbolType == SymbolType . Enum ) ;
334
+ Assert . Equal ( "AEnum" , firstEnumSymbol . SymbolName ) ;
335
+ Assert . Equal ( 37 , firstEnumSymbol . ScriptRegion . StartLineNumber ) ;
336
+ Assert . Equal ( 1 , firstEnumSymbol . ScriptRegion . StartColumnNumber ) ;
337
+ }
338
+
339
+ [ SkippableFact ]
340
+ public void FindsSymbolsInDSCFile ( )
341
+ {
342
+ Skip . If ( ! s_isWindows , "DSC only works properly on Windows." ) ;
343
+
344
+ List < SymbolReference > symbolsResult = FindSymbolsInFile ( FindSymbolsInDSCFile . SourceDetails ) ;
345
+
346
+ Assert . Single ( symbolsResult . Where ( symbolReference => symbolReference . SymbolType == SymbolType . Configuration ) ) ;
347
+ SymbolReference firstConfigurationSymbol = symbolsResult . First ( r => r . SymbolType == SymbolType . Configuration ) ;
348
+ Assert . Equal ( "AConfiguration" , firstConfigurationSymbol . SymbolName ) ;
349
+ Assert . Equal ( 2 , firstConfigurationSymbol . ScriptRegion . StartLineNumber ) ;
350
+ Assert . Equal ( 1 , firstConfigurationSymbol . ScriptRegion . StartColumnNumber ) ;
312
351
}
313
352
314
353
[ Fact ]
0 commit comments