Skip to content

Commit 1829093

Browse files
committed
Fix the rest of the symbols service tests
1 parent aa6bfc7 commit 1829093

File tree

1 file changed

+140
-141
lines changed

1 file changed

+140
-141
lines changed

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

Lines changed: 140 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -737,175 +737,174 @@ public void FindsSymbolsInFile()
737737
{
738738
IEnumerable<SymbolReference> symbols = FindSymbolsInFile(FindSymbolsInMultiSymbolFile.SourceDetails);
739739

740-
Assert.Equal(7, symbols.Count(symbolReference => symbolReference.SymbolType == SymbolType.Function));
741-
Assert.Equal(12, symbols.Count(symbolReference => symbolReference.SymbolType == SymbolType.Variable));
740+
Assert.Equal(7, symbols.Count(i => i.SymbolType == SymbolType.Function));
741+
Assert.Equal(8, symbols.Count(i => i.SymbolType == SymbolType.Variable));
742+
Assert.Equal(4, symbols.Count(i => i.SymbolType == SymbolType.Parameter));
743+
Assert.Equal(12, symbols.Count(i => SymbolTypeUtils.SymbolTypeMatches(SymbolType.Variable, i.SymbolType)));
744+
745+
SymbolReference symbol = symbols.First(i => i.SymbolType == SymbolType.Function);
746+
Assert.Equal("AFunction", symbol.SymbolName);
747+
Assert.Equal("function AFunction ()", symbol.DisplayString);
748+
Assert.True(symbol.IsDeclaration);
742749

743-
SymbolReference firstFunctionSymbol = symbols.First(r => r.SymbolType == SymbolType.Function);
744-
Assert.Equal("AFunction", firstFunctionSymbol.SymbolName);
745-
AssertIsRegion(firstFunctionSymbol.NameRegion, 7, 10, 7, 19);
750+
symbol = symbols.First(i => i.SymbolName == "AFilter");
751+
Assert.Equal("filter AFilter ()", symbol.DisplayString);
752+
Assert.True(symbol.IsDeclaration);
746753

747-
SymbolReference lastVariableSymbol = symbols.Last(r => r.SymbolType == SymbolType.Variable);
748-
Assert.Equal("$param3", lastVariableSymbol.SymbolName);
749-
AssertIsRegion(lastVariableSymbol.NameRegion, 32, 50, 32, 57);
754+
symbol = symbols.Last(i => i.SymbolType == SymbolType.Variable);
755+
Assert.Equal("$nestedVar", symbol.SymbolName);
756+
Assert.Equal("$nestedVar", symbol.DisplayString);
757+
Assert.False(symbol.IsDeclaration);
758+
AssertIsRegion(symbol.NameRegion, 16, 29, 16, 39);
750759

751-
SymbolReference firstWorkflowSymbol =
752-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Workflow));
753-
Assert.Equal("AWorkflow", firstWorkflowSymbol.SymbolName);
754-
AssertIsRegion(firstWorkflowSymbol.NameRegion, 23, 10, 23, 19);
760+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Workflow));
761+
Assert.Equal("AWorkflow", symbol.SymbolName);
762+
Assert.Equal("workflow AWorkflow ()", symbol.DisplayString);
763+
Assert.True(symbol.IsDeclaration);
755764

756-
SymbolReference firstClassSymbol =
757-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Class));
758-
Assert.Equal("AClass", firstClassSymbol.SymbolName);
759-
AssertIsRegion(firstClassSymbol.NameRegion, 25, 7, 25, 13);
765+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Class));
766+
Assert.Equal("AClass", symbol.SymbolName);
767+
Assert.Equal("class AClass { }", symbol.DisplayString);
768+
Assert.True(symbol.IsDeclaration);
760769

761-
SymbolReference firstPropertySymbol =
762-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Property));
763-
Assert.Equal("AClass.AProperty", firstPropertySymbol.SymbolName);
764-
AssertIsRegion(firstPropertySymbol.NameRegion, 26, 13, 26, 23);
770+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Property));
771+
Assert.Equal("$AProperty", symbol.SymbolName);
772+
Assert.Equal("[string] $AProperty", symbol.DisplayString);
773+
Assert.True(symbol.IsDeclaration);
765774

