protected async Task TestBraceHighlightingAsync(
            string markup,
            ParseOptions options        = null,
            bool swapAnglesWithBrackets = false
            )
        {
            MarkupTestFile.GetPositionAndSpans(
                markup,
                out var text,
                out int cursorPosition,
                out var expectedSpans
                );

            // needed because markup test file can't support [|[|] to indicate selecting
            // just an open bracket.
            if (swapAnglesWithBrackets)
            {
                text = text.Replace("<", "[").Replace(">", "]");
            }

            using (var workspace = CreateWorkspace(text, options))
            {
                WpfTestRunner.RequireWpfFact(
                    $"{nameof(AbstractBraceHighlightingTests)}.{nameof(TestBraceHighlightingAsync)} creates asynchronous taggers"
                    );

                var provider = new BraceHighlightingViewTaggerProvider(
                    workspace.GetService <IThreadingContext>(),
                    GetBraceMatchingService(workspace),
                    workspace.GetService <IForegroundNotificationService>(),
                    AsynchronousOperationListenerProvider.NullProvider
                    );

                var testDocument = workspace.Documents.First();
                var buffer       = testDocument.GetTextBuffer();
                var document     = buffer.CurrentSnapshot
                                   .GetRelatedDocumentsWithChanges()
                                   .FirstOrDefault();
                var context = new TaggerContext <BraceHighlightTag>(
                    document,
                    buffer.CurrentSnapshot,
                    new SnapshotPoint(buffer.CurrentSnapshot, cursorPosition)
                    );
                await provider.GetTestAccessor().ProduceTagsAsync(context);

                var expectedHighlights = expectedSpans
                                         .Select(ts => ts.ToSpan())
                                         .OrderBy(s => s.Start)
                                         .ToList();
                var actualHighlights = context.tagSpans
                                       .Select(ts => ts.Span.Span)
                                       .OrderBy(s => s.Start)
                                       .ToList();

                Assert.Equal(expectedHighlights, actualHighlights);
            }
        }
Exemplo n.º 2
0
        private static async Task <IEnumerable <ITagSpan <BraceHighlightTag> > > ProduceTagsAsync(
            TestWorkspace workspace,
            ITextBuffer buffer,
            int position)
        {
            var producer = new BraceHighlightingViewTaggerProvider(
                workspace.ExportProvider.GetExportedValue <IThreadingContext>(),
                workspace.GetService <IBraceMatchingService>(),
                AsynchronousOperationListenerProvider.NullProvider);

            var context = new TaggerContext <BraceHighlightTag>(
                buffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault(),
                buffer.CurrentSnapshot, new SnapshotPoint(buffer.CurrentSnapshot, position));
            await producer.GetTestAccessor().ProduceTagsAsync(context);

            return(context.tagSpans);
        }