Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }