Skip to content

Commit

Permalink
Fix some build and test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mavasani committed Mar 10, 2020
1 parent f1b4348 commit cbead33
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CSharpEditorConfigCodeStyleParserTests
[InlineData(" before_and_after ", BinaryOperatorSpacingOptions.Single)]
public void TestParseSpacingAroundBinaryOperator(string rawValue, BinaryOperatorSpacingOptions parsedValue)
{
Assert.Equal(parsedValue, CSharpFormattingOptions.ParseEditorConfigSpacingAroundBinaryOperator(rawValue));
Assert.Equal(parsedValue, CSharpFormattingOptions2.ParseEditorConfigSpacingAroundBinaryOperator(rawValue));
}

[Theory]
Expand All @@ -37,7 +37,7 @@ public void TestParseSpacingAroundBinaryOperator(string rawValue, BinaryOperator
[InlineData(" one_less_than_current ", LabelPositionOptions.OneLess)]
public void TestParseLabelPositioning(string rawValue, LabelPositionOptions parsedValue)
{
Assert.Equal(parsedValue, CSharpFormattingOptions.ParseEditorConfigLabelPositioning(rawValue));
Assert.Equal(parsedValue, CSharpFormattingOptions2.ParseEditorConfigLabelPositioning(rawValue));
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using Microsoft.CodeAnalysis.CSharp.Formatting;
using Xunit;
using static Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions;
using static Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions2;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Formatting
{
Expand All @@ -19,7 +19,7 @@ public class EditorConfigOptionParserTests
InlineData("expressions , , , control_flow_statements", SpacingWithinParenthesesOption.ControlFlowStatements),
InlineData("expressions , , , control_flow_statements", SpacingWithinParenthesesOption.Expressions),
InlineData(", , , control_flow_statements", SpacingWithinParenthesesOption.ControlFlowStatements)]
static void TestParseParenthesesSpaceOptionsTrue(string value, CSharpFormattingOptions.SpacingWithinParenthesesOption parenthesesSpacingOption)
static void TestParseParenthesesSpaceOptionsTrue(string value, SpacingWithinParenthesesOption parenthesesSpacingOption)
{
Assert.True(DetermineIfSpaceOptionIsSet(value, parenthesesSpacingOption),
$"Expected option {value} to be parsed as set.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public void TestParseEditorConfigCodeStyleOption(string args, bool isEnabled, Re
break;
}

var codeStyleOption = new CodeStyleOption<bool>(value: isEnabled, notification: notificationOption);

CodeStyleHelpers.TryParseBoolEditorConfigCodeStyleOption(args, out var result);
Assert.True(result.Value == isEnabled,
$"Expected {nameof(isEnabled)} to be {isEnabled}, was {result.Value}");
Expand All @@ -80,13 +78,13 @@ public void TestParseEditorConfigCodeStyleOption(string args, bool isEnabled, Re
[InlineData("omit_if_default : error", (int)AccessibilityModifiersRequired.OmitIfDefault, ReportDiagnostic.Error)]
public void TestParseEditorConfigAccessibilityModifiers(string args, int value, ReportDiagnostic severity)
{
var storageLocation = CodeStyleOptions.RequireAccessibilityModifiers.StorageLocations
.OfType<EditorConfigStorageLocation<CodeStyleOption<AccessibilityModifiersRequired>>>()
var storageLocation = CodeStyleOptions2.RequireAccessibilityModifiers.StorageLocations
.OfType<EditorConfigStorageLocation<CodeStyleOption2<AccessibilityModifiersRequired>>>()
.Single();
var allRawConventions = new Dictionary<string, string?> { { storageLocation.KeyName, args } };

Assert.True(storageLocation.TryGetOption(allRawConventions, typeof(CodeStyleOption<AccessibilityModifiersRequired>), out var parsedCodeStyleOption));
var codeStyleOption = (CodeStyleOption<AccessibilityModifiersRequired>)parsedCodeStyleOption!;
Assert.True(storageLocation.TryGetOption(allRawConventions, typeof(CodeStyleOption2<AccessibilityModifiersRequired>), out var parsedCodeStyleOption));
var codeStyleOption = (CodeStyleOption2<AccessibilityModifiersRequired>)parsedCodeStyleOption!;
Assert.Equal((AccessibilityModifiersRequired)value, codeStyleOption.Value);
Assert.Equal(severity, codeStyleOption.Notification.Severity);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Workspaces/CoreTest/Execution/SnapshotSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,31 +319,31 @@ public async Task OptionSet_Serialization_CustomValue()
{
var workspace = new AdhocWorkspace();

var newQualifyFieldAccessValue = new CodeStyleOption<bool>(false, NotificationOption.Error);
var newQualifyMethodAccessValue = new CodeStyleOption<bool>(true, NotificationOption.Warning);
var newVarWhenTypeIsApparentValue = new CodeStyleOption<bool>(false, NotificationOption.Suggestion);
var newPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue = new CodeStyleOption<bool>(true, NotificationOption.Silent);
var newQualifyFieldAccessValue = new CodeStyleOption2<bool>(false, NotificationOption2.Error);
var newQualifyMethodAccessValue = new CodeStyleOption2<bool>(true, NotificationOption2.Warning);
var newVarWhenTypeIsApparentValue = new CodeStyleOption2<bool>(false, NotificationOption2.Suggestion);
var newPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue = new CodeStyleOption2<bool>(true, NotificationOption2.Silent);

workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options
.WithChangedOption(CodeStyleOptions.QualifyFieldAccess, LanguageNames.CSharp, newQualifyFieldAccessValue)
.WithChangedOption(CodeStyleOptions.QualifyMethodAccess, LanguageNames.VisualBasic, newQualifyMethodAccessValue)
.WithChangedOption(CodeStyleOptions2.QualifyFieldAccess, LanguageNames.CSharp, newQualifyFieldAccessValue)
.WithChangedOption(CodeStyleOptions2.QualifyMethodAccess, LanguageNames.VisualBasic, newQualifyMethodAccessValue)
.WithChangedOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, newVarWhenTypeIsApparentValue)
.WithChangedOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, LanguageNames.VisualBasic, newPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue)));
.WithChangedOption(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, LanguageNames.VisualBasic, newPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue)));

