diff --git a/src/EditorFeatures/Test2/IntelliSense/CompletionRulesTests.vb b/src/EditorFeatures/Test2/IntelliSense/CompletionRulesTests.vb index a270b6cf50ba6e5069ec95ba24c86c5029fca646..fb1571ec4853bbc5e0059b5fff1f9e0017fe9a48 100644 --- a/src/EditorFeatures/Test2/IntelliSense/CompletionRulesTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/CompletionRulesTests.vb @@ -3,6 +3,7 @@ Imports System.Globalization Imports Microsoft.CodeAnalysis.Completion Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces +Imports Microsoft.CodeAnalysis.Text Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense ' These tests adapted from David Kean's table at @@ -10,7 +11,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Public Class CompletionRulesTests Public Sub TestMatchLowerCaseEnglishI() - Dim wordsToMatch = {"index", "Index", "işte", "İşte"} + Dim wordsToMatch = {"[|i|]ndex", "[|I|]ndex", "[|i|]şte", "[|İ|]şte"} Dim wordsToNotMatch = {"ırak"} TestMatches("i", wordsToMatch) @@ -19,7 +20,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Public Sub TestMatchDottedUpperTurkishI() - Dim wordsToMatch = {"index", "işte", "İşte"} + Dim wordsToMatch = {"[|i|]ndex", "[|i|]şte", "[|İ|]şte"} Dim wordsToNotMatch = {"ırak", "Irak", "Index"} TestMatches("İ", wordsToMatch) @@ -28,7 +29,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Public Sub TestMatchNonDottedLowerTurkishI() - Dim wordsToMatch = {"ırak", "Irak"} + Dim wordsToMatch = {"[|ı|]rak", "[|I|]rak"} Dim wordsToNotMatch = {"index", "işte", "İşte"} TestMatches("ı", wordsToMatch) @@ -37,31 +38,48 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Public Sub TestMatchEnglishUpperI() - Dim wordsToMatch = {"Index", "index", "ırak", "Irak"} + ' In turkish-culture "I" will not match "index". However, we want to verify that + ' the underlying completion helper will fallback to doing an en-us check if the + ' tr-tr check fails, and that it properly also returns the matched spans in this case. + + Dim wordsToMatch = {"[|I|]ndex", "[|i|]ndex", "[|ı|]rak", "[|I|]rak"} Dim wordsToNotMatch = {"İşte"} TestMatches("I", wordsToMatch) TestNotMatches("I", wordsToNotMatch) End Sub - Private Sub TestMatches(v As String, wordsToMatch() As String) + Private Sub TestMatches(pattern As String, wordsToMatch() As String) Dim culture = New CultureInfo("tr-TR", useUserOverride:=False) Dim workspace = New TestWorkspace Dim helper = CompletionHelper.GetHelper(workspace, LanguageNames.CSharp) - For Each word In wordsToMatch + + For Each wordMarkup In wordsToMatch + Dim word As String = Nothing + Dim wordMatchSpan As TextSpan = Nothing + MarkupTestFile.GetSpan(wordMarkup, word, wordMatchSpan) + Dim item = CompletionItem.Create(word) - Assert.True(helper.MatchesPattern(item.FilterText, v, culture), $"Expected item {word} does not match {v}") + Assert.True(helper.MatchesPattern(item.FilterText, pattern, culture), $"Expected item {word} does not match {pattern}") + + Dim highlightedSpans = helper.GetHighlightedSpans(item.FilterText, pattern, culture) + Assert.NotEmpty(highlightedSpans) + Assert.Equal(1, highlightedSpans.Length) + Assert.Equal(wordMatchSpan, highlightedSpans(0)) Next End Sub - Private Sub TestNotMatches(v As String, wordsToNotMatch() As String) + Private Sub TestNotMatches(pattern As String, wordsToNotMatch() As String) Dim culture = New CultureInfo("tr-TR", useUserOverride:=False) Dim workspace = New TestWorkspace Dim helper = CompletionHelper.GetHelper(workspace, LanguageNames.CSharp) For Each word In wordsToNotMatch Dim item = CompletionItem.Create(word) - Assert.False(helper.MatchesPattern(item.FilterText, v, culture), $"Unexpected item {word} matches {v}") + Assert.False(helper.MatchesPattern(item.FilterText, pattern, culture), $"Unexpected item {word} matches {pattern}") + + Dim highlightedSpans = helper.GetHighlightedSpans(item.FilterText, pattern, culture) + Assert.Empty(highlightedSpans) Next End Sub End Class