private void SnapshotOutlineTest(string fileContents, params ExpectedTag[] expected) { var snapshot = new MockTextSnapshot(new 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( x.Span.Start.ToSnapshotPoint(snapshot), x.Span.End.ToSnapshotPoint(snapshot) ) ); VerifyTags(snapshot, tags, expected); }
#pragma warning restore 67 /// <summary> /// Raises a fake changed low priority event /// </summary> public void RaiseChangedLowPriority() { var changed = ChangedLowPriority; if (changed != null) { MockTextSnapshot oldSnapshot = _snapshot; MockTextSnapshot 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)); } }
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); }
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); }
public MockTextVersion(int version, MockTextSnapshot snapshot) { _version = version; _snapshot = snapshot; _imageVersion = new MockTextImageVersion(this); }
public MockTextBuffer(string content) { _snapshot = new MockTextSnapshot(this, content); }
private SnapshotPoint GetPoint(ITextVersion version) { if (version.TextBuffer != _snapshot.TextBuffer) { Debug.Fail("Mismatched buffers"); throw new ArgumentException("Mismatched text buffers"); } var newPos = _position; var current = _snapshot.Version; var target = version; MockTextSnapshot toSnapshot = ((MockTextVersion)target)._snapshot; if (current.VersionNumber > target.VersionNumber) { // Apply the changes in reverse var changesStack = new Stack <INormalizedTextChangeCollection>(); for (var v = target; v.VersionNumber < current.VersionNumber; v = v.Next) { changesStack.Push(v.Changes); } while (changesStack.Count > 0) { foreach (var change in changesStack.Pop()) { if (change.Delta > 0 && change.NewPosition <= newPos && change.NewPosition - change.Delta > newPos) { // point was deleted newPos = change.NewPosition; } else if (change.NewPosition == newPos) { if (_mode == PointTrackingMode.Positive) { newPos -= change.Delta; } } else if (change.NewPosition < newPos) { newPos -= change.Delta; } } } } else if (current.VersionNumber < target.VersionNumber) { // Apply the changes normally for (var v = current; v.VersionNumber < target.VersionNumber; v = v.Next) { foreach (var change in v.Changes) { if (change.Delta < 0 && change.OldPosition <= newPos && change.OldPosition - change.Delta > newPos) { // point was deleted newPos = change.OldPosition; } else if (change.OldPosition == newPos) { if (_mode == PointTrackingMode.Positive) { newPos += change.Delta; } } else if (change.OldPosition < newPos) { newPos += change.Delta; } } } } Debug.Assert(newPos >= 0, string.Format("new point '{0}' should be zero or greater", newPos)); Debug.Assert(newPos <= toSnapshot.Length, string.Format("new point '{0}' should be {1} or less", newPos, toSnapshot.Length)); return(new SnapshotPoint(toSnapshot, newPos)); }
public MockTextEdit(MockTextSnapshot snapshot) { _snapshot = snapshot; }