Skip to content

Commit

Permalink
Add regression test for suppression operator in returns
Browse files Browse the repository at this point in the history
Closes #2968
  • Loading branch information
sharwell committed Sep 3, 2019
1 parent e7ab2f3 commit 9847a55
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,59 @@ public void TestMethod<T>()

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(2968, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2968")]
public async Task TestExpressionBodyEndsWithSuppressionAsync()
{
const string testCode = @"using System;
#nullable enable
public class Foo
{
public T? TestMethod<T>() where T : class => throw null;
public IDisposable Service => this.TestMethod<IDisposable>([|)|] !;
}";
const string fixedCode = @"using System;
#nullable enable
public class Foo
{
public T? TestMethod<T>() where T : class => throw null;
public IDisposable Service => this.TestMethod<IDisposable>()!;
}";

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(2968, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2968")]
public async Task TestBlockBodyEndsWithSuppressionAsync()
{
const string testCode = @"using System;
#nullable enable
public class Foo
{
public T? TestMethod<T>() where T : class => throw null;
public IDisposable Service()
{
return this.TestMethod<IDisposable>([|)|] !;
}
}";
const string fixedCode = @"using System;
#nullable enable
public class Foo
{
public T? TestMethod<T>() where T : class => throw null;
public IDisposable Service()
{
return this.TestMethod<IDisposable>()!;
}
}";

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}

0 comments on commit 9847a55

Please sign in to comment.