Skip to content

Commit f9310a2

Browse files
authored
Merge branch 'master' into tests-in-containing-symbol
2 parents ca3e321 + 7278aba commit f9310a2

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/OmniSharp.Roslyn.CSharp.Tests/SemanticHighlightFacts.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Threading.Tasks;
3+
using System.Windows.Input;
34
using Microsoft.CodeAnalysis.Text;
45
using OmniSharp.Models.SemanticHighlight;
56
using OmniSharp.Models.V2;
@@ -102,6 +103,93 @@ class C1
102103
);
103104
}
104105

106+
[Fact]
107+
public async Task SemanticHighlightWithAsyncEnumerable()
108+
{
109+
var testFile = new TestFile("a.cs", @"
110+
class C1
111+
{
112+
public async Task C2() {
113+
string s1 = ""hello"";
114+
await foreach (var x in e) { }
115+
string s2 = ""world"";
116+
}
117+
}");
118+
119+
var highlights = await GetSemanticHighlightsForFileAsync(testFile);
120+
121+
AssertSyntax(highlights, testFile.Content.Code, 0,
122+
Keyword("class"),
123+
ClassName("C1"),
124+
Punctuation("{"),
125+
Keyword("public"),
126+
Keyword("async"),
127+
Identifier("Task"),
128+
Method("C2"),
129+
Punctuation("("),
130+
Punctuation(")"),
131+
Punctuation("{"),
132+
Keyword("string"),
133+
Local("s1"),
134+
Operator("="),
135+
String("\"hello\""),
136+
Punctuation(";"),
137+
Keyword("await"),
138+
ControlKeyword("foreach"),
139+
Punctuation("("),
140+
Keyword("var"),
141+
Local("x"),
142+
ControlKeyword("in"),
143+
Identifier("e"),
144+
Punctuation(")"),
145+
Punctuation("{"),
146+
Punctuation("}"),
147+
Keyword("string"),
148+
Local("s2"),
149+
Operator("="),
150+
String("\"world\""),
151+
Punctuation(";"),
152+
Punctuation("}"),
153+
Punctuation("}")
154+
);
155+
}
156+
157+
[Fact]
158+
public async Task SemanticHighlightWithNullable()
159+
{
160+
var testFile = new TestFile("a.cs", @"
161+
class C1
162+
{
163+
string s1 = ""hello"";
164+
int[]? example;
165+
string s2 = ""world"";
166+
}");
167+
168+
var highlights = await GetSemanticHighlightsForFileAsync(testFile);
169+
170+
AssertSyntax(highlights, testFile.Content.Code, 0,
171+
Keyword("class"),
172+
ClassName("C1"),
173+
Punctuation("{"),
174+
Keyword("string"),
175+
Field("s1"),
176+
Operator("="),
177+
String("\"hello\""),
178+
Punctuation(";"),
179+
Keyword("int"),
180+
Punctuation("["),
181+
Punctuation("]"),
182+
Operator("?"),
183+
Field("example"),
184+
Punctuation(";"),
185+
Keyword("string"),
186+
Field("s2"),
187+
Operator("="),
188+
String("\"world\""),
189+
Punctuation(";"),
190+
Punctuation("}")
191+
);
192+
}
105193

106194
[Fact]
107195
public async Task SemanticHighlightStaticModifiers()
@@ -208,11 +296,14 @@ private static void AssertSyntax(SemanticHighlightSpan[] highlights, string code
208296
Assert.Equal(expectedTokens.Length, highlights.Length);
209297
}
210298

299+
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Method(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.MethodName, text, modifiers);
300+
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Local(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.LocalName, text, modifiers);
211301
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) ClassName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ClassName, text, modifiers);
212302
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Field(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.FieldName, text, modifiers);
213303
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Identifier(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Identifier, text, modifiers);
214304
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) NamespaceName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.NamespaceName, text, modifiers);
215305
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Keyword(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Keyword, text, modifiers);
306+
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) ControlKeyword(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ControlKeyword, text, modifiers);
216307
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Number(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.NumericLiteral, text, modifiers);
217308
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Operator(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Operator, text, modifiers);
218309
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Punctuation(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Punctuation, text, modifiers);

0 commit comments

Comments
 (0)