예제 #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);
        }
예제 #2
0
        private static void AssertExpression(string content, string expected, int index = -1, PythonLanguageVersion version = PythonLanguageVersion.V35)
        {
            var buffer = new MockTextBuffer(content);

            if (index < 0)
            {
                index += content.Length + 1;
            }
            var span   = new SnapshotSpan(buffer.CurrentSnapshot, index, 0);
            var actual = PythonTextBufferInfo.ForBuffer(null, buffer).GetExpressionAtPoint(span, GetExpressionOptions.Hover);

            Assert.AreEqual(expected, actual?.GetText(), content);
        }
예제 #3
0
        private static void AssertIndent(string code, int lineNumber, int expected, int tabSize = 4, int indentSize = 4)
        {
            var buffer = new MockTextBuffer(code, PythonContentType);
            var view   = new MockTextView(buffer);

            view.Options.SetOptionValue(DefaultOptions.IndentSizeOptionId, indentSize);
            view.Options.SetOptionValue(DefaultOptions.TabSizeOptionId, tabSize);

            var line   = buffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber - 1);
            var actual = AutoIndent.GetLineIndentation(PythonTextBufferInfo.ForBuffer(null, buffer), line, view);

            Assert.AreEqual(expected, actual, line.GetText());
        }
예제 #4
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);
            }
        }
예제 #5
0
        private static void AssertHasExpression(string content, bool expectExpression, int index = -1, PythonLanguageVersion version = PythonLanguageVersion.V35)
        {
            var buffer = new MockTextBuffer(content);

            if (index < 0)
            {
                index += content.Length + 1;
            }
            var pt     = new SnapshotPoint(buffer.CurrentSnapshot, index);
            var actual = PythonTextBufferInfo.ForBuffer(null, buffer).IsPossibleExpressionAtPoint(pt);

            if (expectExpression)
            {
                Assert.IsTrue(actual, content);
            }
            else
            {
                Assert.IsFalse(actual, content);
            }
        }