示例#1
0
            public async Task CheckDefinitionLocations(int pos, int length, params LocationInfo[] expectedLocations)
            {
                var entry = (AnalysisEntry)_view.GetAnalysisEntry();

                entry.Analyzer.WaitForCompleteAnalysis(_ => true);

                var trackingSpan = _view.CurrentSnapshot.CreateTrackingSpan(pos, length, SpanTrackingMode.EdgeInclusive);
                var snapshotSpan = trackingSpan.GetSpan(_view.CurrentSnapshot);

                Console.WriteLine("Finding definition of \"{0}\"", snapshotSpan.GetText());
                var actualLocations = await NavigableSymbolSource.GetDefinitionLocationsAsync(entry, snapshotSpan.Start);

                Console.WriteLine($"Actual locations for pos={pos}, length={length}:");
                foreach (var actualLocation in actualLocations)
                {
                    Console.WriteLine($"file={actualLocation.Location.DocumentUri},line={actualLocation.Location.StartLine},col={actualLocation.Location.StartColumn}");
                }

                // Check that any real locations are not our test files. These may be included in debug builds,
                // but we don't want to be testing them.
                // Fake paths are from our tests, so always include them.
                actualLocations = actualLocations
                                  .Where(v => !File.Exists(v.Location.FilePath) || !PathUtils.IsSubpathOf(PathUtils.GetParent(typeof(IAnalysisVariable).Assembly.Location), v.Location.FilePath))
                                  .ToArray();

                if (expectedLocations != null)
                {
                    Assert.IsNotNull(actualLocations);

                    Assert.AreEqual(expectedLocations.Length, actualLocations.Length, "incorrect number of locations");
                    for (int i = 0; i < expectedLocations.Length; i++)
                    {
                        Assert.AreEqual(expectedLocations[i].StartLine, actualLocations[i].Location.StartLine, "incorrect line");
                        Assert.AreEqual(expectedLocations[i].StartColumn, actualLocations[i].Location.StartColumn, "incorrect column");
                        if (expectedLocations[i].FilePath != null)
                        {
                            Assert.AreEqual(expectedLocations[i].FilePath, Path.GetFileName(actualLocations[i].Location.FilePath));
                        }
                    }
                }
                else
                {
                    Assert.AreEqual(0, actualLocations.Length, "incorrect number of locations");
                }
            }
示例#2
0
            public async Task CheckDefinitionLocation(int pos, int length, AnalysisLocation expected)
            {
                var entry = (AnalysisEntry)_view.GetAnalysisEntry();

                entry.Analyzer.WaitForCompleteAnalysis(_ => true);

                var trackingSpan = _view.CurrentSnapshot.CreateTrackingSpan(pos, length, SpanTrackingMode.EdgeInclusive);
                var snapshotSpan = trackingSpan.GetSpan(_view.CurrentSnapshot);
                var result       = await NavigableSymbolSource.GetDefinitionLocationAsync(entry, _view.View.TextView, snapshotSpan);

                if (expected != null)
                {
                    Assert.IsNotNull(result);
                    Assert.AreEqual(expected.Line, result.Line);
                    Assert.AreEqual(expected.Column, result.Column);
                    Assert.AreEqual(expected.FilePath, Path.GetFileName(result.FilePath));
                }
                else
                {
                    Assert.IsNull(result);
                }
            }
示例#3
0
            public async Task CheckDefinitionLocations(int pos, int length, params LocationInfo[] expectedLocations)
            {
                var entry = (AnalysisEntry)_view.GetAnalysisEntry();

                entry.Analyzer.WaitForCompleteAnalysis(_ => true);

                var trackingSpan = _view.CurrentSnapshot.CreateTrackingSpan(pos, length, SpanTrackingMode.EdgeInclusive);
                var snapshotSpan = trackingSpan.GetSpan(_view.CurrentSnapshot);

                Console.WriteLine("Finding definition of \"{0}\"", snapshotSpan.GetText());
                var actualLocations = await NavigableSymbolSource.GetDefinitionLocationsAsync(entry, snapshotSpan.Start);

                if (expectedLocations != null)
                {
                    Assert.IsNotNull(actualLocations);

                    Console.WriteLine($"Actual locations for pos={pos}, length={length}:");
                    foreach (var actualLocation in actualLocations)
                    {
                        Console.WriteLine($"file={actualLocation.Location.DocumentUri},line={actualLocation.Location.StartLine},col={actualLocation.Location.StartColumn}");
                    }

                    Assert.AreEqual(expectedLocations.Length, actualLocations.Length, "incorrect number of locations");
                    for (int i = 0; i < expectedLocations.Length; i++)
                    {
                        Assert.AreEqual(expectedLocations[i].StartLine, actualLocations[i].Location.StartLine, "incorrect line");
                        Assert.AreEqual(expectedLocations[i].StartColumn, actualLocations[i].Location.StartColumn, "incorrect column");
                        if (expectedLocations[i].FilePath != null)
                        {
                            Assert.AreEqual(expectedLocations[i].FilePath, Path.GetFileName(actualLocations[i].Location.FilePath));
                        }
                    }
                }
                else
                {
                    Assert.AreEqual(0, actualLocations.Length, "incorrect number of locations");
                }
            }
示例#4
0
        private static void TestQuickInfo(PythonEditor view, int start, int end, string expected = null)
        {
            var snapshot = view.CurrentSnapshot;

            for (var i = start; i < end; i++)
            {
                var quickInfo = view.Analyzer.GetQuickInfoAsync(
                    (AnalysisEntry)view.GetAnalysisEntry(),
                    view.View.TextView,
                    new SnapshotPoint(snapshot, start)
                    ).Result;

                if (expected != null)
                {
                    Assert.IsNotNull(quickInfo);
                    Assert.AreEqual(expected, quickInfo.Text);
                }
                else
                {
                    Assert.IsNull(quickInfo);
                }
            }
        }
示例#5
0
            public async Task CheckDefinitionLocations(int pos, int length, params AnalysisLocation[] expectedLocations)
            {
                var entry = (AnalysisEntry)_view.GetAnalysisEntry();

                entry.Analyzer.WaitForCompleteAnalysis(_ => true);

                var trackingSpan    = _view.CurrentSnapshot.CreateTrackingSpan(pos, length, SpanTrackingMode.EdgeInclusive);
                var snapshotSpan    = trackingSpan.GetSpan(_view.CurrentSnapshot);
                var actualLocations = await NavigableSymbolSource.GetDefinitionLocationsAsync(entry, snapshotSpan.Start);

                if (expectedLocations != null)
                {
                    Assert.IsNotNull(actualLocations);

                    Console.WriteLine($"Actual locations for pos={pos}, length={length}:");
                    foreach (var actualLocation in actualLocations)
                    {
                        Console.WriteLine($"{actualLocation.Line}, {actualLocation.Column}");
                    }

                    Assert.AreEqual(expectedLocations.Length, actualLocations.Length);
                    for (int i = 0; i < expectedLocations.Length; i++)
                    {
                        Assert.AreEqual(expectedLocations[i].Line, actualLocations[i].Line);
                        Assert.AreEqual(expectedLocations[i].Column, actualLocations[i].Column);
                        if (expectedLocations[i].FilePath != null)
                        {
                            Assert.AreEqual(expectedLocations[i].FilePath, Path.GetFileName(actualLocations[i].FilePath));
                        }
                    }
                }
                else
                {
                    Assert.AreEqual(0, actualLocations.Length);
                }
            }