766-
SymbolReference firstConstructorSymbol =
767-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Constructor));
768-
Assert.Equal("AClass.AClass([string]$AParameter)", firstConstructorSymbol.SymbolName);
769-
AssertIsRegion(firstConstructorSymbol.NameRegion, 28, 5, 28, 11);
775+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Constructor));
776+
Assert.Equal("AClass", symbol.SymbolName);
777+
Assert.Equal("AClass([string]$AParameter)", symbol.DisplayString);
778+
Assert.True(symbol.IsDeclaration);
770779

771-
SymbolReference firstMethodSymbol =
772-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Method));
773-
Assert.Equal("AClass.AMethod([string]$param1, [int]$param2, $param3)", firstMethodSymbol.SymbolName);
774-
AssertIsRegion(firstMethodSymbol.NameRegion, 32, 11, 32, 18);
780+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Method));
781+
Assert.Equal("AMethod", symbol.SymbolName);
782+
Assert.Equal("void AMethod([string]$param1, [int]$param2, $param3)", symbol.DisplayString);
783+
Assert.True(symbol.IsDeclaration);
775784

776-
SymbolReference firstEnumSymbol =
777-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Enum));
778-
Assert.Equal("AEnum", firstEnumSymbol.SymbolName);
779-
AssertIsRegion(firstEnumSymbol.NameRegion, 37, 6, 37, 11);
785+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Enum));
786+
Assert.Equal("AEnum", symbol.SymbolName);
787+
Assert.Equal("enum AEnum { }", symbol.DisplayString);
788+
Assert.True(symbol.IsDeclaration);
780789

781-
SymbolReference firstEnumMemberSymbol =
782-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.EnumMember));
783-
Assert.Equal("AEnum.AValue", firstEnumMemberSymbol.SymbolName);
784-
AssertIsRegion(firstEnumMemberSymbol.NameRegion, 38, 5, 38, 11);
790+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.EnumMember));
791+
Assert.Equal("$AValue", symbol.SymbolName);
792+
Assert.Equal("AValue", symbol.DisplayString);
793+
Assert.True(symbol.IsDeclaration);
785794
}
786795

