Skip to content

Commit 09d632c

Browse files
author
Justin Chen
committed
used Assert.Collection instead of Assert.Single
1 parent 6c21195 commit 09d632c

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/PowerShellEditorServices/Services/TextDocument/Handlers/PsesSemanticTokensHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public PsesSemanticTokensHandler(ILogger<PsesSemanticTokensHandler> logger, Work
4545
protected override Task Tokenize(SemanticTokensBuilder builder, ITextDocumentIdentifierParams identifier,
4646
CancellationToken cancellationToken)
4747
{
48-
ScriptFile file = _workspaceService.GetFile(DocumentUri.GetFileSystemPath(identifier));
48+
ScriptFile file = _workspaceService.GetFile(identifier.TextDocument.Uri);
4949
foreach (Token token in file.ScriptTokens)
5050
{
5151
PushToken(token, builder);

test/PowerShellEditorServices.Test/Language/SemanticTokenTest.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1212
using Microsoft.PowerShell.EditorServices.Handlers;
1313
using OmniSharp.Extensions.LanguageServer.Protocol;
14-
using OmniSharp.Extensions.LanguageServer.Protocol.Document.Proposals;
1514
using OmniSharp.Extensions.LanguageServer.Protocol.Models.Proposals;
1615
using Xunit;
1716

@@ -42,20 +41,20 @@ function Get-Sum {
4241
case "function":
4342
case "param":
4443
case "return":
45-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Keyword, mappedTokens[0].Type));
44+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Keyword == sToken.Type);
4645
break;
4746
case "Get-Sum":
48-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Function, mappedTokens[0].Type));
47+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Function == sToken.Type);
4948
break;
5049
case "$a":
5150
case "$b":
52-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Variable, mappedTokens[0].Type));
51+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Variable == sToken.Type);
5352
break;
5453
case "[int]":
55-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Type, mappedTokens[0].Type));
54+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Type == sToken.Type);
5655
break;
5756
case "+":
58-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Operator, mappedTokens[0].Type));
57+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Operator == sToken.Type);
5958
break;
6059
}
6160
}
@@ -73,8 +72,7 @@ public async Task TokenizesStringExpansion()
7372

7473
Token commandToken = scriptFile.ScriptTokens[0];
7574
List<SemanticToken> mappedTokens = new List<SemanticToken>(PsesSemanticTokensHandler.ConvertToSemanticTokens(commandToken));
76-
Assert.Single(mappedTokens);
77-
Assert.Equal(SemanticTokenType.Function, mappedTokens[0].Type);
75+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Function == sToken.Type);
7876

7977
Token stringExpandableToken = scriptFile.ScriptTokens[1];
8078
mappedTokens = new List<SemanticToken>(PsesSemanticTokensHandler.ConvertToSemanticTokens(stringExpandableToken));
@@ -105,10 +103,10 @@ function Get-A*A {
105103
switch (t.Text)
106104
{
107105
case "function":
108-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Keyword, mappedTokens[0].Type));
106+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Keyword == sToken.Type);
109107
break;
110108
case "Get-A*A":
111-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Function, mappedTokens[0].Type));
109+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Function == sToken.Type);
112110
break;
113111
}
114112
}
@@ -130,10 +128,10 @@ public async Task RecognizesArrayMemberInExpandableString()
130128
switch (t.Text)
131129
{
132130
case "$Array":
133-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Variable, mappedTokens[0].Type));
131+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Variable == sToken.Type);
134132
break;
135133
case "Count":
136-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Member, mappedTokens[0].Type));
134+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Member == sToken.Type);
137135
break;
138136
}
139137
}
@@ -150,11 +148,11 @@ public async Task RecognizesCurlyQuotedString()
150148
Version.Parse("5.0"));
151149

152150
List<SemanticToken> mappedTokens = new List<SemanticToken>(PsesSemanticTokensHandler.ConvertToSemanticTokens(scriptFile.ScriptTokens[0]));
153-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.String, mappedTokens[0].Type));
151+
Assert.Single(mappedTokens, sToken => SemanticTokenType.String == sToken.Type);
154152
}
155153

156154
[Fact]
157-
public async Task RecognizeDoubleQuotedHereString()
155+
public async Task RecognizeEnum()
158156
{
159157
string text = @"
160158
enum MyEnum{
@@ -175,13 +173,13 @@ enum MyEnum{
175173
switch (t.Text)
176174
{
177175
case "enum":
178-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Keyword, mappedTokens[0].Type));
176+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Keyword == sToken.Type);
179177
break;
180178
case "MyEnum":
181179
case "one":
182180
case "two":
183181
case "three":
184-
Assert.Collection(mappedTokens, sToken => Assert.Equal(SemanticTokenType.Member, mappedTokens[0].Type));
182+
Assert.Single(mappedTokens, sToken => SemanticTokenType.Member == sToken.Type);
185183
break;
186184
}
187185
}

0 commit comments

Comments
 (0)