Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression test for SA1013 reporting on anonymous types in indexers #1192

Merged
merged 2 commits into from
Aug 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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