public void CompareToMockSnapshot()
        {
            const string Text = @"try
{
    if (a == 0)
    {
        return foo(a,
                   10);

    }
    else
    {
        while(a > 0)
            a -= 1;

    }
}
";
            var          fake = new FakeSnapshot(Text);
            var          mock = new MockTextBuffer(Text).CurrentSnapshot;

            Assert.AreEqual(mock.Length, fake.Length, "Length does not match");
            for (int i = 0; i < mock.LineCount && i < fake.LineCount; ++i)
            {
                var mockLine = mock.GetLineFromLineNumber(i);
                var fakeLine = fake.GetLineFromLineNumber(i);
                Assert.AreEqual(mockLine.GetText(), fakeLine.GetText(), string.Format("Line {0} text does not match", i));
                Assert.AreEqual(mockLine.Start.Position, fakeLine.Start.Position, string.Format("Line {0} start does not match", i));
                Assert.AreEqual(mockLine.End.Position, fakeLine.End.Position, string.Format("Line {0} end does not match", i));
            }
            Assert.AreEqual(mock.LineCount, fake.LineCount, "LineCount does not match");
        }
Esempio n. 2
0
        internal static DocumentAnalyzer MakeAnalyzer(
            string text,
            LineBehavior behavior,
            int indentSize,
            int tabSize,
            string contentType,
            int chunkSize
            )
        {
            var buffer = new MockTextBuffer(text);

            buffer.ContentType = new MockContentType(contentType, null);
            return(MakeAnalyzer(buffer.CurrentSnapshot, behavior, indentSize, tabSize, chunkSize));
        }
Esempio n. 3
0
        private static void MemberCompletionTest(int location, string sourceCode, string expectedExpression)
        {
            if (location < 0)
            {
                location = sourceCode.Length + location;
            }

            var analyzer = new PythonAnalyzer(new MockDlrRuntimeHost(), new MockErrorProviderFactory());
            var buffer   = new MockTextBuffer(sourceCode);
            var snapshot = (MockTextSnapshot)buffer.CurrentSnapshot;
            var context  = analyzer.GetCompletions(snapshot, buffer, new MockTrackingSpan(snapshot, location, 1));

            AreEqual(context.Text, expectedExpression);
        }
Esempio n. 4
0
        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)
                );
        }
Esempio n. 5
0
        private static ExpressionAnalysis AnalyzeExpression(int location, string sourceCode)
        {
            if (location < 0)
            {
                location = sourceCode.Length + location;
            }

            var analyzer = new PythonAnalyzer(new MockDlrRuntimeHost(), new MockErrorProviderFactory());
            var buffer   = new MockTextBuffer(sourceCode);
            var textView = new MockTextView(buffer);
            var item     = analyzer.AnalyzeTextView(textView);

            while (item.IsAnalyzed)
            {
                Thread.Sleep(100);
            }

            var snapshot = (MockTextSnapshot)buffer.CurrentSnapshot;

            return(analyzer.AnalyzeExpression(snapshot, buffer, new MockTrackingSpan(snapshot, location, 0)));
        }
Esempio n. 6
0
 public MockTextSnapshot(MockTextBuffer mockTextBuffer)
 {
     _buffer = mockTextBuffer;
 }
Esempio n. 7
0
        private static void SignatureTest(int location, string sourceCode, string expectedExpression, int paramIndex)
        {
            if (location < 0) {
                location = sourceCode.Length + location;
            }

            var analyzer = new PythonAnalyzer(new MockDlrRuntimeHost(), new MockErrorProviderFactory());
            var buffer = new MockTextBuffer(sourceCode);
            var snapshot = (MockTextSnapshot)buffer.CurrentSnapshot;
            var context = analyzer.GetSignatures(snapshot, buffer, new MockTrackingSpan(snapshot, location, 1));
            AreEqual(context.Text, expectedExpression);
            AreEqual(context.ParameterIndex, paramIndex);
        }
Esempio n. 8
0
        private static ExpressionAnalysis AnalyzeExpression(int location, string sourceCode)
        {
            if (location < 0) {
                location = sourceCode.Length + location;
            }

            var analyzer = new PythonAnalyzer(new MockDlrRuntimeHost(), new MockErrorProviderFactory());
            var buffer = new MockTextBuffer(sourceCode);
            var textView = new MockTextView(buffer);
            var item = analyzer.AnalyzeTextView(textView);
            while (item.IsAnalyzed) {
                Thread.Sleep(100);
            }

            var snapshot = (MockTextSnapshot)buffer.CurrentSnapshot;

            return analyzer.AnalyzeExpression(snapshot, buffer, new MockTrackingSpan(snapshot, location, 0));
        }
Esempio n. 9
0
 public MockTextSnapshot(MockTextBuffer mockTextBuffer)
 {
     _buffer = mockTextBuffer;
 }