Skip to content

Commit

Permalink
Merge pull request #11168 from Hosch250/UseBraces2
Browse files Browse the repository at this point in the history
Adds an analyzer/codefix for adding missing braces

Fixes #10942
  • Loading branch information
CyrusNajmabadi committed May 10, 2016
2 parents 5f95f2d + 2c0da2c commit a3772f5
Show file tree
Hide file tree
Showing 13 changed files with 1,157 additions and 1 deletion.
267 changes: 267 additions & 0 deletions src/EditorFeatures/CSharpTest/AddBraces/AddBracesFixAllTests.cs
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);
}
}
}
Loading

0 comments on commit a3772f5

Please sign in to comment.