public void CanGetSurroundingBraces()
        {
            var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
              var snapshot = textBuffer.CurrentSnapshot;
              var cache = new TextBufferBraces(snapshot, GetLang(textBuffer), RainbowColoringMode.Unified);
              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 TextBufferBraces(snapshot, GetLang(textBuffer), RainbowColoringMode.Unified);
              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 CanInvalidate()
        {
            var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
              var snapshot = textBuffer.CurrentSnapshot;
              var cache = new TextBufferBraces(snapshot, GetLang(textBuffer), RainbowColoringMode.Unified);
              var span = snapshot.GetSpan();

              // force the cache to parse entire file
              cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count();

              // invalidate starting in Get_<T>
              var endpoint = new SnapshotPoint(snapshot, 357);
              cache.Invalidate(endpoint);
              // 331 is the position of the closing } of method before this
              Assert.Equal(331, cache.LastParsedPosition);
        }
 public void ParsingPlainTextFileDoesntScanDocument()
 {
     var textBuffer = GetPlainTextBuffer("Rainbow1.txt");
       var snapshot = textBuffer.CurrentSnapshot;
       var cache = new TextBufferBraces(snapshot, GetLang(textBuffer), RainbowColoringMode.Unified);
       var span = snapshot.GetSpan();
       Assert.Equal(0, cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count());
       Assert.True(cache.LastParsedPosition <= 0);
 }
 public void CanParseEntireFile()
 {
     var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
       var snapshot = textBuffer.CurrentSnapshot;
       var cache = new TextBufferBraces(snapshot, GetLang(textBuffer), RainbowColoringMode.Unified);
       var span = snapshot.GetSpan();
       Assert.Equal(32, cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count());
 }