internal void VerifyNavigateToResultItem( NavigateToItem result, string name, string displayMarkup, PatternMatchKind matchKind, string navigateToItemKind, Glyph glyph, string additionalInfo = null) { // Verify symbol information Assert.Equal(name, result.Name); Assert.Equal(matchKind, result.PatternMatch.Kind); Assert.Equal(this.Language, result.Language); Assert.Equal(navigateToItemKind, result.Kind); MarkupTestFile.GetSpans(displayMarkup, out displayMarkup, out ImmutableArray <TextSpan> expectedDisplayNameSpans); var itemDisplay = (NavigateToItemDisplay)result.DisplayFactory.CreateItemDisplay(result); Assert.Equal(itemDisplay.GlyphMoniker, glyph.GetImageMoniker()); Assert.Equal(displayMarkup, itemDisplay.Name); Assert.Equal <TextSpan>( expectedDisplayNameSpans, itemDisplay.GetNameMatchRuns("").Select(s => s.ToTextSpan()).ToImmutableArray()); if (additionalInfo != null) { Assert.Equal(additionalInfo, itemDisplay.AdditionalInformation); } }
/// <summary> /// Creates a PatternMatch object with an optional single span. /// </summary> /// <param name="resultType">How is this match categorized?</param> /// <param name="punctuationStripped">Was punctuation removed?</param> /// <param name="isCaseSensitive">Was this a case sensitive match?</param> public PatternMatch( PatternMatchKind resultType, bool punctuationStripped, bool isCaseSensitive) : this(resultType, punctuationStripped, isCaseSensitive, ImmutableArray <Span> .Empty) { }
internal PatternMatch( PatternMatchKind resultType, bool punctuationStripped, bool isCaseSensitive, TextSpan?matchedSpan) : this(resultType, punctuationStripped, isCaseSensitive, matchedSpan == null ? ImmutableArray <TextSpan> .Empty : ImmutableArray.Create(matchedSpan.Value)) { }
// Test is internal as PatternMatchKind is internal, but this is still ran. internal void TestNonFuzzyMatch( string candidate, string pattern, PatternMatchKind matchKind, bool isCaseSensitive) { var match = TestNonFuzzyMatch(candidate, pattern); Assert.NotNull(match); Assert.Equal(matchKind, match.Value.Kind); Assert.Equal(isCaseSensitive, match.Value.IsCaseSensitive); }
internal PatternMatch( PatternMatchKind resultType, bool punctuationStripped, bool isCaseSensitive, TextSpan?matchedSpan, int?camelCaseWeight = null) : this(resultType, punctuationStripped, isCaseSensitive, matchedSpan == null ? null : new[] { matchedSpan.Value }, camelCaseWeight) { }
internal PatternMatch( PatternMatchKind resultType, bool punctuationStripped, bool isCaseSensitive, ImmutableArray <TextSpan> matchedSpans) : this() { this.Kind = resultType; this.IsCaseSensitive = isCaseSensitive; this.MatchedSpans = matchedSpans; _punctuationStripped = punctuationStripped; }
internal PatternMatch(PatternMatchKind resultType, bool punctuationStripped, bool isCaseSensitive, int?camelCaseWeight = null) : this() { this.Kind = resultType; this.IsCaseSensitive = isCaseSensitive; this.CamelCaseWeight = camelCaseWeight; this.punctuationStripped = punctuationStripped; if ((resultType == PatternMatchKind.CamelCase) != camelCaseWeight.HasValue) { throw new ArgumentException("A CamelCase weight must be specified if and only if the resultType is CamelCase."); } }
private void AssertContainsType(PatternMatchKind type, IEnumerable<PatternMatch> results) { Assert.True(results.Any(r => r.Kind == type)); }
private void AssertContainsType(PatternMatchKind type, IEnumerable <PatternMatch> results) { Assert.True(results.Any(r => r.Kind == type)); }
/// <summary> /// Compares two <see cref="PatternMatchKind"/> values, suggesting which one is more likely to be what the user was searching for. /// </summary> /// <param name="kind1">Item to be compared.</param> /// <param name="kind2">Item to be compared.</param> /// <returns>A negative value means kind1 is preferable, positive means kind2 is preferable. Zero means they are equivalent.</returns> public static int CompareTo(this PatternMatchKind kind1, PatternMatchKind kind2) { return(kind1 - kind2); }
private static PatternMatchKind MergeMatchKinds(PatternMatchKind kind1, PatternMatchKind kind2) { // Ensure ordering for simpler processing below. if (kind2 < kind1) { return(MergeMatchKinds(kind2, kind1)); } // Guess the match kind. Unfortunately we can't assume contiguity. It is hard to guess when dealing with Exact, Fuzzy, // and multiple prefixes, so assume that if you have an exact match, the other merged thing must be redundant. // The only exception is fuzzy (which degrades everything) since the match obviously missed somehow. // // Kinds: // Exact (E), Prefix (P), Substring (S), CamelCaseExact (CE), CamelCasePrefix (CP), CamelCaseNonContiguousPrefix (NP) // CamelCaseSubstring (CS), CamelCaseNonContiguousSubstring(NS ), Fuzzy (F) // // Mapping: // In |E |P |S |CE |CP |NP |CS |NS |F // ___________________________________ // E |E E E E E E E E F // P | P NP CE CP NP NP NP F // S | NS CE NP NP NS NS F // CE | CE CE CE CE CE F // CP | CP NP NP NP F // NP | NP NP NP F // CS | NS NS F // NS | NS F // F | F // // See PatternMatchingUnitTests.MatchMultiWordPatterns_MatchKindMerge for examples. There's a bunch. if (kind1 == PatternMatchKind.Fuzzy || kind2 == PatternMatchKind.Fuzzy) { return(PatternMatchKind.Fuzzy); } else if (kind1 == PatternMatchKind.Exact || kind2 == PatternMatchKind.Exact) { return(PatternMatchKind.Exact); } else if (kind1 == PatternMatchKind.CamelCaseExact || kind2 == PatternMatchKind.CamelCaseExact) { return(PatternMatchKind.CamelCaseExact); } else if (kind1 == PatternMatchKind.CamelCaseNonContiguousPrefix || kind2 == PatternMatchKind.CamelCaseNonContiguousPrefix) { return(PatternMatchKind.CamelCaseNonContiguousPrefix); } else { // Ok, we have to actually think about this one. We can assume that kind1 <= kind2 here. // //Reduced manifest from above: // In |P |S |CP |CS |NS // ____________________ // P |P NP CP NP NP // S | NS NP NS NS // CP | CP NP NP // CS | NS NS // NS | NS switch (kind1) { case PatternMatchKind.Prefix: if (kind2 == PatternMatchKind.Prefix) { return(PatternMatchKind.Prefix); } else if (kind2 == PatternMatchKind.CamelCasePrefix) { return(PatternMatchKind.CamelCasePrefix); } return(PatternMatchKind.CamelCaseNonContiguousPrefix); case PatternMatchKind.Substring: if (kind2 == PatternMatchKind.CamelCasePrefix) { return(PatternMatchKind.CamelCaseNonContiguousPrefix); } return(PatternMatchKind.CamelCaseNonContiguousSubstring); case PatternMatchKind.CamelCasePrefix: if (kind2 == PatternMatchKind.CamelCasePrefix) { return(PatternMatchKind.CamelCasePrefix); } return(PatternMatchKind.CamelCaseNonContiguousPrefix); default: // Handles CamelCaseSubstring and CamelCaseNonContiguousSubstring return(PatternMatchKind.CamelCaseNonContiguousSubstring); } } }