forked from dotnet/format
/
CodeStyleAnalyzerFormatterTests.cs
63 lines (54 loc) · 1.78 KB
/
CodeStyleAnalyzerFormatterTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 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;
using Xunit.Abstractions;
namespace Microsoft.CodeAnalysis.Tools.Tests.Analyzers
{
public class CodeStyleAnalyzerFormatterTests : CSharpFormatterTests
{
private protected override ICodeFormatter Formatter => AnalyzerFormatter.CodeStyleFormatter;
public CodeStyleAnalyzerFormatterTests(ITestOutputHelper output)
{
TestOutputHelper = output;
}
[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);
}
}
}