Skip to content

Commit e4c7e8e

Browse files
committed
Cleanup the conditional directives in analyzer/fixer tests in shared layer. Should be much cleaner now.
1 parent cbead33 commit e4c7e8e

File tree

3 files changed

+48
-76
lines changed

3 files changed

+48
-76
lines changed

src/Analyzers/CSharp/Tests/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionTests.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
using System.Linq;
66
using System.Threading.Tasks;
7+
using Microsoft.CodeAnalysis.CodeStyle;
8+
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
79
using Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression;
810
using Microsoft.CodeAnalysis.Diagnostics;
911
using Microsoft.CodeAnalysis.Test.Utilities;
@@ -14,14 +16,6 @@
1416
Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionDiagnosticAnalyzer,
1517
Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider>;
1618

17-
#if CODE_STYLE
18-
using Microsoft.CodeAnalysis.CSharp.Internal.CodeStyle;
19-
using Microsoft.CodeAnalysis.Internal.Options;
20-
#else
21-
using Microsoft.CodeAnalysis.CodeStyle;
22-
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
23-
#endif
24-
2519
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertSwitchStatementToExpression
2620
{
2721
public class ConvertSwitchStatementToExpressionTests
@@ -729,7 +723,7 @@ int M(int i)
729723
},
730724
Options =
731725
{
732-
{ CSharpCodeStyleOptions.PreferSwitchExpression, true, NotificationOption.Warning },
726+
{ CSharpCodeStyleOptions.PreferSwitchExpression, true, NotificationOption2.Warning },
733727
},
734728
}.RunAsync();
735729
}
@@ -1070,7 +1064,7 @@ public static void Test(string name)
10701064
FixedCode = expected,
10711065
Options =
10721066
{
1073-
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption.Silent },
1067+
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption2.Silent },
10741068
},
10751069
}.RunAsync();
10761070
}
@@ -1138,7 +1132,7 @@ public static void Test(string name)
11381132
FixedCode = expected,
11391133
Options =
11401134
{
1141-
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption.Silent },
1135+
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption2.Silent },
11421136
},
11431137
}.RunAsync();
11441138
}
@@ -1206,7 +1200,7 @@ public static void Test(string name)
12061200
FixedCode = expected,
12071201
Options =
12081202
{
1209-
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption.Silent },
1203+
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption2.Silent },
12101204
},
12111205
}.RunAsync();
12121206
}
@@ -1282,7 +1276,7 @@ public static void Test(string name)
12821276
FixedCode = expected,
12831277
Options =
12841278
{
1285-
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption.Silent },
1279+
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption2.Silent },
12861280
},
12871281
}.RunAsync();
12881282
}
@@ -1350,7 +1344,7 @@ public static void Test(string name)
13501344
FixedCode = expected,
13511345
Options =
13521346
{
1353-
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption.Silent },
1347+
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption2.Silent },
13541348
},
13551349
}.RunAsync();
13561350
}
@@ -1418,7 +1412,7 @@ public static void Test(string name)
14181412
FixedCode = expected,
14191413
Options =
14201414
{
1421-
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption.Silent },
1415+
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption2.Silent },
14221416
},
14231417
}.RunAsync();
14241418
}
@@ -1486,7 +1480,7 @@ public static void Test(string name)
14861480
FixedCode = expected,
14871481
Options =
14881482
{
1489-
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption.Silent },
1483+
{ CSharpCodeStyleOptions.VarElsewhere, true, NotificationOption2.Silent },
14901484
},
14911485
}.RunAsync();
14921486
}
@@ -1533,7 +1527,7 @@ public static void Test()
15331527
FixedCode = expected,
15341528
Options =
15351529
{
1536-
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption.Silent },
1530+
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption2.Silent },
15371531
},
15381532
}.RunAsync();
15391533
}
@@ -1578,7 +1572,7 @@ public static void Test()
15781572
FixedCode = expected,
15791573
Options =
15801574
{
1581-
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption.Silent },
1575+
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption2.Silent },
15821576
},
15831577
}.RunAsync();
15841578
}
@@ -1624,7 +1618,7 @@ public static void Test()
16241618
FixedCode = expected,
16251619
Options =
16261620
{
1627-
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption.Silent },
1621+
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption2.Silent },
16281622
},
16291623
}.RunAsync();
16301624
}
@@ -1670,7 +1664,7 @@ public static void Test()
16701664
FixedCode = expected,
16711665
Options =
16721666
{
1673-
{ CSharpCodeStyleOptions.VarForBuiltInTypes, false, NotificationOption.Silent },
1667+
{ CSharpCodeStyleOptions.VarForBuiltInTypes, false, NotificationOption2.Silent },
16741668
},
16751669
}.RunAsync();
16761670
}
@@ -1716,7 +1710,7 @@ public static void Test()
17161710
FixedCode = expected,
17171711
Options =
17181712
{
1719-
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption.Silent },
1713+
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true, NotificationOption2.Silent },
17201714
},
17211715
}.RunAsync();
17221716
}

