-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Add/inline using static directive (RR0014, RR0180) (#988)
- Loading branch information
1 parent
f30b281
commit fe9ec66
Showing
8 changed files
with
249 additions
and
38 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
15 changes: 0 additions & 15 deletions
15
src/Tests.Old/Refactorings.Tests.Old/AddUsingStaticDirectiveRefactoring.cs
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/Tests.Old/Refactorings.Tests.Old/InlineUsingStaticRefactoring.cs
This file was deleted.
Oops, something went wrong.
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
163 changes: 163 additions & 0 deletions
163
src/Tests/Refactorings.Tests/RR0014AddUsingStaticDirectiveTests.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,163 @@ | ||
// 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.Refactorings.Tests | ||
{ | ||
public class RR0014AddUsingStaticDirectiveTests : AbstractCSharpRefactoringVerifier | ||
{ | ||
public override string RefactoringId { get; } = RefactoringIdentifiers.AddUsingStaticDirective; | ||
|
||
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.AddUsingStaticDirective)] | ||
public async Task Test_Math_Max() | ||
{ | ||
await VerifyRefactoringAsync(@" | ||
using System; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
int max = [|Math|].Max(1, 2); | ||
} | ||
} | ||
", @" | ||
using System; | ||
using static System.Math; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
int max = Max(1, 2); | ||
} | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(RefactoringId)); | ||
} | ||
|
||
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.AddUsingStaticDirective)] | ||
public async Task Test_Math_Max2() | ||
{ | ||
await VerifyRefactoringAsync(@" | ||
class C | ||
{ | ||
void M() | ||
{ | ||
int max = [|System.Math|].Max(1, 2); | ||
} | ||
} | ||
", @"using static System.Math; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
int max = Max(1, 2); | ||
} | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(RefactoringId)); | ||
} | ||
|
||
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.AddUsingStaticDirective)] | ||
public async Task Test_Math_Max3() | ||
{ | ||
await VerifyRefactoringAsync(@" | ||
class C | ||
{ | ||
void M() | ||
{ | ||
int max = [|global::System.Math|].Max(1, 2); | ||
} | ||
} | ||
", @"using static System.Math; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
int max = Max(1, 2); | ||
} | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(RefactoringId)); | ||
} | ||
|
||
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.AddUsingStaticDirective)] | ||
public async Task Test_SimpleMemberAccessExpression() | ||
{ | ||
await VerifyRefactoringAsync(@" | ||
using System; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
var x = [|StringComparer|].CurrentCulture.GetHashCode(); | ||
} | ||
} | ||
", @" | ||
using System; | ||
using static System.StringComparer; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
var x = CurrentCulture.GetHashCode(); | ||
} | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(RefactoringId)); | ||
} | ||
|
||
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.AddUsingStaticDirective)] | ||
public async Task Test_SimpleMemberAccessExpression2() | ||
{ | ||
await VerifyRefactoringAsync(@" | ||
class C | ||
{ | ||
void M() | ||
{ | ||
var x = [|System.StringComparer|].CurrentCulture.GetHashCode(); | ||
} | ||
} | ||
", @"using static System.StringComparer; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
var x = CurrentCulture.GetHashCode(); | ||
} | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(RefactoringId)); | ||
} | ||
|
||
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.AddUsingStaticDirective)] | ||
public async Task Test_Struct() | ||
{ | ||
await VerifyRefactoringAsync(@" | ||
using System; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
var x = [|TimeSpan|].Zero; | ||
} | ||
} | ||
", @" | ||
using System; | ||
using static System.TimeSpan; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
var x = Zero; | ||
} | ||
} | ||
", equivalenceKey: EquivalenceKey.Create(RefactoringId)); | ||
} | ||
} | ||
} |
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