await VerifyOptionSetsAsync(workspace, VerifyOptions).ConfigureAwait(false);

void VerifyOptions(OptionSet options)
{
var actualQualifyFieldAccessValue = options.GetOption(CodeStyleOptions.QualifyFieldAccess, LanguageNames.CSharp);
var actualQualifyFieldAccessValue = options.GetOption(CodeStyleOptions2.QualifyFieldAccess, LanguageNames.CSharp);
Assert.Equal(newQualifyFieldAccessValue, actualQualifyFieldAccessValue);

var actualQualifyMethodAccessValue = options.GetOption(CodeStyleOptions.QualifyMethodAccess, LanguageNames.VisualBasic);
var actualQualifyMethodAccessValue = options.GetOption(CodeStyleOptions2.QualifyMethodAccess, LanguageNames.VisualBasic);
Assert.Equal(newQualifyMethodAccessValue, actualQualifyMethodAccessValue);

var actualVarWhenTypeIsApparentValue = options.GetOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent);
Assert.Equal(newVarWhenTypeIsApparentValue, actualVarWhenTypeIsApparentValue);

var actualPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue = options.GetOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, LanguageNames.VisualBasic);
var actualPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue = options.GetOption(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, LanguageNames.VisualBasic);
Assert.Equal(newPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue, actualPreferIntrinsicPredefinedTypeKeywordInMemberAccessValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

#if CODE_STYLE
using WorkspacesResources = Microsoft.CodeAnalysis.CodeStyleResources;
#else
Expand Down Expand Up @@ -44,8 +46,13 @@ private NotificationOption2(string name, ReportDiagnostic severity)
public override string ToString() => Name;

#if !CODE_STYLE
public static implicit operator NotificationOption2(NotificationOption notificationOption)
public static implicit operator NotificationOption2?(NotificationOption? notificationOption)
{
if (notificationOption is null)
{
return null;
}

return notificationOption.Severity switch
{
ReportDiagnostic.Suppress => None,
Expand All @@ -57,8 +64,13 @@ public static implicit operator NotificationOption2(NotificationOption notificat
};
}

public static implicit operator NotificationOption(NotificationOption2 notificationOption)
public static implicit operator NotificationOption?(NotificationOption2? notificationOption)
{
if (notificationOption is null)
{
return null;
}

return notificationOption.Severity switch
{
ReportDiagnostic.Suppress => NotificationOption.None,
Expand All @@ -70,7 +82,7 @@ public static implicit operator NotificationOption(NotificationOption2 notificat
};
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj is NotificationOption)
{
Expand All @@ -89,19 +101,19 @@ public override int GetHashCode()
return Hash.Combine(Name.GetHashCode(), Severity.GetHashCode());
}

public bool Equals(NotificationOption2 notificationOption2)
public bool Equals(NotificationOption2? notificationOption2)
{
return ReferenceEquals(this, notificationOption2);
}

public static bool operator ==(NotificationOption notificationOption, NotificationOption2 notificationOption2)
public static bool operator ==(NotificationOption? notificationOption, NotificationOption2? notificationOption2)
{
return notificationOption2.Equals((NotificationOption2)notificationOption);
return Equals((NotificationOption2?)notificationOption, notificationOption2);
}

public static bool operator !=(NotificationOption notificationOption, NotificationOption2 notificationOption2)
{
return !notificationOption2.Equals((NotificationOption2)notificationOption);
return !Equals((NotificationOption2?)notificationOption, notificationOption2);
}
#endif
}
Expand Down

0 comments on commit cbead33

Please sign in to comment.