Skip to content

Commit 9011949

Browse files
committed
update document symbols test
1 parent 155cdb4 commit 9011949

File tree

4 files changed

+85
-9
lines changed

4 files changed

+85
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file represents a script with a DSC configuration
2+
configuration AConfiguration {
3+
Node "TEST-PC" {}
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
5+
6+
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Symbols
7+
{
8+
public static class FindSymbolsInDSCFile
9+
{
10+
public static readonly ScriptRegion SourceDetails =
11+
new(
12+
file: TestUtilities.NormalizePath("Symbols/DSCFile.ps1"),
13+
text: string.Empty,
14+
startLineNumber: 0,
15+
startColumnNumber: 0,
16+
startOffset: 0,
17+
endLineNumber: 0,
18+
endColumnNumber: 0,
19+
endOffset: 0);
20+
}
21+
}

test/PowerShellEditorServices.Test.Shared/Symbols/MultipleSymbols.ps1

+15-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,22 @@ function AnAdvancedFunction {
2222

2323
workflow AWorkflow {}
2424

25-
Configuration AConfiguration {
26-
Node "TEST-PC" {}
25+
class AClass {
26+
[string]$AProperty
27+
28+
AClass([string]$AParameter) {
29+
30+
}
31+
32+
[void]AMethod([string]$param1, [int]$param2, $param3) {
33+
34+
}
35+
}
36+
37+
enum AEnum {
38+
AValue = 0
2739
}
2840

2941
AFunction
3042
1..3 | AFilter
31-
AnAdvancedFunction
43+
AnAdvancedFunction

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

+45-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Management.Automation;
9+
using System.Runtime.InteropServices;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Microsoft.Extensions.Logging.Abstractions;
@@ -32,6 +33,7 @@ public class SymbolsServiceTests : IDisposable
3233
private readonly PsesInternalHost psesHost;
3334
private readonly WorkspaceService workspace;
3435
private readonly SymbolsService symbolsService;
36+
private static readonly bool s_isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
3537

3638
public SymbolsServiceTests()
3739
{
@@ -287,6 +289,11 @@ public void FindsSymbolsInFile()
287289
Assert.Equal(4, symbolsResult.Count(symbolReference => symbolReference.SymbolType == SymbolType.Function));
288290
Assert.Equal(3, symbolsResult.Count(symbolReference => symbolReference.SymbolType == SymbolType.Variable));
289291
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));
290297

291298
SymbolReference firstFunctionSymbol = symbolsResult.First(r => r.SymbolType == SymbolType.Function);
292299
Assert.Equal("AFunction", firstFunctionSymbol.SymbolName);
@@ -303,12 +310,44 @@ public void FindsSymbolsInFile()
303310
Assert.Equal(23, firstWorkflowSymbol.ScriptRegion.StartLineNumber);
304311
Assert.Equal(1, firstWorkflowSymbol.ScriptRegion.StartColumnNumber);
305312

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);
312351
}
313352

314353
[Fact]

0 commit comments

Comments
 (0)