提交 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 @@
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" />
<PackageReference Include="Xunit.Combinatorial" Version="$(XunitCombinatorialVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
......
......@@ -37,39 +37,37 @@ private static async Task<bool> CanUseSpeculativeSemanticModelAsync(Document doc
return !service.GetMemberBodySpanForSpeculativeBinding(node).IsEmpty;
}
protected async Task TestAsync(string text, string expectedType, bool testNode = true, bool testPosition = true,
SourceCodeKind sourceCodeKind = SourceCodeKind.Regular)
/// <summary>
/// Specifies which overload of the <see cref="ITypeInferenceService"/> will be tested.
/// </summary>
public enum TestMode
{
MarkupTestFile.GetSpan(text.NormalizeLineEndings(), out text, out var textSpan);
if (testNode)
{
await TestWithAndWithoutSpeculativeSemanticModelAsync(text, textSpan, expectedType, useNodeStartPosition: false, sourceCodeKind);
}
/// <summary>
/// Specifies the test is going to call into <see cref="ITypeInferenceService.InferTypes(SemanticModel, SyntaxNode, string, System.Threading.CancellationToken)"/>.
/// </summary>
Node,
if (testPosition)
{
await TestWithAndWithoutSpeculativeSemanticModelAsync(text, textSpan, expectedType, useNodeStartPosition: true, sourceCodeKind);
}
/// <summary>
/// Specifies the test is going to call into <see cref="ITypeInferenceService.InferTypes(SemanticModel, int, string, System.Threading.CancellationToken)"/>.
/// </summary>
Position
}
private async Task TestWithAndWithoutSpeculativeSemanticModelAsync(
string text,
TextSpan textSpan,
string expectedType,
bool useNodeStartPosition,
SourceCodeKind sourceCodeKind)
protected async Task TestAsync(string text, string expectedType, TestMode mode,
SourceCodeKind sourceCodeKind = SourceCodeKind.Regular)
{
MarkupTestFile.GetSpan(text.NormalizeLineEndings(), out text, out var textSpan);
var document = fixture.UpdateDocument(text, sourceCodeKind);
await TestWorkerAsync(document, textSpan, expectedType, useNodeStartPosition);
await TestWorkerAsync(document, textSpan, expectedType, mode);
if (await CanUseSpeculativeSemanticModelAsync(document, textSpan.Start))
{
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 @@
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" />
<PackageReference Include="Xunit.Combinatorial" Version="$(XunitCombinatorialVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.CodeAnalysis.Editor.Shared.Extensions" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册