提交 2bf2eae7 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #15304 from CyrusNajmabadi/testOptions

Simplify API for tests to create options.
...@@ -170,8 +170,8 @@ void baz() ...@@ -170,8 +170,8 @@ void baz()
"; ";
await TestAsync(text, expected, await TestAsync(text, expected,
options: OptionsSet( options: OptionsSet(
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedProperties, true, NotificationOption.None), SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedProperties, true, NotificationOption.None),
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None))); SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None)));
} }
[Fact, Trait(Traits.Feature, Traits.Features.EncapsulateField)] [Fact, Trait(Traits.Feature, Traits.Features.EncapsulateField)]
......
...@@ -24,9 +24,10 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa ...@@ -24,9 +24,10 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
// specify all options explicitly to override defaults. // specify all options explicitly to override defaults.
private IDictionary<OptionKey, object> ImplicitTypingEverywhere() => private IDictionary<OptionKey, object> ImplicitTypingEverywhere() =>
OptionSet(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo) OptionsSet(
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo),
SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo));
internal IDictionary<OptionKey, object> OptionSet(OptionKey option, object value) internal IDictionary<OptionKey, object> OptionSet(OptionKey option, object value)
{ {
......
...@@ -28,10 +28,10 @@ public class GenerateVariableTests : AbstractCSharpDiagnosticProviderBasedUserDi ...@@ -28,10 +28,10 @@ public class GenerateVariableTests : AbstractCSharpDiagnosticProviderBasedUserDi
private readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion); private readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion);
// specify all options explicitly to override defaults. // specify all options explicitly to override defaults.
private IDictionary<OptionKey, object> ImplicitTypingEverywhere() => private IDictionary<OptionKey, object> ImplicitTypingEverywhere() => OptionsSet(
OptionSet(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo));
internal IDictionary<OptionKey, object> OptionSet(OptionKey option, object value) internal IDictionary<OptionKey, object> OptionSet(OptionKey option, object value)
{ {
......
...@@ -1257,8 +1257,8 @@ public override int M ...@@ -1257,8 +1257,8 @@ public override int M
} }
} }
}", options: OptionsSet( }", options: OptionsSet(
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedProperties, true, NotificationOption.None), SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedProperties, true, NotificationOption.None),
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None))); SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None)));
} }
[WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")] [WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")]
...@@ -1296,8 +1296,8 @@ public override int M ...@@ -1296,8 +1296,8 @@ public override int M
} }
} }
}", options: OptionsSet( }", options: OptionsSet(
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedProperties, true, NotificationOption.None), SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedProperties, true, NotificationOption.None),
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None))); SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None)));
} }
[WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")] [WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")]
...@@ -1356,8 +1356,8 @@ class T : A ...@@ -1356,8 +1356,8 @@ class T : A
} }
} }
}", options: OptionsSet( }", options: OptionsSet(
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, true, NotificationOption.None), SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, true, NotificationOption.None),
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None))); SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None)));
} }
[WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")] [WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")]
...@@ -1395,8 +1395,8 @@ class T : A ...@@ -1395,8 +1395,8 @@ class T : A
} }
} }
}", options: OptionsSet( }", options: OptionsSet(
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, true, NotificationOption.None), SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, true, NotificationOption.None),
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None))); SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, false, NotificationOption.None)));
} }
[WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")] [WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")]
...@@ -1426,8 +1426,8 @@ public override int M ...@@ -1426,8 +1426,8 @@ public override int M
get => throw new NotImplementedException(); get => throw new NotImplementedException();
} }
}", options: OptionsSet( }", options: OptionsSet(
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedProperties, false, NotificationOption.None), SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedProperties, false, NotificationOption.None),
Tuple.Create((IOption)CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, true, NotificationOption.None))); SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, true, NotificationOption.None)));
} }
[WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")] [WorkItem(581500, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/581500")]
......
...@@ -24,21 +24,21 @@ public partial class PreferFrameworkTypeTests : AbstractCSharpDiagnosticProvider ...@@ -24,21 +24,21 @@ public partial class PreferFrameworkTypeTests : AbstractCSharpDiagnosticProvider
private readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion); private readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion);
private readonly CodeStyleOption<bool> offWithInfo = new CodeStyleOption<bool>(false, NotificationOption.Suggestion); private readonly CodeStyleOption<bool> offWithInfo = new CodeStyleOption<bool>(false, NotificationOption.Suggestion);
private IDictionary<OptionKey, object> NoFrameworkType => private IDictionary<OptionKey, object> NoFrameworkType => OptionsSet(
Option(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Suggestion) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Suggestion),
.With(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, onWithInfo, GetLanguage()); SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, onWithInfo, GetLanguage()));
private IDictionary<OptionKey, object> FrameworkTypeEverywhere => private IDictionary<OptionKey, object> FrameworkTypeEverywhere => OptionsSet(
Option(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, false, NotificationOption.Suggestion) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, false, NotificationOption.Suggestion),
.With(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, offWithInfo, GetLanguage()); SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, offWithInfo, GetLanguage()));
private IDictionary<OptionKey, object> FrameworkTypeInDeclaration => private IDictionary<OptionKey, object> FrameworkTypeInDeclaration => OptionsSet(
Option(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, false, NotificationOption.Suggestion) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, false, NotificationOption.Suggestion),
.With(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, onWithInfo, GetLanguage()); SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, onWithInfo, GetLanguage()));
private IDictionary<OptionKey, object> FrameworkTypeInMemberAccess => private IDictionary<OptionKey, object> FrameworkTypeInMemberAccess => OptionsSet(
Option(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Suggestion) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Suggestion),
.With(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, offWithInfo, GetLanguage()); SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, offWithInfo, GetLanguage()));
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseFrameworkType)] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseFrameworkType)]
public async Task NotWhenOptionsAreNotSet() public async Task NotWhenOptionsAreNotSet()
......
...@@ -3770,17 +3770,17 @@ private async Task TestWithPredefinedTypeOptionsAsync(string code, string expect ...@@ -3770,17 +3770,17 @@ private async Task TestWithPredefinedTypeOptionsAsync(string code, string expect
await TestAsync(code, expected, index, options: PreferIntrinsicTypeEverywhere); await TestAsync(code, expected, index, options: PreferIntrinsicTypeEverywhere);
} }
private IDictionary<OptionKey, object> PreferIntrinsicTypeEverywhere => private IDictionary<OptionKey, object> PreferIntrinsicTypeEverywhere => OptionsSet(
Option(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Error) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Error),
.With(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, this.onWithError, GetLanguage()); SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, this.onWithError, GetLanguage()));
private IDictionary<OptionKey, object> PreferIntrinsicTypeInDeclaration => private IDictionary<OptionKey, object> PreferIntrinsicTypeInDeclaration => OptionsSet(
Option(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Error) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, true, NotificationOption.Error),
.With(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, this.offWithNone, GetLanguage()); SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, this.offWithNone, GetLanguage()));
private IDictionary<OptionKey, object> PreferIntrinsicTypeInMemberAccess => private IDictionary<OptionKey, object> PreferIntrinsicTypeInMemberAccess => OptionsSet(
Option(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, true, NotificationOption.Error) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, true, NotificationOption.Error),
.With(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, this.offWithNone, GetLanguage()); SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, this.offWithNone, GetLanguage()));
private readonly CodeStyleOption<bool> onWithNone = new CodeStyleOption<bool>(true, NotificationOption.None); private readonly CodeStyleOption<bool> onWithNone = new CodeStyleOption<bool>(true, NotificationOption.None);
private readonly CodeStyleOption<bool> offWithNone = new CodeStyleOption<bool>(false, NotificationOption.None); private readonly CodeStyleOption<bool> offWithNone = new CodeStyleOption<bool>(false, NotificationOption.None);
......
...@@ -932,8 +932,9 @@ void N() ...@@ -932,8 +932,9 @@ void N()
</Workspace>"; </Workspace>";
var options = OptionsSet( var options = OptionsSet(
Tuple.Create((IOption)CodeStyleOptions.QualifyPropertyAccess, false, NotificationOption.Suggestion), SingleOption(CodeStyleOptions.QualifyPropertyAccess, false, NotificationOption.Suggestion),
Tuple.Create((IOption)CodeStyleOptions.QualifyFieldAccess, true, NotificationOption.Suggestion)); SingleOption(CodeStyleOptions.QualifyFieldAccess, true, NotificationOption.Suggestion));
await TestAsync( await TestAsync(
initialMarkup: input, initialMarkup: input,
expectedMarkup: expected, expectedMarkup: expected,
......
...@@ -34,30 +34,30 @@ public partial class UseExplicitTypeTests : AbstractCSharpDiagnosticProviderBase ...@@ -34,30 +34,30 @@ public partial class UseExplicitTypeTests : AbstractCSharpDiagnosticProviderBase
private readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error); private readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error);
// specify all options explicitly to override defaults. // specify all options explicitly to override defaults.
private IDictionary<OptionKey, object> ExplicitTypeEverywhere() => private IDictionary<OptionKey, object> ExplicitTypeEverywhere() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, offWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, offWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo));
private IDictionary<OptionKey, object> ExplicitTypeExceptWhereApparent() => private IDictionary<OptionKey, object> ExplicitTypeExceptWhereApparent() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo));
private IDictionary<OptionKey, object> ExplicitTypeForBuiltInTypesOnly() => private IDictionary<OptionKey, object> ExplicitTypeForBuiltInTypesOnly() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo));
private IDictionary<OptionKey, object> ExplicitTypeEnforcements() => private IDictionary<OptionKey, object> ExplicitTypeEnforcements() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithWarning) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithWarning),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, offWithError) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, offWithError),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo));
private IDictionary<OptionKey, object> ExplicitTypeNoneEnforcement() => private IDictionary<OptionKey, object> ExplicitTypeNoneEnforcement() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithNone) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithNone),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, offWithNone) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, offWithNone),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithNone); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithNone));
private IDictionary<OptionKey, object> Options(OptionKey option, object value) private IDictionary<OptionKey, object> Options(OptionKey option, object value)
{ {
......
...@@ -34,35 +34,35 @@ public partial class UseImplicitTypeTests : AbstractCSharpDiagnosticProviderBase ...@@ -34,35 +34,35 @@ public partial class UseImplicitTypeTests : AbstractCSharpDiagnosticProviderBase
private static readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error); private static readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error);
// specify all options explicitly to override defaults. // specify all options explicitly to override defaults.
public static IDictionary<OptionKey, object> ImplicitTypeEverywhere() => public IDictionary<OptionKey, object> ImplicitTypeEverywhere() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo));
private IDictionary<OptionKey, object> ImplicitTypeWhereApparent() => private IDictionary<OptionKey, object> ImplicitTypeWhereApparent() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo));
private IDictionary<OptionKey, object> ImplicitTypeWhereApparentAndForIntrinsics() => private IDictionary<OptionKey, object> ImplicitTypeWhereApparentAndForIntrinsics() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, offWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo));
public static IDictionary<OptionKey, object> ImplicitTypeButKeepIntrinsics() => public IDictionary<OptionKey, object> ImplicitTypeButKeepIntrinsics() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, offWithInfo),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo));
private IDictionary<OptionKey, object> ImplicitTypeEnforcements() => private IDictionary<OptionKey, object> ImplicitTypeEnforcements() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithWarning) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithWarning),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithError) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithError),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo));
private IDictionary<OptionKey, object> ImplicitTypeNoneEnforcement() => private IDictionary<OptionKey, object> ImplicitTypeNoneEnforcement() => OptionsSet(
Options(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithNone) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithNone),
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithNone) SingleOption(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithNone),
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithNone); SingleOption(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithNone));
private static IDictionary<OptionKey, object> Options(OptionKey option, object value) private static IDictionary<OptionKey, object> Options(OptionKey option, object value)
{ {
......
...@@ -209,7 +209,7 @@ void M(string v) ...@@ -209,7 +209,7 @@ void M(string v)
{ {
} }
} }
}", options: UseImplicitTypeTests.ImplicitTypeEverywhere()); }", options: new UseImplicitTypeTests().ImplicitTypeEverywhere());
} }
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)]
...@@ -234,7 +234,7 @@ void M(string v) ...@@ -234,7 +234,7 @@ void M(string v)
{ {
} }
} }
}", options: UseImplicitTypeTests.ImplicitTypeButKeepIntrinsics()); }", options: new UseImplicitTypeTests().ImplicitTypeButKeepIntrinsics());
} }
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)]
...@@ -568,7 +568,7 @@ void M2(out int i) ...@@ -568,7 +568,7 @@ void M2(out int i)
void M2(out string s) void M2(out string s)
{ {
} }
}", options: UseImplicitTypeTests.ImplicitTypeEverywhere()); }", options: new UseImplicitTypeTests().ImplicitTypeEverywhere());
} }
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)]
...@@ -609,7 +609,7 @@ void M2(out int i) ...@@ -609,7 +609,7 @@ void M2(out int i)
void M2(out string s) void M2(out string s)
{ {
} }
}", options: UseImplicitTypeTests.ImplicitTypeEverywhere()); }", options: new UseImplicitTypeTests().ImplicitTypeEverywhere());
} }
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)]
...@@ -642,7 +642,7 @@ void M() ...@@ -642,7 +642,7 @@ void M()
void M2<T>(out T i) void M2<T>(out T i)
{ {
} }
}", options: UseImplicitTypeTests.ImplicitTypeEverywhere()); }", options: new UseImplicitTypeTests().ImplicitTypeEverywhere());
} }
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineDeclaration)]
......
...@@ -534,25 +534,43 @@ protected static IList<CodeAction> FlattenActions(IEnumerable<CodeAction> codeAc ...@@ -534,25 +534,43 @@ protected static IList<CodeAction> FlattenActions(IEnumerable<CodeAction> codeAc
: new[] { a }).ToList(); : new[] { a }).ToList();
} }
protected IDictionary<OptionKey, object> Option(IOption option, CodeStyleOption<bool> notification) protected (OptionKey, object) SingleOption(Option<CodeStyleOption<bool>> option, bool enabled, NotificationOption notification)
=> Option(option, notification.Value, notification.Notification); => SingleOption(option, new CodeStyleOption<bool>(enabled, notification));
protected IDictionary<OptionKey, object> Option(IOption option, bool value, NotificationOption notification) protected (OptionKey, object) SingleOption(Option<CodeStyleOption<bool>> option, CodeStyleOption<bool> codeStyle)
=> OptionsSet(Tuple.Create(option, value, notification)); => (new OptionKey(option), codeStyle);
protected IDictionary<OptionKey, object> OptionsSet(params Tuple<IOption, bool, NotificationOption>[] optionsToSet) protected (OptionKey, object) SingleOption(PerLanguageOption<CodeStyleOption<bool>> option, bool enabled, NotificationOption notification)
=> SingleOption(option, new CodeStyleOption<bool>(enabled, notification));
protected (OptionKey, object) SingleOption(PerLanguageOption<CodeStyleOption<bool>> option, CodeStyleOption<bool> codeStyle)
=> SingleOption(option, codeStyle, language: GetLanguage());
protected static (OptionKey, object) SingleOption(PerLanguageOption<CodeStyleOption<bool>> option, CodeStyleOption<bool> codeStyle, string language)
=> (new OptionKey(option, language), codeStyle);
protected IDictionary<OptionKey, object> Option(Option<CodeStyleOption<bool>> option, bool enabled, NotificationOption notification)
=> OptionsSet(SingleOption(option, enabled, notification));
protected IDictionary<OptionKey, object> Option(Option<CodeStyleOption<bool>> option, CodeStyleOption<bool> codeStyle)
=> OptionsSet(SingleOption(option, codeStyle));
protected IDictionary<OptionKey, object> Option(PerLanguageOption<CodeStyleOption<bool>> option, bool enabled, NotificationOption notification)
=> OptionsSet(SingleOption(option, enabled, notification));
protected IDictionary<OptionKey, object> Option(PerLanguageOption<CodeStyleOption<bool>> option, CodeStyleOption<bool> codeStyle)
=> OptionsSet(SingleOption(option, codeStyle));
protected static IDictionary<OptionKey, object> OptionsSet(
params (OptionKey key, object value)[] options)
{ {
var options = new Dictionary<OptionKey, object>(); var result = new Dictionary<OptionKey, object>();
foreach (var triple in optionsToSet) foreach (var option in options)
{ {
var option = triple.Item1; result.Add(option.key, option.value);
var value = triple.Item2;
var notification = triple.Item3;
var optionKey = new OptionKey(option, option.IsPerLanguage ? GetLanguage() : null);
options.Add(optionKey, new CodeStyleOption<bool>(value, notification));
} }
return options; return result;
} }
} }
} }
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.Editor.UnitTests
{
internal static class OptionExtensions
{
internal static IDictionary<OptionKey, object> With(this IDictionary<OptionKey, object> options, OptionKey option, object value)
{
options.Add(option, value);
return options;
}
internal static IDictionary<OptionKey, object> With(this IDictionary<OptionKey, object> options, PerLanguageOption<CodeStyleOption<bool>> option, object value, string language)
{
options.Add(new OptionKey(option, language), value);
return options;
}
}
}
...@@ -199,7 +199,6 @@ ...@@ -199,7 +199,6 @@
<Compile Include="NavigateTo\AbstractNavigateToTests.cs" /> <Compile Include="NavigateTo\AbstractNavigateToTests.cs" />
<Compile Include="NavigateTo\NavigateToTestAggregator.Callback.cs" /> <Compile Include="NavigateTo\NavigateToTestAggregator.Callback.cs" />
<Compile Include="NavigateTo\NavigateToTestAggregator.cs" /> <Compile Include="NavigateTo\NavigateToTestAggregator.cs" />
<Compile Include="OptionExtensions.cs" />
<Compile Include="Preview\MockPreviewPaneService.cs" /> <Compile Include="Preview\MockPreviewPaneService.cs" />
<Compile Include="QuickInfo\AbstractQuickInfoSourceTests.cs" /> <Compile Include="QuickInfo\AbstractQuickInfoSourceTests.cs" />
<Compile Include="QuickInfo\AbstractSemanticQuickInfoSourceTests.cs" /> <Compile Include="QuickInfo\AbstractSemanticQuickInfoSourceTests.cs" />
......
...@@ -23,29 +23,33 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.Prefer ...@@ -23,29 +23,33 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.Prefer
Private ReadOnly Property NoFrameworkType As IDictionary(Of OptionKey, Object) Private ReadOnly Property NoFrameworkType As IDictionary(Of OptionKey, Object)
Get Get
Return [Option](CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, True, NotificationOption.Suggestion).With( Return OptionsSet(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.onWithInfo, GetLanguage()) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, True, NotificationOption.Suggestion),
SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.onWithInfo, GetLanguage()))
End Get End Get
End Property End Property
Private ReadOnly Property FrameworkTypeEverywhere As IDictionary(Of OptionKey, Object) Private ReadOnly Property FrameworkTypeEverywhere As IDictionary(Of OptionKey, Object)
Get Get
Return [Option](CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, False, NotificationOption.Suggestion).With( Return OptionsSet(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.offWithInfo, GetLanguage()) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, False, NotificationOption.Suggestion),
SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.offWithInfo, GetLanguage()))
End Get End Get
End Property End Property
Private ReadOnly Property FrameworkTypeInDeclaration As IDictionary(Of OptionKey, Object) Private ReadOnly Property FrameworkTypeInDeclaration As IDictionary(Of OptionKey, Object)
Get Get
Return [Option](CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, False, NotificationOption.Suggestion).With( Return OptionsSet(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.onWithInfo, GetLanguage()) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, False, NotificationOption.Suggestion),
SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.onWithInfo, GetLanguage()))
End Get End Get
End Property End Property
Private ReadOnly Property FrameworkTypeInMemberAccess As IDictionary(Of OptionKey, Object) Private ReadOnly Property FrameworkTypeInMemberAccess As IDictionary(Of OptionKey, Object)
Get Get
Return [Option](CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, False, NotificationOption.Suggestion).With( Return OptionsSet(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, Me.onWithInfo, GetLanguage()) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, False, NotificationOption.Suggestion),
SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, Me.onWithInfo, GetLanguage()))
End Get End Get
End Property End Property
......
...@@ -23,22 +23,25 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.Simpli ...@@ -23,22 +23,25 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.Simpli
Private Function PreferIntrinsicPredefinedTypeEverywhere() As IDictionary(Of OptionKey, Object) Private Function PreferIntrinsicPredefinedTypeEverywhere() As IDictionary(Of OptionKey, Object)
Dim language = GetLanguage() Dim language = GetLanguage()
Return [Option](CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, True, NotificationOption.Error).With( Return OptionsSet(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.onWithError, language) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, True, NotificationOption.Error),
SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.onWithError, language))
End Function End Function
Private Function PreferIntrinsicPredefinedTypeInDeclaration() As IDictionary(Of OptionKey, Object) Private Function PreferIntrinsicPredefinedTypeInDeclaration() As IDictionary(Of OptionKey, Object)
Dim language = GetLanguage() Dim language = GetLanguage()
Return [Option](CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, True, NotificationOption.Error).With( Return OptionsSet(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.offWithNone, language) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, True, NotificationOption.Error),
SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, Me.offWithNone, language))
End Function End Function
Private Function PreferIntrinsicTypeInMemberAccess() As IDictionary(Of OptionKey, Object) Private Function PreferIntrinsicTypeInMemberAccess() As IDictionary(Of OptionKey, Object)
Dim language = GetLanguage() Dim language = GetLanguage()
Return [Option](CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, True, NotificationOption.Error).With( Return OptionsSet(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, Me.offWithNone, language) SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, True, NotificationOption.Error),
SingleOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, Me.offWithNone, language))
End Function End Function
Private ReadOnly onWithError = New CodeStyleOption(Of Boolean)(True, NotificationOption.Error) Private ReadOnly onWithError = New CodeStyleOption(Of Boolean)(True, NotificationOption.Error)
...@@ -2444,7 +2447,7 @@ End Class") ...@@ -2444,7 +2447,7 @@ End Class")
Public Async Function TestAppropriateDiagnosticOnMissingQualifier() As Task Public Async Function TestAppropriateDiagnosticOnMissingQualifier() As Task
Await TestDiagnosticSeverityAndCountAsync( Await TestDiagnosticSeverityAndCountAsync(
"Class C : Property SomeProperty As Integer : Sub M() : [|Me|].SomeProperty = 1 : End Sub : End Class", "Class C : Property SomeProperty As Integer : Sub M() : [|Me|].SomeProperty = 1 : End Sub : End Class",
options:=OptionsSet(Tuple.Create(DirectCast(CodeStyleOptions.QualifyPropertyAccess, IOption), False, NotificationOption.Error)), options:=OptionsSet(SingleOption(CodeStyleOptions.QualifyPropertyAccess, False, NotificationOption.Error)),
diagnosticCount:=1, diagnosticCount:=1,
diagnosticId:=IDEDiagnosticIds.RemoveQualificationDiagnosticId, diagnosticId:=IDEDiagnosticIds.RemoveQualificationDiagnosticId,
diagnosticSeverity:=DiagnosticSeverity.Error) diagnosticSeverity:=DiagnosticSeverity.Error)
......
...@@ -790,8 +790,8 @@ End Class]]> ...@@ -790,8 +790,8 @@ End Class]]>
</Workspace>.ToString() </Workspace>.ToString()
Dim options = OptionsSet( Dim options = OptionsSet(
Tuple.Create(DirectCast(CodeStyleOptions.QualifyPropertyAccess, IOption), False, NotificationOption.Suggestion), SingleOption(CodeStyleOptions.QualifyPropertyAccess, False, NotificationOption.Suggestion),
Tuple.Create(DirectCast(CodeStyleOptions.QualifyFieldAccess, IOption), True, NotificationOption.Suggestion)) SingleOption(CodeStyleOptions.QualifyFieldAccess, True, NotificationOption.Suggestion))
Await TestAsync( Await TestAsync(
initialMarkup:=input, initialMarkup:=input,
expectedMarkup:=expected, expectedMarkup:=expected,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册