public void SnapshotSpanSourceCodeReaderTest() {
            var text = "hello world\r\nHello again!";
            var buffer = new MockTextBuffer(text);
            var snapshot = new MockTextSnapshot(buffer, text);

            var reader = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, text.Length)));

            Assert.AreEqual(reader.Snapshot, snapshot);
            Assert.AreEqual(reader.Position, 0);
            var line = reader.ReadLine();
            Assert.AreEqual(line, "hello world");
            line = reader.ReadLine();
            Assert.AreEqual(line, "Hello again!");

            reader = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, text.Length)));
            int ch = reader.Peek();
            Assert.AreEqual(ch, (int)'h');

            char[] readBuf = new char[text.Length];
            reader.Read(readBuf, 0, readBuf.Length);

            Assert.AreEqual(new string(readBuf), text);

            reader = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, text.Length)));
            Assert.AreEqual(reader.ReadToEnd(), text);

            reader.Reset();

            Assert.AreEqual(reader.ReadToEnd(), text);

            reader.Close();
            Assert.AreEqual(reader.Snapshot, null);
        }
Example #2
0
        private void SnapshotCellTest(string fileContents, params ExpectedTag[] expected)
        {
            var snapshot = new TestUtilities.Mocks.MockTextSnapshot(new TestUtilities.Mocks.MockTextBuffer(fileContents), fileContents);
            var ast      = Parser.CreateParser(new TextSnapshotToTextReader(snapshot), PythonLanguageVersion.V34).ParseFile();
            var tags     = Microsoft.PythonTools.OutliningTaggerProvider.OutliningTagger.ProcessCellTags(snapshot, default(CancellationToken));

            VerifyTags(snapshot, tags, expected);
        }
Example #3
0
 public MockTextBuffer(string content, IContentType contentType, string filename = null) {
     _snapshot = new MockTextSnapshot(this, content);
     _contentType = contentType;
     if (filename == null) {
         filename = Path.Combine(TestData.GetTempPath(), Path.GetRandomFileName(), "file.py");
     }
     Properties[typeof(ITextDocument)] = new MockTextDocument(this, filename);
 }
Example #4
0
 public MockTextSnapshotLine(MockTextSnapshot snapshot, string text, int lineNo, int startPos, string lineBreak) {
     Debug.Assert(!text.EndsWith("\n"));
     _snapshot = snapshot;
     _text = text;
     _lineNo = lineNo;
     _startPos = startPos;
     _lineBreak = lineBreak;
 }
 public MockTextSnapshot(MockTextBuffer buffer, string text, MockTextSnapshot prevVersion, params ITextChange[] changes)
 {
     _text = text;
     _buffer = buffer;
     _version = new MockTextVersion(prevVersion.Version.VersionNumber + 1, this);
     ((MockTextVersion)prevVersion.Version).SetNext(_version, changes);
     _lines = MakeLines(_text).ToList();
 }
#pragma warning restore 67

        /// <summary>
        /// Raises a fake changed low priority event
        /// </summary>
        public void RaiseChangedLowPriority() {
            var changed = ChangedLowPriority;
            if (changed != null) {
                var oldSnapshot = _snapshot;
                var newSnapshot = new MockTextSnapshot(this, _snapshot.GetText(), _snapshot);
                _snapshot = newSnapshot;
                changed(this, new TextContentChangedEventArgs(oldSnapshot, newSnapshot, EditOptions.None, null));
            }
        }
#pragma warning restore 67

        /// <summary>
        /// Raises a fake changed low priority event
        /// </summary>
        public void RaiseChangedLowPriority()
        {
            var changed = ChangedLowPriority;

            if (changed != null)
            {
                var oldSnapshot = _snapshot;
                var newSnapshot = new MockTextSnapshot(this, _snapshot.GetText(), _snapshot,
                                                       new MockTextChange(
                                                           new SnapshotSpan(_snapshot, 0, _snapshot.Length),
                                                           0,
                                                           _snapshot.GetText()
                                                           )
                                                       );
                _snapshot = newSnapshot;
                changed(this, new TextContentChangedEventArgs(oldSnapshot, newSnapshot, EditOptions.None, null));
            }
        }
