コード例 #1
0
        private static void TestNavigator(
            string code,
            Func <ITextStructureNavigator, SnapshotSpan, SnapshotSpan> func,
            int startPosition,
            int startLength,
            int endPosition,
            int endLength,
            CSharpParseOptions options)
        {
            using (var workspace = TestWorkspace.CreateCSharp(code, options))
            {
                var buffer = workspace.Documents.First().GetTextBuffer();

                var provider = new TextStructureNavigatorProvider(
                    workspace.GetService <ITextStructureNavigatorSelectorService>(),
                    workspace.GetService <IContentTypeRegistryService>(),
                    workspace.GetService <IWaitIndicator>());

                var navigator = provider.CreateTextStructureNavigator(buffer);

                var actualSpan   = func(navigator, new SnapshotSpan(buffer.CurrentSnapshot, startPosition, startLength));
                var expectedSpan = new SnapshotSpan(buffer.CurrentSnapshot, endPosition, endLength);
                Assert.Equal(expectedSpan, actualSpan.Span);
            }
        }
コード例 #2
0
        private static void AssertExtent(string code, int pos, bool isSignificant, int start, int length, CSharpParseOptions options)
        {
            using (var workspace = TestWorkspace.CreateCSharp(code, options))
            {
                var buffer = workspace.Documents.First().GetTextBuffer();

                var provider = new TextStructureNavigatorProvider(
                    workspace.GetService <ITextStructureNavigatorSelectorService>(),
                    workspace.GetService <IContentTypeRegistryService>(),
                    workspace.GetService <IWaitIndicator>());

                var navigator = provider.CreateTextStructureNavigator(buffer);

                var extent = navigator.GetExtentOfWord(new SnapshotPoint(buffer.CurrentSnapshot, pos));
                Assert.Equal(isSignificant, extent.IsSignificant);

                var expectedSpan = new SnapshotSpan(buffer.CurrentSnapshot, start, length);
                Assert.Equal(expectedSpan, extent.Span);
            }
        }