Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic tokens tests: Use Linq instead #8256

Merged
merged 5 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,12 @@ public async Task VerifyGetClassificationsAsync(IEnumerable<ClassificationSpan>
var actualClassifications = await GetClassificationsAsync(cancellationToken);
var actualArray = actualClassifications.ToArray();
var expectedArray = expectedClassifications.ToArray();
var actualOffset = 0;

for (var i = 0; i < expectedArray.Length; i++)
for (var i = 0; i < actualArray.Length; i++)
{
var actualClassification = actualArray[i+actualOffset];
var actualClassification = actualArray[i];
var expectedClassification = expectedArray[i];

if (actualClassification.ClassificationType.BaseTypes.Count() == 0 &&
actualClassification.ClassificationType is ILayeredClassificationType layeredClassificationType &&
layeredClassificationType.Layer == ClassificationLayer.Syntactic)
{
// Don't check purely syntactic classifications, we're gonna try this again.
actualOffset++;
i--;
continue;
}

if (actualClassification.ClassificationType.BaseTypes.Count() > 1)
{
Assert.Equal(expectedClassification, actualClassification, ClassificationTypeComparer.Instance);
Expand All @@ -128,7 +117,7 @@ actualClassification.ClassificationType is ILayeredClassificationType layeredCla
}
}

Assert.Equal(expectedArray.Length, actualArray.Length - actualOffset);
Assert.Equal(expectedArray.Length, actualArray.Length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert is not doing anything any more: If the lengths weren't equal, we would have got index out of range exceptions on line 104/5.

I think this should be moved in front of the loop, just for good measure, and to provide a little more information than an index out of range exception would, should it ever fail.

ryanbrandenburg marked this conversation as resolved.
Show resolved Hide resolved
}

public async Task<IEnumerable<ClassificationSpan>> GetClassificationsAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0,1,RazorTransition,
0,1,RazorTransition,
1,8,RazorDirective,
10,19,class name,
33,1,HTML Tag Delimiter,
Expand Down Expand Up @@ -26,6 +26,7 @@
113,1,HTML Tag Delimiter,
124,1,HTML Tag Delimiter,
125,7,RazorComponentElement,
132,1,HTML Tag Delimiter,
133,1,HTML Tag Delimiter,
134,1,HTML Tag Delimiter,
141,1,HTML Tag Delimiter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0,1,RazorTransition,
0,1,RazorTransition,
1,4,RazorDirective,
6,10,string,
20,1,HTML Tag Delimiter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0,1,RazorTransition,
0,1,RazorTransition,
1,4,RazorDirective,
6,3,string,
13,1,HTML Tag Delimiter,
Expand Down Expand Up @@ -27,5 +27,6 @@
141,4,HTML Attribute Value,
145,5,HTML Attribute Value,
150,1,HTML Attribute Value,
151,1,HTML Tag Delimiter,
152,1,HTML Tag Delimiter,
153,1,HTML Tag Delimiter,
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
101,1,operator,
102,7,identifier,
109,1,HTML Attribute Value,
110,1,HTML Tag Delimiter,
111,1,HTML Tag Delimiter,
112,1,HTML Tag Delimiter,
115,1,HTML Tag Delimiter,
Expand Down