src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseExplicitTypeTests.cs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,60 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Collections.Generic;
65
using System.Threading.Tasks;
76
using Microsoft.CodeAnalysis.CodeFixes;
7+
using Microsoft.CodeAnalysis.CodeStyle;
8+
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
89
using Microsoft.CodeAnalysis.CSharp.Diagnostics.TypeStyle;
910
using Microsoft.CodeAnalysis.CSharp.TypeStyle;
1011
using Microsoft.CodeAnalysis.Diagnostics;
12+
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
1113
using Microsoft.CodeAnalysis.Test.Utilities;
1214
using Roslyn.Test.Utilities;
1315
using Xunit;
1416

15-
#if CODE_STYLE
16-
using Microsoft.CodeAnalysis.Internal.Options;
17-
using Microsoft.CodeAnalysis.CSharp.Internal.CodeStyle;
18-
#else
19-
using Microsoft.CodeAnalysis.CodeStyle;
20-
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
21-
using Microsoft.CodeAnalysis.Options;
22-
#endif
23-
2417
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.UseExplicitType
2518
{
2619
public partial class UseExplicitTypeTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
2720
{
2821
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
2922
=> (new CSharpUseExplicitTypeDiagnosticAnalyzer(), new UseExplicitTypeCodeFixProvider());
3023

31-
private readonly CodeStyleOption<bool> onWithSilent = new CodeStyleOption<bool>(true, NotificationOption.Silent);
32-
private readonly CodeStyleOption<bool> offWithSilent = new CodeStyleOption<bool>(false, NotificationOption.Silent);
33-
private readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion);
34-
private readonly CodeStyleOption<bool> offWithInfo = new CodeStyleOption<bool>(false, NotificationOption.Suggestion);
35-
private readonly CodeStyleOption<bool> onWithWarning = new CodeStyleOption<bool>(true, NotificationOption.Warning);
36-
private readonly CodeStyleOption<bool> offWithWarning = new CodeStyleOption<bool>(false, NotificationOption.Warning);
37-
private readonly CodeStyleOption<bool> onWithError = new CodeStyleOption<bool>(true, NotificationOption.Error);
38-
private readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error);
24+
private readonly CodeStyleOption2<bool> onWithSilent = new CodeStyleOption2<bool>(true, NotificationOption2.Silent);
25+
private readonly CodeStyleOption2<bool> offWithSilent = new CodeStyleOption2<bool>(false, NotificationOption2.Silent);
26+
private readonly CodeStyleOption2<bool> onWithInfo = new CodeStyleOption2<bool>(true, NotificationOption2.Suggestion);
27+
private readonly CodeStyleOption2<bool> offWithInfo = new CodeStyleOption2<bool>(false, NotificationOption2.Suggestion);
28+
private readonly CodeStyleOption2<bool> onWithWarning = new CodeStyleOption2<bool>(true, NotificationOption2.Warning);
29+
private readonly CodeStyleOption2<bool> offWithWarning = new CodeStyleOption2<bool>(false, NotificationOption2.Warning);
30+
private readonly CodeStyleOption2<bool> onWithError = new CodeStyleOption2<bool>(true, NotificationOption2.Error);
31+
private readonly CodeStyleOption2<bool> offWithError = new CodeStyleOption2<bool>(false, NotificationOption2.Error);
3932

