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 #893 from JoeRobich/add-codestyle-test
Add unit test for code style fixer formatting
- Loading branch information
Showing
7 changed files
with
119 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Tools.Analyzers; | ||
using Microsoft.CodeAnalysis.Tools.Formatters; | ||
using Microsoft.CodeAnalysis.Tools.Tests.Formatters; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.Tools.Tests.Analyzers | ||
{ | ||
public class CodeStyleAnalyzerFormatterTests : CSharpFormatterTests | ||
{ | ||
private protected override ICodeFormatter Formatter => AnalyzerFormatter.CodeStyleFormatter; | ||
|
||
[Fact] | ||
public async Task TestUseVarCodeStyle_AppliesWhenNotUsingVar() | ||
{ | ||
var testCode = @" | ||
using System.Collections.Generic; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
object obj = new object(); | ||
List<string> list = new List<string>(); | ||
int count = 5; | ||
} | ||
}"; | ||
|
||
var expectedCode = @" | ||
using System.Collections.Generic; | ||
class C | ||
{ | ||
void M() | ||
{ | ||
var obj = new object(); | ||
var list = new List<string>(); | ||
var count = 5; | ||
} | ||
}"; | ||
|
||
var editorConfig = new Dictionary<string, string>() | ||
{ | ||
/// Prefer "var" everywhere | ||
["dotnet_diagnostic.IDE0007.severity"] = "error", | ||
["csharp_style_var_for_built_in_types"] = "true:error", | ||
["csharp_style_var_when_type_is_apparent"] = "true:error", | ||
["csharp_style_var_elsewhere"] = "true:error", | ||
}; | ||
|
||
await AssertCodeChangedAsync(testCode, expectedCode, editorConfig, fixCategory: FixCategory.CodeStyle); | ||
} | ||
} | ||
} |
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