787796
[Fact]
788797
public void FindsSymbolsWithNewLineInFile()
789798
{
790799
IEnumerable<SymbolReference> symbols = FindSymbolsInFile(FindSymbolsInNewLineSymbolFile.SourceDetails);
791800

792-
SymbolReference firstFunctionSymbol =
793-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Function));
794-
Assert.Equal("returnTrue", firstFunctionSymbol.SymbolName);
795-
AssertIsRegion(firstFunctionSymbol.NameRegion, 2, 1, 2, 11);
796-
AssertIsRegion(firstFunctionSymbol.ScriptRegion, 1, 1, 4, 2);
797-
798-
SymbolReference firstClassSymbol =
799-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Class));
800-
Assert.Equal("NewLineClass", firstClassSymbol.SymbolName);
801-
AssertIsRegion(firstClassSymbol.NameRegion, 7, 1, 7, 13);
802-
AssertIsRegion(firstClassSymbol.ScriptRegion, 6, 1, 23, 2);
803-
804-
SymbolReference firstConstructorSymbol =
805-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Constructor));
806-
Assert.Equal("NewLineClass.NewLineClass()", firstConstructorSymbol.SymbolName);
807-
AssertIsRegion(firstConstructorSymbol.NameRegion, 8, 5, 8, 17);
808-
AssertIsRegion(firstConstructorSymbol.ScriptRegion, 8, 5, 10, 6);
809-
810-
SymbolReference firstPropertySymbol =
811-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Property));
812-
Assert.Equal("NewLineClass.SomePropWithDefault", firstPropertySymbol.SymbolName);
813-
AssertIsRegion(firstPropertySymbol.NameRegion, 15, 5, 15, 25);
814-
AssertIsRegion(firstPropertySymbol.ScriptRegion, 12, 5, 15, 40);
815-
816-
SymbolReference firstMethodSymbol =
817-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Method));
818-
Assert.Equal("NewLineClass.MyClassMethod([MyNewLineEnum]$param1)", firstMethodSymbol.SymbolName);
819-
AssertIsRegion(firstMethodSymbol.NameRegion, 20, 5, 20, 18);
820-
AssertIsRegion(firstMethodSymbol.ScriptRegion, 17, 5, 22, 6);
821-
822-
SymbolReference firstEnumSymbol =
823-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.Enum));
824-
Assert.Equal("MyNewLineEnum", firstEnumSymbol.SymbolName);
825-
AssertIsRegion(firstEnumSymbol.NameRegion, 26, 1, 26, 14);
826-
AssertIsRegion(firstEnumSymbol.ScriptRegion, 25, 1, 28, 2);
827-
828-
SymbolReference firstEnumMemberSymbol =
829-
Assert.Single(symbols.Where(symbolReference => symbolReference.SymbolType == SymbolType.EnumMember));
830-
Assert.Equal("MyNewLineEnum.First", firstEnumMemberSymbol.SymbolName);
831-
AssertIsRegion(firstEnumMemberSymbol.NameRegion, 27, 5, 27, 10);
832-
AssertIsRegion(firstEnumMemberSymbol.ScriptRegion, 27, 5, 27, 10);
801+
SymbolReference symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Function));
802+
Assert.Equal("returnTrue", symbol.SymbolName);
803+
AssertIsRegion(symbol.NameRegion, 2, 1, 2, 11);
804+
AssertIsRegion(symbol.ScriptRegion, 1, 1, 4, 2);
805+
806+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Class));
807+
Assert.Equal("NewLineClass", symbol.SymbolName);
808+
AssertIsRegion(symbol.NameRegion, 7, 1, 7, 13);
809+
AssertIsRegion(symbol.ScriptRegion, 6, 1, 23, 2);
810+
811+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Constructor));
812+
Assert.Equal("NewLineClass", symbol.SymbolName);
813+
AssertIsRegion(symbol.NameRegion, 8, 5, 8, 17);
814+
AssertIsRegion(symbol.ScriptRegion, 8, 5, 10, 6);
815+
816+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Property));
817+
Assert.Equal("$SomePropWithDefault", symbol.SymbolName);
818+
AssertIsRegion(symbol.NameRegion, 15, 5, 15, 25);
819+
AssertIsRegion(symbol.ScriptRegion, 12, 5, 15, 40);
820+
821+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Method));
822+
Assert.Equal("MyClassMethod", symbol.SymbolName);
823+
Assert.Equal("string MyClassMethod([MyNewLineEnum]$param1)", symbol.DisplayString);
824+
AssertIsRegion(symbol.NameRegion, 20, 5, 20, 18);
825+
AssertIsRegion(symbol.ScriptRegion, 17, 5, 22, 6);
826+
827+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.Enum));
828+
Assert.Equal("MyNewLineEnum", symbol.SymbolName);
829+
AssertIsRegion(symbol.NameRegion, 26, 1, 26, 14);
830+
AssertIsRegion(symbol.ScriptRegion, 25, 1, 28, 2);
831+
832+
symbol = Assert.Single(symbols.Where(i => i.SymbolType == SymbolType.EnumMember));
833+
Assert.Equal("$First", symbol.SymbolName);
834+
AssertIsRegion(symbol.NameRegion, 27, 5, 27, 10);
835+
AssertIsRegion(symbol.ScriptRegion, 27, 5, 27, 10);
833836
}
834837

835838
[SkippableFact]
836839
public void FindsSymbolsInDSCFile()
837840
{
838841
Skip.If(!s_isWindows, "DSC only works properly on Windows.");
839842

840-
IEnumerable<SymbolReference> symbolsResult = FindSymbolsInFile(FindSymbolsInDSCFile.SourceDetails);
841-
842-
Assert.Single(symbolsResult.Where(symbolReference => symbolReference.SymbolType == SymbolType.Configuration));
843-
SymbolReference firstConfigurationSymbol = symbolsResult.First(r => r.SymbolType == SymbolType.Configuration);
844-
Assert.Equal("AConfiguration", firstConfigurationSymbol.SymbolName);
845-
Assert.Equal(2, firstConfigurationSymbol.ScriptRegion.StartLineNumber);
846-
Assert.Equal(15, firstConfigurationSymbol.ScriptRegion.StartColumnNumber);
843+
IEnumerable<SymbolReference> symbols = FindSymbolsInFile(FindSymbolsInDSCFile.SourceDetails);
844+
SymbolReference symbol = Assert.Single(symbols, i => i.SymbolType == SymbolType.Configuration);
845+
Assert.Equal("AConfiguration", symbol.SymbolName);
846+
Assert.Equal(2, symbol.ScriptRegion.StartLineNumber);
847+
Assert.Equal(15, symbol.ScriptRegion.StartColumnNumber);
847848
}
848849

