Skip to content

Commit

Permalink
Merge pull request #1192 from pdelvo/fix-1191
Browse files Browse the repository at this point in the history
Add regression test for SA1013 reporting on anonymous types in indexers
  • Loading branch information
sharwell committed Aug 12, 2015
2 parents 2088f26 + 99ec864 commit 44fb8f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,31 @@ public void TestMethod2()
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the analyzer will properly handle anonymous classes in indexers.
/// This is a regression test for <see href="https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1191">DotNetAnalyzers/StyleCopAnalyzers#1191</see>
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task TestIndexersAsync()
{
var testCode = @"namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
{
var dictionary = new System.Collections.Generic.Dictionary<object, object>();
dictionary[new { Foo = ""Foo"", Bar = 5 }] = 42;
}
}
}
";

// no space between closing curly bracket and closing bracket should not be reported by SA1013
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <inheritdoc/>
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ private static void HandleCloseBraceToken(SyntaxTreeAnalysisContext context, Syn
|| nextToken.IsKind(SyntaxKind.CommaToken)
|| nextToken.IsKind(SyntaxKind.SemicolonToken)
|| nextToken.IsKind(SyntaxKind.DotToken)
|| (nextToken.IsKind(SyntaxKind.QuestionToken) && nextToken.GetNextToken(includeZeroWidth: true).IsKind(SyntaxKind.DotToken));
|| (nextToken.IsKind(SyntaxKind.QuestionToken) && nextToken.GetNextToken(includeZeroWidth: true).IsKind(SyntaxKind.DotToken))
|| nextToken.IsKind(SyntaxKind.CloseBracketToken);
}
else
{
Expand Down

0 comments on commit 44fb8f6

Please sign in to comment.