提交 3323aeee 编写于 作者: C CyrusNajmabadi

fix tests.

上级 860ab0aa
......@@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Completion;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion;
using Microsoft.CodeAnalysis.Editor.UnitTests.Completion;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Text;
......@@ -216,16 +217,14 @@ protected async Task VerifyCommitCharactersAsync(string initialMarkup, string te
var completionList = await GetCompletionListAsync(service, document, position, CompletionTrigger.Default);
var item = completionList.Items.First(i => i.DisplayText.StartsWith(textTypedSoFar));
var completionRules = CompletionHelper.GetHelper(document, service);
foreach (var ch in validChars)
{
Assert.True(completionRules.IsCommitCharacter(item, ch, textTypedSoFar), $"Expected '{ch}' to be a commit character");
Assert.True(Controller.IsCommitCharacter(service.GetRules(), item, ch, textTypedSoFar), $"Expected '{ch}' to be a commit character");
}
foreach (var ch in invalidChars)
{
Assert.False(completionRules.IsCommitCharacter(item, ch, textTypedSoFar), $"Expected '{ch}' NOT to be a commit character");
Assert.False(Controller.IsCommitCharacter(service.GetRules(), item, ch, textTypedSoFar), $"Expected '{ch}' NOT to be a commit character");
}
}
}
......
......@@ -317,7 +317,10 @@ private bool IsCommitCharacter(char ch)
completionService.GetRules(), model.SelectedItem.Item, ch, filterText);
}
private bool IsCommitCharacter(
/// <summary>
/// Internal for testing purposes only.
/// </summary>
internal static bool IsCommitCharacter(
CompletionRules completionRules, CompletionItem item, char ch, string filterText)
{
// general rule: if the filtering text exactly matches the start of the item then it must be a filter character
......@@ -380,7 +383,10 @@ private static bool TextTypedSoFarMatchesItem(CompletionItem item, char ch, stri
item.FilterText.StartsWith(textTypedWithChar, StringComparison.CurrentCultureIgnoreCase);
}
private bool IsFilterCharacter(CompletionItem item, char ch, string filterText)
/// <summary>
/// Internal for testing purposes only.
/// </summary>
internal static bool IsFilterCharacter(CompletionItem item, char ch, string filterText)
{
// general rule: if the filtering text exactly matches the start of the item then it must be a filter character
if (TextTypedSoFarMatchesItem(item, ch, textTypedSoFar: filterText))
......
......@@ -9,6 +9,7 @@
using System.Windows.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Options;
......@@ -313,7 +314,7 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document
{
var completionRules = GetCompletionHelper(document, service);
var textView = (await WorkspaceFixture.GetWorkspaceAsync()).Documents.Single().GetTextView();
VerifyCustomCommitWorker(customCommitCompletionProvider, firstItem, completionRules, textView, textBuffer, codeBeforeCommit, expectedCodeAfterCommit, commitChar);
VerifyCustomCommitWorker(service, customCommitCompletionProvider, firstItem, completionRules, textView, textBuffer, codeBeforeCommit, expectedCodeAfterCommit, commitChar);
}
else
{
......@@ -333,9 +334,7 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document
string actualExpectedCode = null;
MarkupTestFile.GetPosition(expectedCodeAfterCommit, out actualExpectedCode, out expectedCaretPosition);
CompletionHelper completionRules = GetCompletionHelper(document, service);
if (commitChar.HasValue && !completionRules.IsCommitCharacter(completionItem, commitChar.Value, string.Empty))
if (commitChar.HasValue && !Controller.IsCommitCharacter(service.GetRules(), completionItem, commitChar.Value, string.Empty))
{
Assert.Equal(codeBeforeCommit, actualExpectedCode);
return;
......@@ -359,6 +358,7 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document
}
internal virtual void VerifyCustomCommitWorker(
CompletionService service,
ICustomCommitCompletionProvider customCommitCompletionProvider,
CompletionItem completionItem,
CompletionHelper completionRules,
......@@ -372,7 +372,7 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document
string actualExpectedCode = null;
MarkupTestFile.GetPosition(expectedCodeAfterCommit, out actualExpectedCode, out expectedCaretPosition);
if (commitChar.HasValue && !completionRules.IsCommitCharacter(completionItem, commitChar.Value, string.Empty))
if (commitChar.HasValue && !Controller.IsCommitCharacter(service.GetRules(), completionItem, commitChar.Value, string.Empty))
{
Assert.Equal(codeBeforeCommit, actualExpectedCode);
return;
......@@ -407,7 +407,8 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document
}
}
private async Task VerifyProviderCommitCheckResultsAsync(Document document, int position, string itemToCommit, string expectedCodeAfterCommit, char? commitCharOpt, string textTypedSoFar)
private async Task VerifyProviderCommitCheckResultsAsync(
Document document, int position, string itemToCommit, string expectedCodeAfterCommit, char? commitCharOpt, string textTypedSoFar)
{
var workspace = await WorkspaceFixture.GetWorkspaceAsync();
var textBuffer = workspace.Documents.Single().TextBuffer;
......@@ -422,7 +423,7 @@ private async Task VerifyProviderCommitCheckResultsAsync(Document document, int
var text = await document.GetTextAsync();
if (commitChar == '\t' || completionRules.IsCommitCharacter(firstItem, commitChar, textTypedSoFar))
if (commitChar == '\t' || Controller.IsCommitCharacter(service.GetRules(), firstItem, commitChar, textTypedSoFar))
{
var textChange = CompletionHelper.GetTextChangeAsync(service, document, firstItem, commitChar).Result;
......
......@@ -3,6 +3,7 @@
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Completion
Imports Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Completion
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.Text
......@@ -145,11 +146,11 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
Dim helper = CompletionHelper.GetHelper(document, service)
For Each ch In chars
Assert.True(helper.IsCommitCharacter(item, ch, textTypedSoFar), $"Expected '{ch}' to be a commit character")
Assert.True(Controller.IsCommitCharacter(service.GetRules(), item, ch, textTypedSoFar), $"Expected '{ch}' to be a commit character")
Next
Dim chr = "x"c
Assert.False(helper.IsCommitCharacter(item, chr, textTypedSoFar), $"Expected '{chr}' NOT to be a commit character")
Assert.False(Controller.IsCommitCharacter(service.GetRules(), item, chr, textTypedSoFar), $"Expected '{chr}' NOT to be a commit character")
End Using
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册