4033
// specify all options explicitly to override defaults.
41-
private IDictionary<OptionKey, object> ExplicitTypeEverywhere() => OptionsSet(
34+
private IOptionsCollection ExplicitTypeEverywhere() => OptionsSet(
4235
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithInfo),
4336
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithInfo),
4437
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo));
4538

46-
private IDictionary<OptionKey, object> ExplicitTypeExceptWhereApparent() => OptionsSet(
39+
private IOptionsCollection ExplicitTypeExceptWhereApparent() => OptionsSet(
4740
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithInfo),
4841
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo),
4942
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo));
5043

51-
private IDictionary<OptionKey, object> ExplicitTypeForBuiltInTypesOnly() => OptionsSet(
44+
private IOptionsCollection ExplicitTypeForBuiltInTypesOnly() => OptionsSet(
5245
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithInfo),
5346
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo),
5447
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo));
5548

56-
private IDictionary<OptionKey, object> ExplicitTypeEnforcements() => OptionsSet(
49+
private IOptionsCollection ExplicitTypeEnforcements() => OptionsSet(
5750
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithWarning),
5851
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithError),
5952
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo));
6053

61-
private IDictionary<OptionKey, object> ExplicitTypeSilentEnforcement() => OptionsSet(
54+
private IOptionsCollection ExplicitTypeSilentEnforcement() => OptionsSet(
6255
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithSilent),
6356
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithSilent),
6457
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithSilent));
6558

66-
private IDictionary<OptionKey, object> Options(OptionKey option, object value)
67-
{
68-
var options = new Dictionary<OptionKey, object>();
69-
options.Add(option, value);
70-
return options;
71-
}
72-
7359
#region Error Cases
7460

7561
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUseExplicitType)]

src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseImplicitTypeTests.cs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
77
using Microsoft.CodeAnalysis.CodeFixes;
88
using Microsoft.CodeAnalysis.CSharp;
99
using Microsoft.CodeAnalysis.CSharp.Diagnostics.TypeStyle;
10+
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
1011
using Microsoft.CodeAnalysis.CSharp.TypeStyle;
1112
using Microsoft.CodeAnalysis.Diagnostics;
13+
using Microsoft.CodeAnalysis.Options;
1214
using Microsoft.CodeAnalysis.Test.Utilities;
1315
using Roslyn.Test.Utilities;
1416
using Xunit;
15-
16-
#if CODE_STYLE
17-
using Microsoft.CodeAnalysis.CSharp.Internal.CodeStyle;
18-
using Microsoft.CodeAnalysis.Internal.Options;
19-
#else
20-
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
2117
using Microsoft.CodeAnalysis.CodeStyle;
22-
using Microsoft.CodeAnalysis.Options;
23-
#endif
18+
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
2419

