Skip to content

Commit 84d0d4b

Browse files
Merge remote-tracking branch 'upstream/main' into initializeFieldOrProp
2 parents 2d85833 + 3e2cadf commit 84d0d4b

File tree

36 files changed

+3059
-2988
lines changed

36 files changed

+3059
-2988
lines changed

src/Analyzers/CSharp/Tests/AddObsoleteAttribute/AddObsoleteAttributeTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis.CSharp.AddObsoleteAttribute;
7+
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
68
using Microsoft.CodeAnalysis.Test.Utilities;
9+
using Microsoft.CodeAnalysis.Testing;
710
using Xunit;
8-
using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier<
9-
Microsoft.CodeAnalysis.Testing.EmptyDiagnosticAnalyzer,
10-
Microsoft.CodeAnalysis.CSharp.AddObsoleteAttribute.CSharpAddObsoleteAttributeCodeFixProvider>;
1111

1212
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.AddObsoleteAttribute;
1313

14+
using VerifyCS = CSharpCodeFixVerifier<
15+
EmptyDiagnosticAnalyzer,
16+
CSharpAddObsoleteAttributeCodeFixProvider>;
17+
1418
[Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)]
1519
public sealed class AddObsoleteAttributeTests
1620
{

src/Analyzers/CSharp/Tests/FileHeaders/FileHeaderTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis.CSharp.FileHeaders;
7+
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
68
using Microsoft.CodeAnalysis.Formatting;
79
using Microsoft.CodeAnalysis.Testing;
810
using Roslyn.Test.Utilities;
911
using Xunit;
10-
using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier<
11-
Microsoft.CodeAnalysis.CSharp.FileHeaders.CSharpFileHeaderDiagnosticAnalyzer,
12-
Microsoft.CodeAnalysis.CSharp.FileHeaders.CSharpFileHeaderCodeFixProvider>;
1312

1413
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.FileHeaders;
1514

15+
using VerifyCS = CSharpCodeFixVerifier<
16+
CSharpFileHeaderDiagnosticAnalyzer,
17+
CSharpFileHeaderCodeFixProvider>;
18+
1619
public sealed class FileHeaderTests
1720
{
1821
private const string TestSettings = """

src/Analyzers/CSharp/Tests/RemoveUnnecessarySuppressions/RemoveUnnecessaryAttributeSuppressionsTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions;
67
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
78
using Microsoft.CodeAnalysis.RemoveUnnecessarySuppressions;
89
using Microsoft.CodeAnalysis.Test.Utilities;
910
using Roslyn.Test.Utilities;
1011
using Xunit;
11-
using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier<
12-
Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions.CSharpRemoveUnnecessaryAttributeSuppressionsDiagnosticAnalyzer,
13-
Microsoft.CodeAnalysis.RemoveUnnecessarySuppressions.RemoveUnnecessaryAttributeSuppressionsCodeFixProvider>;
1412

1513
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.RemoveUnnecessarySuppressions;
1614

15+
using VerifyCS = CSharpCodeFixVerifier<
16+
CSharpRemoveUnnecessaryAttributeSuppressionsDiagnosticAnalyzer,
17+
RemoveUnnecessaryAttributeSuppressionsCodeFixProvider>;
18+
1719
[Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessarySuppressions)]
1820
[WorkItem("https://github.com/dotnet/roslyn/issues/44176")]
1921
public sealed class RemoveUnnecessaryAttributeSuppressionsTests

src/Analyzers/CSharp/Tests/UpdateLegacySuppressions/UpdateLegacySuppressionsTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions;
67
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
78
using Microsoft.CodeAnalysis.RemoveUnnecessarySuppressions;
89
using Microsoft.CodeAnalysis.Test.Utilities;
10+
using Microsoft.CodeAnalysis.UpdateLegacySuppressions;
911
using Roslyn.Test.Utilities;
1012
using Xunit;
11-
using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier<
12-
Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions.CSharpRemoveUnnecessaryAttributeSuppressionsDiagnosticAnalyzer,
13-
Microsoft.CodeAnalysis.UpdateLegacySuppressions.UpdateLegacySuppressionsCodeFixProvider>;
1413

1514
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UpdateLegacySuppressions;
1615

16+
using VerifyCS = CSharpCodeFixVerifier<
17+
CSharpRemoveUnnecessaryAttributeSuppressionsDiagnosticAnalyzer,
18+
UpdateLegacySuppressionsCodeFixProvider>;
19+
1720
[Trait(Traits.Feature, Traits.Features.CodeActionsUpdateLegacySuppressions)]
1821
[WorkItem("https://github.com/dotnet/roslyn/issues/44362")]
1922
public sealed class UpdateLegacySuppressionsTests

src/Analyzers/VisualBasic/Tests/RemoveUnnecessaryParentheses/RemoveUnnecessaryParenthesesTests.vb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.RemoveUnnecessaryP
1515
''' whose current option is set to something other than 'Ignore'.
1616
''' </summary>
1717
<Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)>
18-
Partial Public Class RemoveUnnecessaryParenthesesTests
18+
Partial Public NotInheritable Class RemoveUnnecessaryParenthesesTests
1919
Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest_NoEditor
2020

2121
Private Shared ReadOnly CheckOverflow As CompilationOptions = New VisualBasicCompilationOptions(OutputKind.ConsoleApplication, checkOverflow:=True)
@@ -651,7 +651,16 @@ end class"
651651

652652
Assert.Equal("[1,2]", diagnostic.Properties.Item(WellKnownDiagnosticTags.Unnecessary))
653653
End Using
654+
End Function
654655

656+
<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78187")>
657+
Public Async Function TestWithNullMemberAccess() As Task
658+
Await TestMissingAsync(
659+
"class C
660+
sub M()
661+
RoundTime($$(d.EndDate - d.StartDate)?.TotalMinutes / 60)
662+
end sub
663+
end class", New TestParameters(options:=RequireArithmeticBinaryParenthesesForClarity))
655664
End Function
656665
End Class
657666
End Namespace

src/EditorFeatures/CSharpTest/AddMissingImports/CSharpAddMissingImportsRefactoringProviderTests.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
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-
#nullable disable
6-
75
using System.Diagnostics.CodeAnalysis;
86
using System.Linq;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.AddImport;
109
using Microsoft.CodeAnalysis.CodeRefactorings;
10+
using Microsoft.CodeAnalysis.CodeStyle;
1111
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.AddMissingImports;
12+
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
1213
using Microsoft.CodeAnalysis.Editing;
1314
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
1415
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
@@ -26,6 +27,12 @@ public sealed class CSharpAddMissingImportsRefactoringProviderTests : AbstractCS
2627
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(EditorTestWorkspace workspace, TestParameters parameters)
2728
=> new CSharpAddMissingImportsRefactoringProvider();
2829

30+
private static readonly CodeStyleOption2<AddImportPlacement> InsideNamespaceOption =
31+
new(AddImportPlacement.InsideNamespace, NotificationOption2.Error);
32+
33+
private static readonly CodeStyleOption2<AddImportPlacement> OutsideNamespaceOption =
34+
new(AddImportPlacement.InsideNamespace, NotificationOption2.Error);
35+
2936
protected override void InitializeWorkspace(EditorTestWorkspace workspace, TestParameters parameters)
3037
{
3138
// Treat the span being tested as the pasted span
@@ -46,13 +53,16 @@ protected override void InitializeWorkspace(EditorTestWorkspace workspace, TestP
4653
private Task TestInRegularAndScriptAsync(
4754
[StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string initialMarkup,
4855
[StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string expectedMarkup,
49-
bool placeSystemNamespaceFirst, bool separateImportDirectiveGroups)
56+
bool placeSystemNamespaceFirst,
57+
bool separateImportDirectiveGroups,
58+
bool placeInsideNamespace = false)
5059
{
5160
var options =
5261
new OptionsCollection(GetLanguage())
5362
{
5463
{ GenerationOptions.PlaceSystemNamespaceFirst, placeSystemNamespaceFirst },
5564
{ GenerationOptions.SeparateImportDirectiveGroups, separateImportDirectiveGroups },
65+
{ CSharpCodeStyleOptions.PreferredUsingDirectivePlacement, placeInsideNamespace ? InsideNamespaceOption : OutsideNamespaceOption },
5666
};
5767
return TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: options);
5868
}
@@ -353,4 +363,29 @@ class C
353363
List<Type> list;
354364
}
355365
""", placeSystemNamespaceFirst: true, separateImportDirectiveGroups: true);
366+
367+
[WpfTheory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/54842")]
368+
public Task TestWithNamespace(bool placeInsideNamespace)
369+
=> TestInRegularAndScriptAsync("""
370+
namespace N
371+
{
372+
using System;
373+
374+
class C
375+
{
376+
[|List<Type> list;|]
377+
}
378+
}
379+
""", """
380+
namespace N
381+
{
382+
using System;
383+
using System.Collections.Generic;
384+
385+
class C
386+
{
387+
List<Type> list;
388+
}
389+
}
390+
""", placeSystemNamespaceFirst: true, separateImportDirectiveGroups: true, placeInsideNamespace);
356391
}

src/EditorFeatures/CSharpTest/CodeActions/AddUsing/AbstractAddUsingTests.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
#nullable disable
6-
75
using System.Diagnostics.CodeAnalysis;
86
using System.Threading.Tasks;
97
using Microsoft.CodeAnalysis.CodeActions;
@@ -18,14 +16,10 @@
1816

1917
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.AddUsing;
2018

21-
public abstract class AbstractAddUsingTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
19+
public abstract class AbstractAddUsingTests(ITestOutputHelper? logger = null)
20+
: AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest(logger)
2221
{
23-
protected AbstractAddUsingTests(ITestOutputHelper logger = null)
24-
: base(logger)
25-
{
26-
}
27-
28-
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
22+
internal override (DiagnosticAnalyzer?, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
2923
=> (null, new CSharpAddImportCodeFixProvider());
3024

3125
private protected OptionsCollection SeparateGroups => Option(GenerationOptions.SeparateImportDirectiveGroups, true);
@@ -36,7 +30,7 @@ internal Task TestAsync(
3630
TestHost testHost,
3731
int index = 0,
3832
CodeActionPriority? priority = null,
39-
OptionsCollection options = null)
33+
OptionsCollection? options = null)
4034
=> TestInRegularAndScript1Async(
4135
initialMarkup,
4236
expectedMarkup,

src/EditorFeatures/CSharpTest/CodeActions/AddUsing/AddUsingTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6633,4 +6633,17 @@ class Program
66336633
""",
66346634
index: 0,
66356635
parameters: new TestParameters(testHost: testHost));
6636+
6637+
[Theory, CombinatorialData]
6638+
[WorkItem("https://github.com/dotnet/roslyn/issues/72022")]
6639+
public Task TestAssemblyLevelAttribute(TestHost testHost)
6640+
=> TestAsync(
6641+
"""
6642+
[assembly: [|NeutralResourcesLanguage|]("en")]
6643+
""",
6644+
"""
6645+
using System.Resources;
6646+
6647+
[assembly: NeutralResourcesLanguage("en")]
6648+
""", testHost);
66366649
}

src/EditorFeatures/CSharpTest/CodeActions/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
using Microsoft.CodeAnalysis.Testing;
2121
using Roslyn.Test.Utilities;
2222
using Xunit;
23-
using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeRefactoringVerifier<
24-
Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers.GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider>;
2523

2624
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.GenerateEqualsAndGetHashCodeFromMembers;
2725

26+
using VerifyCS = CSharpCodeRefactoringVerifier<
27+
GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider>;
28+
2829
[UseExportProvider]
2930
[Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
3031
public sealed class GenerateEqualsAndGetHashCodeFromMembersTests
@@ -69,10 +70,7 @@ private static OptionsCollection PreferExplicitTypeWithInfo()
6970
internal static void EnableOption(ImmutableArray<PickMembersOption> options, string id)
7071
{
7172
var option = options.FirstOrDefault(o => o.Id == id);
72-
if (option != null)
73-
{
74-
option.Value = true;
75-
}
73+
option?.Value = true;
7674
}
7775

7876
[Fact]

src/EditorFeatures/CSharpTest/CodeActions/MoveStaticMembers/CSharpMoveStaticMembersTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44

55
using System.Collections.Immutable;
66
using System.Threading.Tasks;
7+
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.MoveStaticMembers;
8+
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
79
using Microsoft.CodeAnalysis.MoveStaticMembers;
810
using Microsoft.CodeAnalysis.Test.Utilities;
911
using Microsoft.CodeAnalysis.Test.Utilities.MoveStaticMembers;
1012
using Roslyn.Test.Utilities;
1113
using Xunit;
12-
using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeRefactoringVerifier<
13-
Microsoft.CodeAnalysis.CSharp.CodeRefactorings.MoveStaticMembers.CSharpMoveStaticMembersRefactoringProvider>;
1414

1515
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MoveStaticMembers;
1616

17+
using VerifyCS = CSharpCodeRefactoringVerifier<
18+
CSharpMoveStaticMembersRefactoringProvider>;
19+
1720
[UseExportProvider]
1821
[Trait(Traits.Feature, Traits.Features.CodeActionsMoveStaticMembers)]
1922
public sealed class CSharpMoveStaticMembersTests

0 commit comments

Comments
 (0)