-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve analyzer SimplifyCoalesceExpression (RCS1143)
- Loading branch information
1 parent
88dd4ce
commit 4c4281e
Showing
2 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Tests/Analyzers.Tests/RCS1143SimplifyCoalesceExpressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Roslynator.CSharp.CodeFixes; | ||
using Xunit; | ||
|
||
namespace Roslynator.CSharp.Analysis.Tests | ||
{ | ||
public class RCS1143SimplifyCoalesceExpressionTests : AbstractCSharpFixVerifier | ||
{ | ||
public override DiagnosticDescriptor Descriptor { get; } = DiagnosticDescriptors.SimplifyCoalesceExpression; | ||
|
||
public override DiagnosticAnalyzer Analyzer { get; } = new SimplifyCoalesceExpressionAnalyzer(); | ||
|
||
public override CodeFixProvider FixProvider { get; } = new BinaryExpressionCodeFixProvider(); | ||
|
||
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.SimplifyCoalesceExpression)] | ||
public async Task Test_DefaultOfNullableType() | ||
{ | ||
await VerifyDiagnosticAndFixAsync(@" | ||
class C | ||
{ | ||
void M() | ||
{ | ||
C x = null; | ||
int? y = x?.M2() [|?? default(int?)|]; | ||
} | ||
int M2() => default; | ||
} | ||
", @" | ||
class C | ||
{ | ||
void M() | ||
{ | ||
C x = null; | ||
int? y = x?.M2(); | ||
} | ||
int M2() => default; | ||
} | ||
"); | ||
} | ||
} | ||
} |