Ejemplo n.º 1
0
        public void EntireRangeWithTransformation_RemoveClass()
        {
            var expectedResult = (IEnumerable <TextSpan>)null;
            var transformer    = new MockCodeCleanupProvider()
            {
                CleanupDocumentAsyncImpl = async(document, spans, options, cancellationToken) =>
                {
                    var root = await document.GetSyntaxRootAsync(cancellationToken);

                    root = root.RemoveCSharpMember(0);

                    expectedResult = SpecializedCollections.SingletonEnumerable(root.FullSpan);

                    return(document.WithSyntaxRoot(root));
                }
            };

            VerifyRange("{|b:class C {}|}", transformer, ref expectedResult);
        }
Ejemplo n.º 2
0
        public void RangeWithTransformation_RemoveMember()
        {
            var expectedResult = (IEnumerable <TextSpan>)null;
            var transformer    = new MockCodeCleanupProvider()
            {
                CleanupDocumentAsyncImpl = async(document, spans, options, cancellationToken) =>
                {
                    var root = await document.GetSyntaxRootAsync(cancellationToken);

                    var @class          = root.GetMember(0).GetMember(0);
                    var classWithMember = @class.RemoveCSharpMember(0);
                    root = root.ReplaceNode(@class, classWithMember);

                    expectedResult = SpecializedCollections.SingletonEnumerable(root.GetMember(0).GetMember(0).GetCodeCleanupSpan());

                    return(document.WithSyntaxRoot(root));
                }
            };

            VerifyRange("namespace N { {|b:class C { void Method() { } }|} }", transformer, ref expectedResult);
        }
Ejemplo n.º 3
0
        private static void VerifyRange(string code, ImmutableArray <ICodeCleanupProvider> codeCleanups, ImmutableArray <TextSpan> spans, ref IEnumerable <TextSpan> expectedResult, string language)
        {
            var result          = (IEnumerable <TextSpan>)null;
            var spanCodeCleanup = new MockCodeCleanupProvider()
            {
                CleanupDocumentAsyncImpl = (document, spans, options, cancellationToken) =>
                {
                    result = spans;
                    return(Task.FromResult(document));
                }
            };

            var document = CreateDocument(code, language);

            CodeCleaner.CleanupAsync(document, spans, codeCleanups.Concat(spanCodeCleanup)).Wait();

            var sortedSpans   = result.ToList();
            var expectedSpans = expectedResult.ToList();

            sortedSpans.Sort();
            expectedSpans.Sort();

            AssertEx.Equal(expectedSpans, sortedSpans);
        }
Ejemplo n.º 4
0
        public void RangeWithTransformation_OutsideOfRange()
        {
            var expectedResult = (IEnumerable <TextSpan>)null;
            var transformer    = new MockCodeCleanupProvider()
            {
                CleanupDocumentAsyncImpl = async(document, spans, options, cancellationToken) =>
                {
                    var root = await document.GetSyntaxRootAsync(cancellationToken);

                    var member        = root.GetMember(0).GetMember(0).GetMember(0);
                    var previousToken = member.GetFirstToken().GetPreviousToken().GetPreviousToken();
                    var nextToken     = member.GetLastToken().GetNextToken().GetNextToken();

                    root = root.ReplaceToken(previousToken, CSharp.SyntaxFactory.Identifier(previousToken.LeadingTrivia, previousToken.ValueText, previousToken.TrailingTrivia));
                    root = root.ReplaceToken(nextToken, CSharp.SyntaxFactory.Token(nextToken.LeadingTrivia, CSharp.CSharpExtensions.Kind(nextToken), nextToken.TrailingTrivia));

                    expectedResult = SpecializedCollections.EmptyEnumerable <TextSpan>();

                    return(document.WithSyntaxRoot(root));
                }
            };

            VerifyRange("namespace N { class C { {|b:void Method() { }|} } }", transformer, ref expectedResult);
        }