<commit_before>﻿// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.SpacingRules
{
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Microsoft.CodeAnalysis;
    using Microsoft.CodeAnalysis.CodeFixes;
    using Microsoft.CodeAnalysis.Diagnostics;
    using StyleCop.Analyzers.SpacingRules;
    using TestHelper;
    using Xunit;

    /// <summary>
    /// Unit tests for <see cref="SA1009ClosingParenthesisMustBeSpacedCorrectly"/>
    /// </summary>
    public class SA1009UnitTests : CodeFixVerifier
    {
        [Fact]
        public async Task TestMethodWithNoParametersAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method()
    {
    }
}";

            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestMethodWithWhitespaceBeforeClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method( )
    {
    }
}";
            const string fixedCode = @"using System;

public class Foo
{
    public void Method()
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(5, 25);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestDocumentationMethodReferenceWithWhitespaceBeforeClosingParenthesisAsync()
        {
            const string testCode = @"
public class Foo
{
    /// <see cref=""Method( )""/>
    public void Method()
    {
    }
}";
            const string fixedCode = @"
public class Foo
{
    /// <see cref=""Method()""/>
    public void Method()
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(4, 28);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestMethodWith2CorrectlySpacedParametersAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestMethodWith2ParametersAndSpaceBeforeClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method(int param1, int param2 )
    {
    }
}";

            const string fixedCode = @"using System;

public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(5, 47);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestAttributeWithParametersAndNoSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;
using System.Security.Permissions;

[PermissionSet(SecurityAction.LinkDemand, Name = ""FullTrust"")]
public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";
            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestAttributeWithParametersAndSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;
using System.Security.Permissions;

[PermissionSet(SecurityAction.LinkDemand, Name = ""FullTrust"") ]
public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            const string fixedCode = @"using System;
using System.Security.Permissions;

[PermissionSet(SecurityAction.LinkDemand, Name = ""FullTrust"")]
public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(4, 61);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestConstructorInheritenceWithSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public Foo(int i) : base()
    {
    }
}";

            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestConstructorInheritenceWithNoSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public Foo(int i): base()
    {
    }
}";

            const string fixedCode = @"using System;

public class Foo
{
    public Foo(int i) : base()
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(string.Empty, "followed").WithLocation(5, 21);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestLambdaExpressionWithNoSpaceAfterClosingParenthesisAsync()
        {
            var invalidStatement = @"System.EventHandler handler = (s, e)=> { };";
            var validStatement = @"System.EventHandler handler = (s, e) => { };";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(string.Empty, "followed").WithLocation(7, 48);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Theory]
        [InlineData("+")]
        [InlineData("-")]
        [InlineData("*")]
        [InlineData("/")]
        public async Task TestSpaceAfterParenthisisInArithmeticOperationAsync(string operatorValue)
        {
            // e.g. var i = (1 + 1) + 2
            var validStatement = string.Format(@"var i = (1 + 1) {0} 2;", operatorValue);

            await this.TestWhitespaceInStatementOrDeclAsync(validStatement, string.Empty, EmptyDiagnosticResults).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestNoSpaceAfterParenthisisInAddOperationAsync()
        {
            // Note - this looks wrong but according to comments in the implementation "this will be reported as SA1022"
            var invalidStatement = @"var i = (1 + 1)+ 2;";

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, string.Empty, EmptyDiagnosticResults).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestNoSpaceAfterParenthisisInSubtractOperationAsync()
        {
            // Note - this looks wrong but according to comments in the implementation "this will be reported as SA1021"
            var invalidStatement = @"var i = (1 + 1)- 2;";

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, string.Empty, EmptyDiagnosticResults).ConfigureAwait(false);
        }

