Skip to content

Commit

Permalink
Merge branch 'master' into tests-in-containing-symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
filipw authored May 11, 2020
2 parents ca3e321 + 7278aba commit f9310a2
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/SemanticHighlightFacts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Models.SemanticHighlight;
using OmniSharp.Models.V2;
Expand Down Expand Up @@ -102,6 +103,93 @@ class C1
);
}

[Fact]
public async Task SemanticHighlightWithAsyncEnumerable()
{
var testFile = new TestFile("a.cs", @"
class C1
{
public async Task C2() {
string s1 = ""hello"";
await foreach (var x in e) { }
string s2 = ""world"";
}
}");

var highlights = await GetSemanticHighlightsForFileAsync(testFile);

AssertSyntax(highlights, testFile.Content.Code, 0,
Keyword("class"),
ClassName("C1"),
Punctuation("{"),
Keyword("public"),
Keyword("async"),
Identifier("Task"),
Method("C2"),
Punctuation("("),
Punctuation(")"),
Punctuation("{"),
Keyword("string"),
Local("s1"),
Operator("="),
String("\"hello\""),
Punctuation(";"),
Keyword("await"),
ControlKeyword("foreach"),
Punctuation("("),
Keyword("var"),
Local("x"),
ControlKeyword("in"),
Identifier("e"),
Punctuation(")"),
Punctuation("{"),
Punctuation("}"),
Keyword("string"),
Local("s2"),
Operator("="),
String("\"world\""),
Punctuation(";"),
Punctuation("}"),
Punctuation("}")
);
}

[Fact]
public async Task SemanticHighlightWithNullable()
{
var testFile = new TestFile("a.cs", @"
class C1
{
string s1 = ""hello"";
int[]? example;
string s2 = ""world"";
}");

var highlights = await GetSemanticHighlightsForFileAsync(testFile);

AssertSyntax(highlights, testFile.Content.Code, 0,
Keyword("class"),
ClassName("C1"),
Punctuation("{"),
Keyword("string"),
Field("s1"),
Operator("="),
String("\"hello\""),
Punctuation(";"),
Keyword("int"),
Punctuation("["),
Punctuation("]"),
Operator("?"),
Field("example"),
Punctuation(";"),
Keyword("string"),
Field("s2"),
Operator("="),
String("\"world\""),
Punctuation(";"),
Punctuation("}")
);
}

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

private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Method(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.MethodName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Local(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.LocalName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) ClassName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ClassName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Field(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.FieldName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Identifier(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Identifier, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) NamespaceName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.NamespaceName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Keyword(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Keyword, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) ControlKeyword(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ControlKeyword, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Number(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.NumericLiteral, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Operator(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Operator, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Punctuation(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Punctuation, text, modifiers);
Expand Down

0 comments on commit f9310a2

Please sign in to comment.