提交 3b1d4b62 编写于 作者: J Jason Malinowski

Convert the type inferrer tests to be Theories

Most of the type inferrer tests test both overloads of the
type inferrence service -- the one that takes a span and one that
takes a position. Both (by default) were tested, but it's impossible
without actually debugging a test to know which one failed. I had a
particular irritating case where I made a behavior change and had to
update a bunch of tests with new baselines, but since the behavior
also split between both APIs it was confusing to figure out what was
going on.
上级 c651fb23
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" />
<PackageReference Include="Xunit.Combinatorial" Version="$(XunitCombinatorialVersion)" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
......
...@@ -37,39 +37,37 @@ private static async Task<bool> CanUseSpeculativeSemanticModelAsync(Document doc ...@@ -37,39 +37,37 @@ private static async Task<bool> CanUseSpeculativeSemanticModelAsync(Document doc
return !service.GetMemberBodySpanForSpeculativeBinding(node).IsEmpty; return !service.GetMemberBodySpanForSpeculativeBinding(node).IsEmpty;
} }
protected async Task TestAsync(string text, string expectedType, bool testNode = true, bool testPosition = true, /// <summary>
SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) /// Specifies which overload of the <see cref="ITypeInferenceService"/> will be tested.
/// </summary>
public enum TestMode
{ {
MarkupTestFile.GetSpan(text.NormalizeLineEndings(), out text, out var textSpan); /// <summary>
/// Specifies the test is going to call into <see cref="ITypeInferenceService.InferTypes(SemanticModel, SyntaxNode, string, System.Threading.CancellationToken)"/>.
if (testNode) /// </summary>
{ Node,
await TestWithAndWithoutSpeculativeSemanticModelAsync(text, textSpan, expectedType, useNodeStartPosition: false, sourceCodeKind);
}
if (testPosition) /// <summary>
{ /// Specifies the test is going to call into <see cref="ITypeInferenceService.InferTypes(SemanticModel, int, string, System.Threading.CancellationToken)"/>.
await TestWithAndWithoutSpeculativeSemanticModelAsync(text, textSpan, expectedType, useNodeStartPosition: true, sourceCodeKind); /// </summary>
} Position
} }
private async Task TestWithAndWithoutSpeculativeSemanticModelAsync( protected async Task TestAsync(string text, string expectedType, TestMode mode,
string text, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular)
TextSpan textSpan,
string expectedType,
bool useNodeStartPosition,
SourceCodeKind sourceCodeKind)
{ {
MarkupTestFile.GetSpan(text.NormalizeLineEndings(), out text, out var textSpan);
var document = fixture.UpdateDocument(text, sourceCodeKind); var document = fixture.UpdateDocument(text, sourceCodeKind);
await TestWorkerAsync(document, textSpan, expectedType, useNodeStartPosition); await TestWorkerAsync(document, textSpan, expectedType, mode);
if (await CanUseSpeculativeSemanticModelAsync(document, textSpan.Start)) if (await CanUseSpeculativeSemanticModelAsync(document, textSpan.Start))
{ {
var document2 = fixture.UpdateDocument(text, sourceCodeKind, cleanBeforeUpdate: false); var document2 = fixture.UpdateDocument(text, sourceCodeKind, cleanBeforeUpdate: false);
await TestWorkerAsync(document2, textSpan, expectedType, useNodeStartPosition); await TestWorkerAsync(document2, textSpan, expectedType, mode);
} }
} }
protected abstract Task TestWorkerAsync(Document document, TextSpan textSpan, string expectedType, bool useNodeStartPosition); protected abstract Task TestWorkerAsync(Document document, TextSpan textSpan, string expectedType, TestMode mode);
} }
} }
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" />
<PackageReference Include="Xunit.Combinatorial" Version="$(XunitCombinatorialVersion)" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Import Include="Microsoft.CodeAnalysis.Editor.Shared.Extensions" /> <Import Include="Microsoft.CodeAnalysis.Editor.Shared.Extensions" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册