Example #8
0
        public ITextSnapshot Replace(Span replaceSpan, string replaceWith)
        {
            var    oldText = _snapshot.GetText();
            string newText = oldText.Remove(replaceSpan.Start, replaceSpan.Length);

            newText = newText.Insert(replaceSpan.Start, replaceWith);

            _snapshot = new MockTextSnapshot(
                this,
                newText,
                _snapshot,
                new MockTextChange(
                    new SnapshotSpan(_snapshot, replaceSpan),
                    replaceSpan.Start,
                    replaceWith
                    )
                );
            return(_snapshot);
        }
Example #9
0
        private void SnapshotOutlineTest(string fileContents, params ExpectedTag[] expected)
        {
            var snapshot = new TestUtilities.Mocks.MockTextSnapshot(new TestUtilities.Mocks.MockTextBuffer(fileContents), fileContents);
            var ast      = Parser.CreateParser(new TextSnapshotToTextReader(snapshot), PythonLanguageVersion.V34).ParseFile();
            var walker   = new OutliningWalker(ast);

            ast.Walk(walker);
            var protoTags = walker.GetTags();

            var tags = protoTags.Select(x =>
                                        OutliningTaggerProvider.OutliningTagger.GetTagSpan(
                                            snapshot,
                                            x.startIndex,
                                            x.endIndex,
                                            x.headerIndex
                                            )
                                        );

            VerifyTags(snapshot, tags, expected);
        }
        public ITextSnapshot Replace(Span replaceSpan, string replaceWith)
        {
            var    oldText = _snapshot.GetText();
            string newText = oldText.Remove(replaceSpan.Start, replaceSpan.Length);

            newText = newText.Insert(replaceSpan.Start, replaceWith);
            var oldSnapshot = _snapshot;

            _snapshot = new MockTextSnapshot(
                this,
                newText,
                _snapshot,
                new MockTextChange(
                    new SnapshotSpan(_snapshot, replaceSpan),
                    replaceSpan.Start,
                    replaceWith
                    )
                );
            if (Changed != null)
            {
                Changed(this, new TextContentChangedEventArgs(oldSnapshot, _snapshot, EditOptions.None, null));
            }
            return(_snapshot);
        }
Example #11
0
 public MockTrackingSpan(MockTextSnapshot snapshot, int start, int length, SpanTrackingMode trackingMode = SpanTrackingMode.EdgeExclusive) {
     _start = start;
     _length = length;
     _snapshot = snapshot;
     _trackingMode = trackingMode;
     switch(_trackingMode) {
         case SpanTrackingMode.EdgeExclusive:
             _startPoint = new MockTrackingPoint(snapshot, start, PointTrackingMode.Positive);
             _endPoint = new MockTrackingPoint(snapshot, start + length, PointTrackingMode.Negative);
             break;
         case SpanTrackingMode.EdgeInclusive:
             _startPoint = new MockTrackingPoint(snapshot, start, PointTrackingMode.Negative);
             _endPoint = new MockTrackingPoint(snapshot, start + length, PointTrackingMode.Positive);
             break;
         case SpanTrackingMode.EdgeNegative:
             _startPoint = new MockTrackingPoint(snapshot, start, PointTrackingMode.Negative);
             _endPoint = new MockTrackingPoint(snapshot, start + length, PointTrackingMode.Negative);
             break;
         case SpanTrackingMode.EdgePositive:
             _startPoint = new MockTrackingPoint(snapshot, start, PointTrackingMode.Positive);
             _endPoint = new MockTrackingPoint(snapshot, start + length, PointTrackingMode.Positive);
             break;
     }
 }
 public MockTextBuffer(string content, IContentType contentType, string filename = "C:\\fob.py")
 {
     _snapshot    = new MockTextSnapshot(this, content);
     _contentType = contentType;
     Properties[typeof(ITextDocument)] = new MockTextDocument(this, filename);
 }
 public MockTextVersion(int version, MockTextSnapshot snapshot) {
     _version = version;
     _snapshot = snapshot;
 }
