-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11168 from Hosch250/UseBraces2
Adds an analyzer/codefix for adding missing braces Fixes #10942
- Loading branch information
Showing
13 changed files
with
1,157 additions
and
1 deletion.
There are no files selected for viewing
267 changes: 267 additions & 0 deletions
267
src/EditorFeatures/CSharpTest/AddBraces/AddBracesFixAllTests.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,267 @@ | ||
using System.Threading.Tasks; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.AddBraces | ||
{ | ||
public partial class AddBracesTests | ||
{ | ||
[Fact] | ||
[Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)] | ||
[Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] | ||
public async Task TestFixAllInDocument() | ||
{ | ||
var input = @" | ||
<Workspace> | ||
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true""> | ||
<Document> | ||
class Program1 | ||
{ | ||
static void Main() | ||
{ | ||
{|FixAllInDocument:if|} (true) return; | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
<Document> | ||
class Program2 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true""> | ||
<Document> | ||
class Program3 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
</Workspace>"; | ||
|
||
var expected = @" | ||
<Workspace> | ||
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true""> | ||
<Document> | ||
class Program1 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) | ||
{ | ||
return; | ||
} | ||
if (true) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
</Document> | ||
<Document> | ||
class Program2 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true""> | ||
<Document> | ||
class Program3 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
</Workspace>"; | ||
|
||
await TestAsync(input, expected, compareTokens: false, fixAllActionEquivalenceKey: null); | ||
} | ||
|
||
[Fact] | ||
[Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)] | ||
[Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] | ||
public async Task TestFixAllInProject() | ||
{ | ||
var input = @" | ||
<Workspace> | ||
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true""> | ||
<Document> | ||
class Program1 | ||
{ | ||
static void Main() | ||
{ | ||
{|FixAllInProject:if|} (true) return; | ||
} | ||
} | ||
</Document> | ||
<Document> | ||
class Program2 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true""> | ||
<Document> | ||
class Program3 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
</Workspace>"; | ||
|
||
var expected = @" | ||
<Workspace> | ||
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true""> | ||
<Document> | ||
class Program1 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
</Document> | ||
<Document> | ||
class Program2 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true""> | ||
<Document> | ||
class Program3 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
</Workspace>"; | ||
|
||
await TestAsync(input, expected, compareTokens: false, fixAllActionEquivalenceKey: null); | ||
} | ||
|
||
[Fact] | ||
[Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)] | ||
[Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] | ||
public async Task TestFixAllInSolution() | ||
{ | ||
var input = @" | ||
<Workspace> | ||
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true""> | ||
<Document> | ||
class Program1 | ||
{ | ||
static void Main() | ||
{ | ||
{|FixAllInSolution:if|} (true) return; | ||
} | ||
} | ||
</Document> | ||
<Document> | ||
class Program2 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true""> | ||
<Document> | ||
class Program3 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) return; | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
</Workspace>"; | ||
|
||
var expected = @" | ||
<Workspace> | ||
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true""> | ||
<Document> | ||
class Program1 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
</Document> | ||
<Document> | ||
class Program2 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true""> | ||
<Document> | ||
class Program3 | ||
{ | ||
static void Main() | ||
{ | ||
if (true) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
</Document> | ||
</Project> | ||
</Workspace>"; | ||
|
||
await TestAsync(input, expected, compareTokens: false, fixAllActionEquivalenceKey: null); | ||
} | ||
} | ||
} |
Oops, something went wrong.