2520
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.UseImplicitType
2621
{
@@ -29,49 +24,46 @@ public partial class UseImplicitTypeTests : AbstractCSharpDiagnosticProviderBase
2924
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
3025
=> (new CSharpUseImplicitTypeDiagnosticAnalyzer(), new UseImplicitTypeCodeFixProvider());
3126

32-
private static readonly CodeStyleOption<bool> onWithSilent = new CodeStyleOption<bool>(true, NotificationOption.Silent);
33-
private static readonly CodeStyleOption<bool> offWithSilent = new CodeStyleOption<bool>(false, NotificationOption.Silent);
34-
private static readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion);
35-
private static readonly CodeStyleOption<bool> offWithInfo = new CodeStyleOption<bool>(false, NotificationOption.Suggestion);
36-
private static readonly CodeStyleOption<bool> onWithWarning = new CodeStyleOption<bool>(true, NotificationOption.Warning);
37-
private static readonly CodeStyleOption<bool> offWithWarning = new CodeStyleOption<bool>(false, NotificationOption.Warning);
38-
private static readonly CodeStyleOption<bool> onWithError = new CodeStyleOption<bool>(true, NotificationOption.Error);
39-
private static readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error);
27+
private static readonly CodeStyleOption2<bool> onWithSilent = new CodeStyleOption2<bool>(true, NotificationOption2.Silent);
28+
private static readonly CodeStyleOption2<bool> offWithSilent = new CodeStyleOption2<bool>(false, NotificationOption2.Silent);
29+
private static readonly CodeStyleOption2<bool> onWithInfo = new CodeStyleOption2<bool>(true, NotificationOption2.Suggestion);
30+
private static readonly CodeStyleOption2<bool> offWithInfo = new CodeStyleOption2<bool>(false, NotificationOption2.Suggestion);
31+
private static readonly CodeStyleOption2<bool> onWithWarning = new CodeStyleOption2<bool>(true, NotificationOption2.Warning);
32+
private static readonly CodeStyleOption2<bool> offWithWarning = new CodeStyleOption2<bool>(false, NotificationOption2.Warning);
33+
private static readonly CodeStyleOption2<bool> onWithError = new CodeStyleOption2<bool>(true, NotificationOption2.Error);
34+
private static readonly CodeStyleOption2<bool> offWithError = new CodeStyleOption2<bool>(false, NotificationOption2.Error);
4035

4136
// specify all options explicitly to override defaults.
42-
public IDictionary<OptionKey, object> ImplicitTypeEverywhere() => OptionsSet(
37+
internal IOptionsCollection ImplicitTypeEverywhere() => OptionsSet(
4338
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithInfo),
4439
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo),
4540
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithInfo));
4641

47-
private IDictionary<OptionKey, object> ImplicitTypeWhereApparent() => OptionsSet(
42+
private IOptionsCollection ImplicitTypeWhereApparent() => OptionsSet(
4843
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithInfo),
4944
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo),
5045
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo));
5146

52-
private IDictionary<OptionKey, object> ImplicitTypeWhereApparentAndForIntrinsics() => OptionsSet(
47+
private IOptionsCollection ImplicitTypeWhereApparentAndForIntrinsics() => OptionsSet(
5348
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithInfo),
5449
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo),
5550
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithInfo));
5651

57-
public IDictionary<OptionKey, object> ImplicitTypeButKeepIntrinsics() => OptionsSet(
52+
internal IOptionsCollection ImplicitTypeButKeepIntrinsics() => OptionsSet(
5853
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithInfo),
5954
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo),
6055
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo));
6156

62-
private IDictionary<OptionKey, object> ImplicitTypeEnforcements() => OptionsSet(
57+
private IOptionsCollection ImplicitTypeEnforcements() => OptionsSet(
6358
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithWarning),
6459
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithError),
6560
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithInfo));
6661

67-
private IDictionary<OptionKey, object> ImplicitTypeSilentEnforcement() => OptionsSet(
62+
private IOptionsCollection ImplicitTypeSilentEnforcement() => OptionsSet(
6863
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithSilent),
6964
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithSilent),
7065
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithSilent));
7166

72-
private static IDictionary<OptionKey, object> Options(OptionKey option, object value)
73-
=> new Dictionary<OptionKey, object> { { option, value } };
74-
7567
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUseImplicitType)]
7668
public async Task NotOnFieldDeclaration()
7769
{

0 commit comments

Comments
 (0)