public void CanGetSurroundingBraces() { var textBuffer = GetCSharpTextBuffer("Rainbow1.txt"); var snapshot = textBuffer.CurrentSnapshot; var cache = new BraceCache(snapshot, GetLang(textBuffer)); var span = snapshot.GetSpan(); // force parsing all text cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count(); // we're looking at the {} for this function //public static bool Has<T>(this IPropertyOwner owner) { // return owner.Properties.ContainsProperty(typeof(T)); //} var line10 = snapshot.GetLineFromLineNumber(9); var matchingBraces = cache.GetBracePairFromPosition(line10.Start + 10, RainbowHighlightMode.TrackInsertionPoint); Assert.NotNull(matchingBraces); Assert.Equal('{', matchingBraces.Item1.Brace); Assert.Equal('}', matchingBraces.Item2.Brace); }
public void CanGetSurroundingBraces_TrackNextScope() { var textBuffer = GetCSharpTextBuffer("Rainbow1.txt"); var snapshot = textBuffer.CurrentSnapshot; var cache = new BraceCache(snapshot, GetLang(textBuffer)); var span = snapshot.GetSpan(); // force parsing all text cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count(); // we're looking at the {} for this function, positioned just at the { //public static bool Has<T>(this IPropertyOwner owner) { // return owner.Properties.ContainsProperty(typeof(T)); //} var line9 = snapshot.GetLineFromLineNumber(8); Console.WriteLine(line9.GetText()); var openingBrace = line9.End - 1; Assert.Equal('{', openingBrace.GetChar()); var matchingBraces = cache.GetBracePairFromPosition(openingBrace, RainbowHighlightMode.TrackNextScope); Assert.NotNull(matchingBraces); Assert.Equal(openingBrace.Position, matchingBraces.Item1.Position); }
public void CanGetSurroundingBraces_TrackInsertionPoint() { var textBuffer = GetCSharpTextBuffer("Rainbow1.txt"); var snapshot = textBuffer.CurrentSnapshot; var cache = new BraceCache(snapshot, GetLang(textBuffer)); var span = snapshot.GetSpan(); // force parsing all text cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count(); // we're looking at the {} for this function, positioned just at the { //public static bool Has<T>(this IPropertyOwner owner) { // return owner.Properties.ContainsProperty(typeof(T)); //} var line9 = snapshot.GetLineFromLineNumber(8); var openingBrace = line9.Start + line9.GetText().IndexOf('{'); Assert.Equal('{', openingBrace.GetChar()); var matchingBraces = cache.GetBracePairFromPosition(openingBrace, RainbowHighlightMode.TrackInsertionPoint); Assert.NotNull(matchingBraces); // we should have gotten braces starting *before* the search position! Assert.True(openingBrace.Position > matchingBraces.Item1.Position); }