        [Theory]
        [InlineData("*")]
        [InlineData("/")]
        public async Task TestNoSpaceAfterParenthisisInArithmeticOperationAsync(string operatorValue)
        {
            // e.g. var i = (1 + 1)* 2;
            var invalidStatement = string.Format(@"var i = (1 + 1){0} 2;", operatorValue);
            var validStatement = string.Format(@"var i = (1 + 1) {0} 2;", operatorValue);

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(string.Empty, "followed").WithLocation(7, 27);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceBeforeParenthisInIncrementingForLoopAsync()
        {
            var invalidStatement = @"for (int i = 0; i < 10; i++ )
            {
            }";
            var validStatement = @"for (int i = 0; i < 10; i++)
            {
            }";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 41);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceBeforeParenthisInDecrementingForLoopAsync()
        {
            var invalidStatement = @"for (int i = 0; i < 10; i-- )
            {
            }";
            var validStatement = @"for (int i = 0; i < 10; i--)
            {
            }";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 41);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceInCastAsync()
        {
            var invalidStatement = @"var i = (int) 1;";
            var validStatement = @"var i = (int)1;";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 25);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceInConstructorCallAsync()
        {
            var invalidStatement = @"var o = new object() ;";
            var validStatement = @"var o = new object();";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 32);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceMethodCallFollowedByPropertyGetAsync()
        {
            var invalidStatement = @"var o = new Baz() .Test;";
            var validStatement = @"var o = new Baz().Test;";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 29);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceMethodCallFollowedByConditionalAccessPropertyGetAsync()
        {
            var invalidStatement = @"var o = new Baz() ?.Test;";
            var validStatement = @"var o = new Baz()?.Test;";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 29);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceMethodCallFollowedByPointerDereferenceAsync()
        {
            var invalidStatement = @"var o = GetPointer() ->ToString();";
            var validStatement = @"var o = GetPointer()->ToString();";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 32);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceOperationInDoubleSetOfParenthesisAsync()
        {
            var invalidStatement = @"var o = ((1 + 1) );";
            var validStatement = @"var o = ((1 + 1));";

            DiagnosticResult[] expected =
            {
                this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 28),
                this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 30),
            };

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Theory]
        [InlineData("++")]
        [InlineData("--")]
        public async Task TestSpaceIncrementOrDecrementOperatorFollowingParenthesisAsync(string operatorValue)
        {
            var invalidStatement = string.Format(
                @"int i = 0;
            (i) {0};",
            operatorValue);
            var validStatement = string.Format(
                @"int i = 0;
            (i){0};",
            operatorValue);

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 15);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceBetweenClosingBraceAndParenthesisAsync()
        {
            var invalidStatement = @"var x = new System.Action(() => { } );";
            var validStatement = @"var x = new System.Action(() => { });";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 49);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);<commit_msg>Fix violations of SA1137 (Elements should have the same indentation)<commit_after>﻿// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.SpacingRules
{
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Microsoft.CodeAnalysis;
    using Microsoft.CodeAnalysis.CodeFixes;
    using Microsoft.CodeAnalysis.Diagnostics;
    using StyleCop.Analyzers.SpacingRules;
    using TestHelper;
    using Xunit;

    /// <summary>
    /// Unit tests for <see cref="SA1009ClosingParenthesisMustBeSpacedCorrectly"/>
    /// </summary>
    public class SA1009UnitTests : CodeFixVerifier
    {
        [Fact]
        public async Task TestMethodWithNoParametersAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method()
    {
    }
}";

            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestMethodWithWhitespaceBeforeClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method( )
    {
    }
}";
            const string fixedCode = @"using System;

public class Foo
{
    public void Method()
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(5, 25);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestDocumentationMethodReferenceWithWhitespaceBeforeClosingParenthesisAsync()
        {
            const string testCode = @"
public class Foo
{
    /// <see cref=""Method( )""/>
    public void Method()
    {
    }
}";
            const string fixedCode = @"
public class Foo
{
    /// <see cref=""Method()""/>
    public void Method()
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(4, 28);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestMethodWith2CorrectlySpacedParametersAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestMethodWith2ParametersAndSpaceBeforeClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public void Method(int param1, int param2 )
    {
    }
}";

            const string fixedCode = @"using System;

public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(5, 47);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestAttributeWithParametersAndNoSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;
using System.Security.Permissions;

[PermissionSet(SecurityAction.LinkDemand, Name = ""FullTrust"")]
public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";
            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestAttributeWithParametersAndSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;
using System.Security.Permissions;

[PermissionSet(SecurityAction.LinkDemand, Name = ""FullTrust"") ]
public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            const string fixedCode = @"using System;
using System.Security.Permissions;

[PermissionSet(SecurityAction.LinkDemand, Name = ""FullTrust"")]
public class Foo
{
    public void Method(int param1, int param2)
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(4, 61);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestConstructorInheritenceWithSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public Foo(int i) : base()
    {
    }
}";

            await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestConstructorInheritenceWithNoSpaceAfterClosingParenthesisAsync()
        {
            const string testCode = @"using System;

public class Foo
{
    public Foo(int i): base()
    {
    }
}";

            const string fixedCode = @"using System;

public class Foo
{
    public Foo(int i) : base()
    {
    }
}";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(string.Empty, "followed").WithLocation(5, 21);

            await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
            await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestLambdaExpressionWithNoSpaceAfterClosingParenthesisAsync()
        {
            var invalidStatement = @"System.EventHandler handler = (s, e)=> { };";
            var validStatement = @"System.EventHandler handler = (s, e) => { };";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(string.Empty, "followed").WithLocation(7, 48);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Theory]
        [InlineData("+")]
        [InlineData("-")]
        [InlineData("*")]
        [InlineData("/")]
        public async Task TestSpaceAfterParenthisisInArithmeticOperationAsync(string operatorValue)
        {
            // e.g. var i = (1 + 1) + 2
            var validStatement = string.Format(@"var i = (1 + 1) {0} 2;", operatorValue);

            await this.TestWhitespaceInStatementOrDeclAsync(validStatement, string.Empty, EmptyDiagnosticResults).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestNoSpaceAfterParenthisisInAddOperationAsync()
        {
            // Note - this looks wrong but according to comments in the implementation "this will be reported as SA1022"
            var invalidStatement = @"var i = (1 + 1)+ 2;";

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, string.Empty, EmptyDiagnosticResults).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestNoSpaceAfterParenthisisInSubtractOperationAsync()
        {
            // Note - this looks wrong but according to comments in the implementation "this will be reported as SA1021"
            var invalidStatement = @"var i = (1 + 1)- 2;";

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, string.Empty, EmptyDiagnosticResults).ConfigureAwait(false);
        }

        [Theory]
        [InlineData("*")]
        [InlineData("/")]
        public async Task TestNoSpaceAfterParenthisisInArithmeticOperationAsync(string operatorValue)
        {
            // e.g. var i = (1 + 1)* 2;
            var invalidStatement = string.Format(@"var i = (1 + 1){0} 2;", operatorValue);
            var validStatement = string.Format(@"var i = (1 + 1) {0} 2;", operatorValue);

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(string.Empty, "followed").WithLocation(7, 27);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceBeforeParenthisInIncrementingForLoopAsync()
        {
            var invalidStatement = @"for (int i = 0; i < 10; i++ )
            {
            }";
            var validStatement = @"for (int i = 0; i < 10; i++)
            {
            }";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 41);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceBeforeParenthisInDecrementingForLoopAsync()
        {
            var invalidStatement = @"for (int i = 0; i < 10; i-- )
            {
            }";
            var validStatement = @"for (int i = 0; i < 10; i--)
            {
            }";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 41);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceInCastAsync()
        {
            var invalidStatement = @"var i = (int) 1;";
            var validStatement = @"var i = (int)1;";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 25);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceInConstructorCallAsync()
        {
            var invalidStatement = @"var o = new object() ;";
            var validStatement = @"var o = new object();";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 32);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceMethodCallFollowedByPropertyGetAsync()
        {
            var invalidStatement = @"var o = new Baz() .Test;";
            var validStatement = @"var o = new Baz().Test;";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 29);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceMethodCallFollowedByConditionalAccessPropertyGetAsync()
        {
            var invalidStatement = @"var o = new Baz() ?.Test;";
            var validStatement = @"var o = new Baz()?.Test;";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 29);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceMethodCallFollowedByPointerDereferenceAsync()
        {
            var invalidStatement = @"var o = GetPointer() ->ToString();";
            var validStatement = @"var o = GetPointer()->ToString();";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 32);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceOperationInDoubleSetOfParenthesisAsync()
        {
            var invalidStatement = @"var o = ((1 + 1) );";
            var validStatement = @"var o = ((1 + 1));";

            DiagnosticResult[] expected =
            {
                this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 28),
                this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 30),
            };

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Theory]
        [InlineData("++")]
        [InlineData("--")]
        public async Task TestSpaceIncrementOrDecrementOperatorFollowingParenthesisAsync(string operatorValue)
        {
            var invalidStatement = string.Format(
                @"int i = 0;
            (i) {0};",
                operatorValue);
            var validStatement = string.Format(
                @"int i = 0;
            (i){0};",
                operatorValue);

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 15);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
        }

        [Fact]
        public async Task TestSpaceBetweenClosingBraceAndParenthesisAsync()
        {
            var invalidStatement = @"var x = new System.Action(() => { } );";
            var validStatement = @"var x = new System.Action(() => { });";

            DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 49);

            await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
{'fraction_non_alphanumeric': 0.10332529465711084, 'fraction_numerical': 0.009102951666043952, 'mean_word_length': 2.8097826086956523, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1892649', 'n_tokens_mistral': 8162, 'n_tokens_neox': 7801, 'n_words': 1702}