849850
[Fact]
850851
public void FindsSymbolsInPesterFile()
851852
{
852-
IEnumerable<PesterSymbolReference> symbolsResult = FindSymbolsInFile(FindSymbolsInPesterFile.SourceDetails).OfType<PesterSymbolReference>();
853-
Assert.Equal(12, symbolsResult.Count(r => r.SymbolType == SymbolType.Function));
854-
855-
Assert.Equal(1, symbolsResult.Count(r => r.Command == PesterCommandType.Describe));
856-
SymbolReference firstDescribeSymbol = symbolsResult.First(r => r.Command == PesterCommandType.Describe);
857-
Assert.Equal("Describe \"Testing Pester symbols\"", firstDescribeSymbol.SymbolName);
858-
Assert.Equal(9, firstDescribeSymbol.ScriptRegion.StartLineNumber);
859-
Assert.Equal(1, firstDescribeSymbol.ScriptRegion.StartColumnNumber);
860-
861-
Assert.Equal(1, symbolsResult.Count(r => r.Command == PesterCommandType.Context));
862-
SymbolReference firstContextSymbol = symbolsResult.First(r => r.Command == PesterCommandType.Context);
863-
Assert.Equal("Context \"When a Pester file is given\"", firstContextSymbol.SymbolName);
864-
Assert.Equal(10, firstContextSymbol.ScriptRegion.StartLineNumber);
865-
Assert.Equal(5, firstContextSymbol.ScriptRegion.StartColumnNumber);
866-
867-
Assert.Equal(4, symbolsResult.Count(r => r.Command == PesterCommandType.It));
868-
SymbolReference lastItSymbol = symbolsResult.Last(r => r.Command == PesterCommandType.It);
869-
Assert.Equal("It \"Should return setup and teardown symbols\"", lastItSymbol.SymbolName);
870-
Assert.Equal(31, lastItSymbol.ScriptRegion.StartLineNumber);
871-
Assert.Equal(9, lastItSymbol.ScriptRegion.StartColumnNumber);
872-
873-
Assert.Equal(1, symbolsResult.Count(r => r.Command == PesterCommandType.BeforeDiscovery));
874-
SymbolReference firstBeforeDiscoverySymbol = symbolsResult.First(r => r.Command == PesterCommandType.BeforeDiscovery);
875-
Assert.Equal("BeforeDiscovery", firstBeforeDiscoverySymbol.SymbolName);
876-
Assert.Equal(1, firstBeforeDiscoverySymbol.ScriptRegion.StartLineNumber);
877-
Assert.Equal(1, firstBeforeDiscoverySymbol.ScriptRegion.StartColumnNumber);
878-
879-
Assert.Equal(2, symbolsResult.Count(r => r.Command == PesterCommandType.BeforeAll));
880-
SymbolReference lastBeforeAllSymbol = symbolsResult.Last(r => r.Command == PesterCommandType.BeforeAll);
881-
Assert.Equal("BeforeAll", lastBeforeAllSymbol.SymbolName);
882-
Assert.Equal(11, lastBeforeAllSymbol.ScriptRegion.StartLineNumber);
883-
Assert.Equal(9, lastBeforeAllSymbol.ScriptRegion.StartColumnNumber);
884-
885-
Assert.Equal(1, symbolsResult.Count(r => r.Command == PesterCommandType.BeforeEach));
886-
SymbolReference firstBeforeEachSymbol = symbolsResult.First(r => r.Command == PesterCommandType.BeforeEach);
887-
Assert.Equal("BeforeEach", firstBeforeEachSymbol.SymbolName);
888-
Assert.Equal(15, firstBeforeEachSymbol.ScriptRegion.StartLineNumber);
889-
Assert.Equal(9, firstBeforeEachSymbol.ScriptRegion.StartColumnNumber);
890-
891-
Assert.Equal(1, symbolsResult.Count(r => r.Command == PesterCommandType.AfterEach));
892-
SymbolReference firstAfterEachSymbol = symbolsResult.First(r => r.Command == PesterCommandType.AfterEach);
893-
Assert.Equal("AfterEach", firstAfterEachSymbol.SymbolName);
894-
Assert.Equal(35, firstAfterEachSymbol.ScriptRegion.StartLineNumber);
895-
Assert.Equal(9, firstAfterEachSymbol.ScriptRegion.StartColumnNumber);
896-
897-
Assert.Equal(1, symbolsResult.Count(r => r.Command == PesterCommandType.AfterAll));
898-
SymbolReference firstAfterAllSymbol = symbolsResult.First(r => r.Command == PesterCommandType.AfterAll);
899-
Assert.Equal("AfterAll", firstAfterAllSymbol.SymbolName);
900-
Assert.Equal(40, firstAfterAllSymbol.ScriptRegion.StartLineNumber);
901-
Assert.Equal(5, firstAfterAllSymbol.ScriptRegion.StartColumnNumber);
902-
}
903-
904-
[Fact]
905-
public void LangServerFindsSymbolsInPSDFile()
906-
{
907-
IEnumerable<SymbolReference> symbolsResult = FindSymbolsInFile(FindSymbolsInPSDFile.SourceDetails);
908-
Assert.Equal(3, symbolsResult.Count());
853+
IEnumerable<PesterSymbolReference> symbols = FindSymbolsInFile(FindSymbolsInPesterFile.SourceDetails).OfType<PesterSymbolReference>();
854+
Assert.Equal(12, symbols.Count(i => i.SymbolType == SymbolType.Function));
855+
856+
SymbolReference symbol = Assert.Single(symbols, i => i.Command == PesterCommandType.Describe);
857+
Assert.Equal("Describe \"Testing Pester symbols\"", symbol.SymbolName);
858+
Assert.Equal(9, symbol.ScriptRegion.StartLineNumber);
859+
Assert.Equal(1, symbol.ScriptRegion.StartColumnNumber);
860+
861+
symbol = Assert.Single(symbols, i => i.Command == PesterCommandType.Context);
862+
Assert.Equal("Context \"When a Pester file is given\"", symbol.SymbolName);
863+
Assert.Equal(10, symbol.ScriptRegion.StartLineNumber);
864+
Assert.Equal(5, symbol.ScriptRegion.StartColumnNumber);
865+
866+
Assert.Equal(4, symbols.Count(i => i.Command == PesterCommandType.It));
867+
symbol = symbols.Last(i => i.Command == PesterCommandType.It);
868+
Assert.Equal("It \"Should return setup and teardown symbols\"", symbol.SymbolName);
869+
Assert.Equal(31, symbol.ScriptRegion.StartLineNumber);
870+
Assert.Equal(9, symbol.ScriptRegion.StartColumnNumber);
871+
872+
symbol = Assert.Single(symbols, i => i.Command == PesterCommandType.BeforeDiscovery);
873+
Assert.Equal("BeforeDiscovery", symbol.SymbolName);
874+
Assert.Equal(1, symbol.ScriptRegion.StartLineNumber);
875+
Assert.Equal(1, symbol.ScriptRegion.StartColumnNumber);
876+
877+
Assert.Equal(2, symbols.Count(i => i.Command == PesterCommandType.BeforeAll));
878+
symbol = symbols.Last(i => i.Command == PesterCommandType.BeforeAll);
879+
Assert.Equal("BeforeAll", symbol.SymbolName);
880+
Assert.Equal(11, symbol.ScriptRegion.StartLineNumber);
881+
Assert.Equal(9, symbol.ScriptRegion.StartColumnNumber);
882+
883+
symbol = Assert.Single(symbols, i => i.Command == PesterCommandType.BeforeEach);
884+
Assert.Equal("BeforeEach", symbol.SymbolName);
885+
Assert.Equal(15, symbol.ScriptRegion.StartLineNumber);
886+
Assert.Equal(9, symbol.ScriptRegion.StartColumnNumber);
887+
888+
symbol = Assert.Single(symbols, i => i.Command == PesterCommandType.AfterEach);
889+
Assert.Equal("AfterEach", symbol.SymbolName);
890+
Assert.Equal(35, symbol.ScriptRegion.StartLineNumber);
891+
Assert.Equal(9, symbol.ScriptRegion.StartColumnNumber);
892+
893+
symbol = Assert.Single(symbols, i => i.Command == PesterCommandType.AfterAll);
894+
Assert.Equal("AfterAll", symbol.SymbolName);
895+
Assert.Equal(40, symbol.ScriptRegion.StartLineNumber);
896+
Assert.Equal(5, symbol.ScriptRegion.StartColumnNumber);
897+
}
898+
899+
[Fact]
900+
public void FindsSymbolsInPSDFile()
901+
{
902+
IEnumerable<SymbolReference> symbols = FindSymbolsInFile(FindSymbolsInPSDFile.SourceDetails);
903+
Assert.All(symbols, i => Assert.Equal(SymbolType.HashtableKey, i.SymbolType));
904+
Assert.Collection(symbols,
905+
i => Assert.Equal("property1", i.SymbolName),
906+
i => Assert.Equal("property2", i.SymbolName),
907+
i => Assert.Equal("property3", i.SymbolName));
909908
}
910909

911910
[Fact]

0 commit comments

Comments
 (0)