Exemple #1
0
        public async Task VerifyRefactoringAsync(
            string source,
            string inlineSource,
            string inlineExpected,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default)
        {
            (TextSpan span, string source2, string expected) = TextParser.ReplaceEmptySpan(source, inlineSource, inlineExpected);

            TextParserResult result = TextParser.GetSpans(source2, LinePositionSpanInfoComparer.IndexDescending);

            if (result.Spans.Any())
            {
                await VerifyRefactoringAsync(
                    source : result.Text,
                    expected : expected,
                    spans : result.Spans.Select(f => f.Span),
                    equivalenceKey : equivalenceKey,
                    options : options,
                    cancellationToken : cancellationToken).ConfigureAwait(false);
            }
            else
            {
                await VerifyRefactoringAsync(
                    source : source2,
                    expected : expected,
                    span : span,
                    equivalenceKey : equivalenceKey,
                    options : options,
                    cancellationToken : cancellationToken).ConfigureAwait(false);
            }
        }
        public async Task VerifyRefactoringAsync(
            string theory,
            string fromData,
            string toData,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default)
        {
            (TextSpan span, string source, string expected) = TextParser.ReplaceEmptySpan(theory, fromData, toData);

            TextParserResult result = TextParser.GetSpans(source, reverse: true);

            if (result.Spans.Any())
            {
                await VerifyRefactoringAsync(
                    source : result.Text,
                    expected : expected,
                    spans : result.Spans.Select(f => f.Span),
                    equivalenceKey : equivalenceKey,
                    options : options,
                    cancellationToken : cancellationToken).ConfigureAwait(false);
            }
            else
            {
                await VerifyRefactoringAsync(
                    source : source,
                    expected : expected,
                    span : span,
                    equivalenceKey : equivalenceKey,
                    options : options,
                    cancellationToken : cancellationToken).ConfigureAwait(false);
            }
        }
Exemple #3
0
        public async Task VerifyDiagnosticAsync(
            string source,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default)
        {
            TextParserResult result = TextParser.GetSpans(source);

            await VerifyDiagnosticAsync(
                result.Text,
                result.Spans.Select(f => CreateDiagnostic(f.Span, f.LineSpan)),
                additionalSources : null,
                options : options,
                cancellationToken).ConfigureAwait(false);
        }
Exemple #4
0
        public async Task VerifyNoRefactoringAsync(
            string source,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default)
        {
            TextParserResult result = TextParser.GetSpans(source, LinePositionSpanInfoComparer.IndexDescending);

            await VerifyNoRefactoringAsync(
                source : result.Text,
                spans : result.Spans.Select(f => f.Span),
                equivalenceKey : equivalenceKey,
                options : options,
                cancellationToken : cancellationToken).ConfigureAwait(false);
        }
Exemple #5
0
        public async Task VerifyDiagnosticAsync(
            string source,
            string inlineSource,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default)
        {
            (TextSpan span, string text) = TextParser.ReplaceEmptySpan(source, inlineSource);

            TextParserResult result = TextParser.GetSpans(text);

            if (result.Spans.Any())
            {
                await VerifyDiagnosticAsync(result.Text, result.Spans.Select(f => f.Span), options, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                await VerifyDiagnosticAsync(text, span, options, cancellationToken).ConfigureAwait(false);
            }
        }
        public async Task VerifyRefactoringAsync(
            string source,
            string expected,
            string[] additionalSources          = null,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default)
        {
            TextParserResult result = TextParser.GetSpans(source, reverse: true);

            await VerifyRefactoringAsync(
                source : result.Text,
                expected : expected,
                spans : result.Spans.Select(f => f.Span),
                additionalSources : additionalSources,
                equivalenceKey : equivalenceKey,
                options : options,
                cancellationToken : cancellationToken).ConfigureAwait(false);
        }
Exemple #7
0
        public static void TestExpressionChainReversedEnumerator_WithSpan5()
        {
            const string     s      = @"
class C
{
    void M(string a, string b)
    {
        string s = [|a|] + b;
    }
}";
            TextParserResult result = TextParser.GetSpans(s);

            BinaryExpressionSyntax be = CSharpSyntaxTree.ParseText(result.Text).GetRoot().FirstDescendant <BinaryExpressionSyntax>();

            ExpressionChain.Reversed.Enumerator en = new ExpressionChain(be, result.Spans[0].Span).Reverse().GetEnumerator();

            Assert.True(en.MoveNext() && en.Current == be.Left);
            Assert.True(!en.MoveNext());
        }
Exemple #8
0
        public async Task VerifyRefactoringAsync(
            string source,
            string expected,
            IEnumerable <string> additionalSources = null,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default)
        {
            TextParserResult result = TextParser.GetSpans(source, LinePositionSpanInfoComparer.IndexDescending);

            await VerifyRefactoringAsync(
                source : result.Text,
                expected : expected,
                spans : result.Spans.Select(f => f.Span),
                additionalSources : additionalSources,
                equivalenceKey : equivalenceKey,
                options : options,
                cancellationToken : cancellationToken);
        }
Exemple #9
0
        public static void TestExpressionChainEnumerator_WithSpan2()
        {
            const string     s      = @"
class C
{
    void M(string a, string b, string c, string d)
    {
        string s = a + b + [|c + d|];
    }
}";
            TextParserResult result = TextParser.GetSpans(s);

            BinaryExpressionSyntax be = CSharpSyntaxTree.ParseText(result.Text).GetRoot().FirstDescendant <BinaryExpressionSyntax>();
            var be2 = (BinaryExpressionSyntax)be.Left;

            ExpressionChain.Enumerator en = new ExpressionChain(be, result.Spans[0].Span).GetEnumerator();

            Assert.True(en.MoveNext() && en.Current == be2.Right);
            Assert.True(en.MoveNext() && en.Current == be.Right);
            Assert.True(!en.MoveNext());
        }
Exemple #10
0
 protected IEnumerable <Diagnostic> CreateDiagnostics(DiagnosticDescriptor descriptor, TextParserResult result)
 {
     return(result.Spans.Select(spanInfo => CreateDiagnostic(descriptor, spanInfo)));
 }