示例#1
0
        protected async Task TestAsync(string codeWithMarker)
        {
            using var workspace = CreateWorkspace(codeWithMarker);

            var hostDocument        = workspace.Documents.First();
            var initialTextSnapshot = hostDocument.GetTextBuffer().CurrentSnapshot;
            var documentId          = hostDocument.Id;

            var document     = workspace.CurrentSolution.GetDocument(documentId);
            var service      = document.GetLanguageService <ITodoCommentService>();
            var todoComments = await service.GetTodoCommentsAsync(
                document,
                TodoCommentDescriptor.Parse(
                    workspace.Options.GetOption(TodoCommentOptions.TokenList)
                    ),
                CancellationToken.None
                );

            using var _ = ArrayBuilder <TodoCommentData> .GetInstance(out var converted);

            await TodoComment.ConvertAsync(
                document,
                todoComments,
                converted,
                CancellationToken.None
                );

            var expectedLists = hostDocument.SelectedSpans;

            Assert.Equal(converted.Count, expectedLists.Count);

            var sourceText = await document.GetTextAsync();

            var tree = await document.GetSyntaxTreeAsync();

            for (var i = 0; i < converted.Count; i++)
            {
                var todo = converted[i];
                var span = expectedLists[i];

                var line = initialTextSnapshot.GetLineFromPosition(span.Start);
                var text = initialTextSnapshot.GetText(span.ToSpan());

                Assert.Equal(todo.MappedLine, line.LineNumber);
                Assert.Equal(todo.MappedColumn, span.Start - line.Start);
                Assert.Equal(todo.Message, text);
            }
        }
示例#2
0
        protected async Task TestAsync(string codeWithMarker)
        {
            using var workspace = CreateWorkspace(codeWithMarker);

            var hostDocument        = workspace.Documents.First();
            var initialTextSnapshot = hostDocument.GetTextBuffer().CurrentSnapshot;
            var documentId          = hostDocument.Id;

            var document  = workspace.CurrentSolution.GetDocument(documentId);
            var service   = document.GetLanguageService <ITodoCommentService>();
            var todoLists = await service.GetTodoCommentsAsync(document,
                                                               TodoCommentDescriptor.Parse(TodoCommentOptions.TokenList.DefaultValue),
                                                               CancellationToken.None);

            var expectedLists = hostDocument.SelectedSpans;

            Assert.Equal(todoLists.Length, expectedLists.Count);

            var sourceText = await document.GetTextAsync();

            var tree = await document.GetSyntaxTreeAsync();

            for (var i = 0; i < todoLists.Length; i++)
            {
                var todo = todoLists[i];
                var span = expectedLists[i];

                var line = initialTextSnapshot.GetLineFromPosition(span.Start);
                var text = initialTextSnapshot.GetText(span.ToSpan());

                var converted = todo.CreateSerializableData(document, sourceText, tree);

                Assert.Equal(converted.MappedLine, line.LineNumber);
                Assert.Equal(converted.MappedColumn, span.Start - line.Start);
                Assert.Equal(converted.Message, text);
            }
        }