Skip to content

Commit

Permalink
Add regression tests for DotNetAnalyzers#1161
Browse files Browse the repository at this point in the history
  • Loading branch information
Noryoko committed Aug 9, 2015
1 parent 2c9b101 commit ec4ad2f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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<int>;
#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<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
{
yield return new SA1209UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>;
#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<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
{
yield return new SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace();
Expand Down

0 comments on commit ec4ad2f

Please sign in to comment.