forked from dotnet/roslynator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code fix for CS0037 (dotnet#929)
- Loading branch information
1 parent
d9794cf
commit 49a91f2
Showing
5 changed files
with
105 additions
and
7 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
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
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
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
73 changes: 73 additions & 0 deletions
73
...ests/CodeFixes.Tests/CS0037CannotConvertNullToTypeBecauseItIsNonNullableValueTypeTests.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,73 @@ | ||
// Copyright (c) Josef Pihrt and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using Roslynator.Testing.CSharp; | ||
using Xunit; | ||
|
||
namespace Roslynator.CSharp.CodeFixes.Tests | ||
{ | ||
public class CS0037CannotConvertNullToTypeBecauseItIsNonNullableValueTypeTests : AbstractCSharpCompilerDiagnosticFixVerifier<RemovePropertyOrFieldInitializerCodeFixProvider> | ||
{ | ||
public override string DiagnosticId { get; } = CompilerDiagnosticIdentifiers.CS0037_CannotConvertNullToTypeBecauseItIsNonNullableValueType; | ||
|
||
[Fact, Trait(Traits.CodeFix, CompilerDiagnosticIdentifiers.CS0037_CannotConvertNullToTypeBecauseItIsNonNullableValueType)] | ||
public async Task Test_RemovePropertyInitializer() | ||
{ | ||
await VerifyFixAsync(@" | ||
using System; | ||
class C | ||
{ | ||
public StringSplitOptions Options { get; set } = null; | ||
} | ||
", @" | ||
using System; | ||
class C | ||
{ | ||
public StringSplitOptions Options { get; set } | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(DiagnosticId, CodeFixIdentifiers.RemovePropertyOrFieldInitializer)); | ||
} | ||
|
||
[Fact, Trait(Traits.CodeFix, CompilerDiagnosticIdentifiers.CS0037_CannotConvertNullToTypeBecauseItIsNonNullableValueType)] | ||
public async Task Test_RemovePropertyInitializer_NullForgivingOperator() | ||
{ | ||
await VerifyFixAsync(@" | ||
using System; | ||
class C | ||
{ | ||
public StringSplitOptions Options { get; set } = null!; | ||
} | ||
", @" | ||
using System; | ||
class C | ||
{ | ||
public StringSplitOptions Options { get; set } | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(DiagnosticId, CodeFixIdentifiers.RemovePropertyOrFieldInitializer)); | ||
} | ||
|
||
[Fact, Trait(Traits.CodeFix, CompilerDiagnosticIdentifiers.CS0037_CannotConvertNullToTypeBecauseItIsNonNullableValueType)] | ||
public async Task Test_RemoveFieldInitializer() | ||
{ | ||
await VerifyFixAsync(@" | ||
using System; | ||
class C | ||
{ | ||
public StringSplitOptions Options = null!; | ||
} | ||
", @" | ||
using System; | ||
class C | ||
{ | ||
public StringSplitOptions Options; | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(DiagnosticId, CodeFixIdentifiers.RemovePropertyOrFieldInitializer)); | ||
} | ||
} | ||
} |