From ec4ad2ff5d9a1dc8dee510ba830e22376923921c Mon Sep 17 00:00:00 2001 From: John Venable Date: Sun, 9 Aug 2015 17:36:31 -0400 Subject: [PATCH] Add regression tests for #1161 --- .../OrderingRules/SA1209UnitTests.cs | 29 +++++++++++++++---- .../OrderingRules/SA1210UnitTests.cs | 22 ++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1209UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1209UnitTests.cs index d5fd39d5e..7ea749071 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1209UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1209UnitTests.cs @@ -113,12 +113,7 @@ class A } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation("Test0.cs", 7, 5), - }; - - await this.VerifyCSharpDiagnosticAsync(compilationUnit, expected, CancellationToken.None).ConfigureAwait(false); + await this.VerifyCSharpDiagnosticAsync(compilationUnit, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } [Fact] @@ -166,6 +161,28 @@ class A await this.VerifyCSharpDiagnosticAsync(namespaceDeclaration, expected, CancellationToken.None).ConfigureAwait(false); } + [Fact] + public async Task TestPreprocessorDirectivesAsync() + { + var testCode = @" +using System; +using Microsoft.VisualStudio; +using MyList = System.Collections.Generic.List; + +#if true +using Threads = System.Threading; +using Microsoft.CodeAnalysis; +#else +using Threads = System.Threading; +using Microsoft.CodeAnalysis; +#endif"; + + // else block is skipped + var expected = this.CSharpDiagnostic().WithLocation(7, 1); + + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } + protected override IEnumerable GetCSharpDiagnosticAnalyzers() { yield return new SA1209UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives(); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1210UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1210UnitTests.cs index 949dcf348..c9a577762 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1210UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1210UnitTests.cs @@ -190,6 +190,28 @@ namespace Test await this.VerifyCSharpDiagnosticAsync(compilationUnit, expected, CancellationToken.None).ConfigureAwait(false); } + [Fact] + public async Task TestPreprocessorDirectivesAsync() + { + var testCode = @" +using System; +using Microsoft.VisualStudio; +using MyList = System.Collections.Generic.List; + +#if true +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis; +#else +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis; +#endif"; + + // else block is skipped + var expected = this.CSharpDiagnostic().WithLocation(7, 1); + + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } + protected override IEnumerable GetCSharpDiagnosticAnalyzers() { yield return new SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace();