Ejemplo n.º 1
0
        public void BufferSync_Issue3570()
        {
            // https://github.com/Microsoft/PTVS/issues/3570

            var buffer = new MockTextBuffer("line");
            var bi     = PythonTextBufferInfo.ForBuffer(null, buffer);

            bi.AddSentSnapshot(buffer.CurrentSnapshot);

            Assert.AreEqual(new SourceLocation(1, 5), bi.LocationTracker.GetSourceLocation(4, 0));

            using (var e = buffer.CreateEdit()) {
                e.Insert(e.Snapshot.Length, "\r\n");
                e.Apply();
            }

            using (var e = buffer.CreateEdit()) {
                e.Insert(e.Snapshot.Length, "    c");
                e.Apply();
            }

            using (var e = buffer.CreateEdit()) {
                e.Insert(e.Snapshot.Length, "o");
                e.Apply();
            }

            var updates    = BufferParser.GetUpdatesForSnapshot(bi, buffer.CurrentSnapshot).ToArray();
            var changeInfo = string.Join(", ", updates
                                         .Select(u => string.Join(", ", u.changes.Select(c => $"({c.startLine},{c.startColumn},'{c.newText}')")))
                                         .Select(u => $"[{u}]"));

            Assert.AreEqual("[(1,5,'\r\n')], [(2,1,'    c')], [(2,6,'o')]", changeInfo);
        }
Ejemplo n.º 2
0
        public void BufferSync_Issue3733()
        {
            // https://github.com/Microsoft/PTVS/issues/3733

            var bigString = string.Join("\n", Enumerable.Repeat("content", 1000));

            var buffer = new MockTextBuffer("");
            var bi     = PythonTextBufferInfo.ForBuffer(null, buffer);

            bi.AddSentSnapshot(buffer.CurrentSnapshot);
            bi.LocationTracker.UpdateBaseSnapshot(buffer.CurrentSnapshot);

            AssertLines(bi, 0);

            using (var e = buffer.CreateEdit())
            {
                e.Insert(e.Snapshot.Length, bigString);
                e.Apply();
            }
            bi.LocationTracker.UpdateBaseSnapshot(buffer.CurrentSnapshot);

            int beforeVersion = bi.Buffer.CurrentSnapshot.Version.VersionNumber;

            using (var e = buffer.CreateEdit())
            {
                e.Replace(0, e.Snapshot.Length, "z");
                e.Apply();
            }
            bi.LocationTracker.UpdateBaseSnapshot(buffer.CurrentSnapshot);

            using (var e = buffer.CreateEdit())
            {
                e.Insert(e.Snapshot.Length, bigString);
                e.Apply();
            }
            bi.LocationTracker.UpdateBaseSnapshot(buffer.CurrentSnapshot);

            var before = bi.LocationTracker.GetLineLocations(beforeVersion);
            var after  = bi.LocationTracker.GetLineLocations(bi.Buffer.CurrentSnapshot.Version.VersionNumber);

            foreach (var t in before.Zip(after, Tuple.Create))
            {
                Assert.AreEqual(t.Item1.EndIndex, t.Item2.EndIndex - 1);
            }
        }
        public void UpdateSnapshot()
        {
            var buffer = new MockTextBuffer("");

            var behavior = new LineBehavior();
            var da = MakeAnalyzer(buffer.CurrentSnapshot, behavior, 4, 4, 5);
            da.ResetAndWait();

            da.AssertLinesIncludeExactly();

            var prevSnapshot = da.Snapshot;

            {
                var edit = buffer.CreateEdit();
                edit.Insert(0, @"0
            1
            2
            3
            4");
                edit.Apply();
            }

            da.UpdateAndWait(null);
            Assert.AreNotSame(prevSnapshot, da.Snapshot);
            Assert.AreNotEqual(prevSnapshot.Version.VersionNumber, da.Snapshot.Version.VersionNumber);
            da.AssertLinesIncludeExactly(
                new LineSpan(1, 3, 0, LineSpanType.Normal),
                new LineSpan(2, 2, 4, LineSpanType.Normal)
            );

            prevSnapshot = da.Snapshot;
            {
                var edit = buffer.CreateEdit();
                edit.Delete(prevSnapshot.GetLineFromLineNumber(2).ExtentIncludingLineBreak.Span);
                edit.Apply();
            }

            da.UpdateAndWait(null);
            Assert.AreNotSame(prevSnapshot, da.Snapshot);
            Assert.AreNotEqual(prevSnapshot.Version.VersionNumber, da.Snapshot.Version.VersionNumber);
            da.AssertLinesIncludeExactly(
                new LineSpan(1, 2, 0, LineSpanType.Normal)
            );
        }