Example #14
0
 public MockTextVersion(int version, MockTextSnapshot snapshot)
 {
     _version      = version;
     _snapshot     = snapshot;
     _imageVersion = new MockTextImageVersion(this);
 }
Example #15
0
 public MockTextEdit(MockTextSnapshot snapshot)
 {
     _snapshot = snapshot;
 }
Example #16
0
 public MockTrackingSpan(MockTextSnapshot snapshot, int start, int length)
 {
     _start    = start;
     _length   = length;
     _snapshot = snapshot;
 }
Example #17
0
        public ITextSnapshot Replace(Span replaceSpan, string replaceWith) {
            var oldText = _snapshot.GetText();
            string newText = oldText.Remove(replaceSpan.Start, replaceSpan.Length);
            newText  = newText.Insert(replaceSpan.Start, replaceWith);

            _snapshot = new MockTextSnapshot(
                this, 
                newText, 
                _snapshot, 
                new MockTextChange(
                    new SnapshotSpan(_snapshot, replaceSpan), 
                    replaceSpan.Start,
                    replaceWith
                )
            );
            return _snapshot;
        }
Example #18
0
 public MockTrackingPoint(MockTextSnapshot snapshot, int position, PointTrackingMode mode = PointTrackingMode.Positive)
 {
     _position = position;
     _snapshot = snapshot;
     _mode     = mode;
 }
Example #19
0
 public MockTrackingPoint(MockTextSnapshot snapshot, int position, PointTrackingMode mode = PointTrackingMode.Positive, TrackingFidelityMode fidelity = TrackingFidelityMode.Forward) {
     _position = position;
     _snapshot = snapshot;
     _mode = mode;
     _fidelity = fidelity;
 }
 public MockTrackingPoint(MockTextSnapshot snapshot, int position, PointTrackingMode mode = PointTrackingMode.Positive) {
     _position = position;
     _snapshot = snapshot;
     _mode = mode;
 }
 public MockTextEdit(MockTextSnapshot snapshot) {
     _snapshot = snapshot;
 }
 public MockTextBuffer(string content, string filename = "C:\\fob.fs", string contentType = "F#")
 {
     _snapshot    = new MockTextSnapshot(this, content);
     _filename    = filename;
     _contentType = contentType;
 }
Example #23
0
 public MockTrackingSpan(MockTextSnapshot snapshot, int start, int length) {
     _start = start;
     _length = length;
     _snapshot = snapshot;
 }
Example #24
0
 public MockTextVersion(int version, MockTextSnapshot snapshot)
 {
     _version  = version;
     _snapshot = snapshot;
 }
 public ITextSnapshot Replace(Span replaceSpan, string replaceWith) {
     var oldText = _snapshot.GetText();
     string newText = oldText.Remove(replaceSpan.Start, replaceSpan.Length);
     newText  = newText.Insert(replaceSpan.Start, replaceWith);
     var oldSnapshot = _snapshot;
     _snapshot = new MockTextSnapshot(
         this,
         newText,
         _snapshot,
         new MockTextChange(
             new SnapshotSpan(_snapshot, replaceSpan),
             replaceSpan.Start,
             replaceWith
         )
     );
     if (Changed != null)
         Changed(this, new TextContentChangedEventArgs(oldSnapshot, _snapshot, EditOptions.None, null));
     if (ChangedLowPriority != null)
         ChangedLowPriority(this, new TextContentChangedEventArgs(oldSnapshot, _snapshot, EditOptions.None, null));
     return _snapshot;
 }
 public MockTextBuffer(string content, string filename = "C:\\fob.fs", string contentType = "F#") {
     _snapshot = new MockTextSnapshot(this, content);
     _filename = filename;
     _contentType = contentType;
 }
 public MockTextBuffer(string content, string filename = "C:\\untitled")
 {
     _snapshot = new MockTextSnapshot(this, content);
     _filename = filename;
 }
Example #28
0
 public MockTextBuffer(string content)
 {
     _snapshot = new MockTextSnapshot(this, content);
 }
 public MockTextBuffer(string content, string filename = "C:\\untitled") {
     _snapshot = new MockTextSnapshot(this, content);
     _filename = filename;
 }