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

Merge pull request #15304 from CyrusNajmabadi/testOptions

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