diff --git a/src/CodeStyle/Core/Tests/UnitTestUtilities/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj b/src/CodeStyle/Core/Tests/UnitTestUtilities/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj
index 69807d0f912fa..3a5c8ce8f9c94 100644
--- a/src/CodeStyle/Core/Tests/UnitTestUtilities/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj
+++ b/src/CodeStyle/Core/Tests/UnitTestUtilities/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj
@@ -24,7 +24,7 @@
-
+
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SemanticSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SemanticSnippetCompletionProviderTests.cs
new file mode 100644
index 0000000000000..83eb82f956ba1
--- /dev/null
+++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SemanticSnippetCompletionProviderTests.cs
@@ -0,0 +1,81 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading.Tasks;
+using Microsoft.CodeAnalysis.CSharp.Completion.CompletionProviders.Snippets;
+using Microsoft.CodeAnalysis.Test.Utilities;
+using Roslyn.Test.Utilities;
+using Xunit;
+
+namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders;
+
+[Trait(Traits.Feature, Traits.Features.Completion)]
+public sealed class SemanticSnippetCompletionProviderTests : AbstractCSharpCompletionProviderTests
+{
+ public SemanticSnippetCompletionProviderTests()
+ {
+ ShowNewSnippetExperience = true;
+ }
+
+ internal override Type GetCompletionProviderType()
+ => typeof(CSharpSnippetCompletionProvider);
+
+ [WpfFact]
+ public async Task InsertConsoleSnippetWithInvocationBeforeAndAfterCursorTest()
+ {
+ var markupBeforeCommit = """
+ class Program
+ {
+ public void Method()
+ {
+ Wr$$Blah
+ }
+ }
+ """;
+
+ var expectedCodeAfterCommit = """
+ using System;
+
+ class Program
+ {
+ public void Method()
+ {
+ Console.WriteLine($$);
+ }
+ }
+ """;
+
+ await VerifyCustomCommitProviderAsync(markupBeforeCommit, "cw", expectedCodeAfterCommit);
+ }
+
+ [WpfFact]
+ public async Task InsertConsoleSnippetWithInvocationUnderscoreBeforeAndAfterCursorTest()
+ {
+ var markupBeforeCommit =
+ """
+ class Program
+ {
+ public void Method()
+ {
+ _Wr$$Blah_
+ }
+ }
+ """;
+
+ var expectedCodeAfterCommit =
+ """
+ using System;
+
+ class Program
+ {
+ public void Method()
+ {
+ Console.WriteLine($$);
+ }
+ }
+ """;
+ await VerifyCustomCommitProviderAsync(markupBeforeCommit, "cw", expectedCodeAfterCommit);
+ }
+}
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpAutoPropertyCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpAutoPropertyCompletionProviderTests.cs
deleted file mode 100644
index 9d689789446a6..0000000000000
--- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpAutoPropertyCompletionProviderTests.cs
+++ /dev/null
@@ -1,172 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Threading.Tasks;
-using Microsoft.CodeAnalysis.Test.Utilities;
-using Microsoft.CodeAnalysis.Testing;
-using Roslyn.Test.Utilities;
-using Xunit;
-
-namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets;
-
-public abstract class AbstractCSharpAutoPropertyCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests
-{
- protected abstract string GetDefaultPropertyBlockText();
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task MissingInNamespace()
- {
- await VerifyPropertyAbsenceAsync("""
- namespace Namespace
- {
- $$
- }
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task MissingInFilescopedNamespace()
- {
- await VerifyPropertyAbsenceAsync("""
- namespace Namespace;
-
- $$
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task MissingInTopLevelContext()
- {
- await VerifyPropertyAbsenceAsync("""
- System.Console.WriteLine();
- $$
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task InsertSnippetInClass()
- {
- await VerifyDefaultPropertyAsync("""
- class MyClass
- {
- $$
- }
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task InsertSnippetInRecord()
- {
- await VerifyDefaultPropertyAsync("""
- record MyRecord
- {
- $$
- }
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task InsertSnippetInStruct()
- {
- await VerifyDefaultPropertyAsync("""
- struct MyStruct
- {
- $$
- }
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public abstract Task InsertSnippetInReadonlyStruct();
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public abstract Task InsertSnippetInReadonlyStruct_ReadonlyModifierInOtherPartialDeclaration();
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public abstract Task InsertSnippetInReadonlyStruct_ReadonlyModifierInOtherPartialDeclaration_MissingPartialModifier();
-
- // This case might produce non-default results for different snippets (e.g. no `set` accessor in 'propg' snippet),
- // so it is tested separately for all of them
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public abstract Task InsertSnippetInInterface();
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task InsertSnippetNaming()
- {
- await VerifyDefaultPropertyAsync("""
- class MyClass
- {
- public int MyProperty { get; set; }
- $$
- }
- """, "MyProperty1");
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task MissingInEnum()
- {
- await VerifyPropertyAbsenceAsync("""
- enum MyEnum
- {
- $$
- }
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task MissingInMethod()
- {
- await VerifyPropertyAbsenceAsync("""
- class Program
- {
- public void Method()
- {
- $$
- }
- }
- """);
- }
-
- [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
- public async Task MissingInConstructor()
- {
- await VerifyPropertyAbsenceAsync("""
- class Program
- {
- public Program()
- {
- $$
- }
- }
- """);
- }
-
- [WpfTheory, Trait(Traits.Feature, Traits.Features.Completion)]
- [InlineData("public")]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- [InlineData("protected internal")]
- public async Task AfterAccessibilityModifier(string modifier)
- {
- await VerifyPropertyAsync($$"""
- class Program
- {
- {{modifier}} $$
- }
- """, $"int MyProperty {GetDefaultPropertyBlockText()}");
- }
-
- private Task VerifyPropertyAbsenceAsync(string markup) => VerifyItemIsAbsentAsync(markup, ItemToCommit);
-
- protected async Task VerifyPropertyAsync(string markup, string propertyText)
- {
- TestFileMarkupParser.GetPosition(markup, out var code, out var position);
- var expectedCode = code.Insert(position, propertyText + "$$");
- await VerifyCustomCommitProviderAsync(markup, ItemToCommit, expectedCode);
- }
-
- protected Task VerifyDefaultPropertyAsync(string markup, string propertyName = "MyProperty")
- => VerifyPropertyAsync(markup, $"public int {propertyName} {GetDefaultPropertyBlockText()}");
-}
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpSnippetCompletionProviderTests.cs
deleted file mode 100644
index 64fe0106bb973..0000000000000
--- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpSnippetCompletionProviderTests.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using Microsoft.CodeAnalysis.CSharp.Completion.CompletionProviders.Snippets;
-
-namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets;
-
-public abstract class AbstractCSharpSnippetCompletionProviderTests : AbstractCSharpCompletionProviderTests
-{
- protected abstract string ItemToCommit { get; }
-
- protected AbstractCSharpSnippetCompletionProviderTests()
- {
- ShowNewSnippetExperience = true;
- }
-
- internal override Type GetCompletionProviderType()
- => typeof(CSharpSnippetCompletionProvider);
-}
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpClassSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpClassSnippetCompletionProviderTests.cs
deleted file mode 100644
index 4af897017458a..0000000000000
--- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpClassSnippetCompletionProviderTests.cs
+++ /dev/null
@@ -1,547 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Threading.Tasks;
-using Microsoft.CodeAnalysis.Test.Utilities;
-using Roslyn.Test.Utilities;
-using Xunit;
-
-namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets;
-
-[Trait(Traits.Feature, Traits.Features.Completion)]
-public class CSharpClassSnippetCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests
-{
- protected override string ItemToCommit => "class";
-
- [WpfFact]
- public async Task InsertClassSnippetInNamespaceTest()
- {
- var markupBeforeCommit =
- """
- namespace Namespace
- {
- $$
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- namespace Namespace
- {
- class MyClass
- {
- $$
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassSnippetInFileScopedNamespaceTest()
- {
- var markupBeforeCommit =
- """
- namespace Namespace;
-
- $$
- """;
-
- var expectedCodeAfterCommit =
- """
- namespace Namespace;
-
- class MyClass
- {
- $$
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassSnippetTest()
- {
- var markupBeforeCommit =
-@"$$";
-
- var expectedCodeAfterCommit =
- """
- class MyClass
- {
- $$
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassTopLevelSnippetTest()
- {
- var markupBeforeCommit =
- """
- System.Console.WriteLine();
- $$
- """;
-
- var expectedCodeAfterCommit =
- """
- System.Console.WriteLine();
- class MyClass
- {
- $$
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassSnippetInClassTest()
- {
- var markupBeforeCommit =
- """
- class MyClass
- {
- $$
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- class MyClass
- {
- class MyClass1
- {
- $$
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassSnippetInRecordTest()
- {
- var markupBeforeCommit =
- """
- record MyRecord
- {
- $$
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- record MyRecord
- {
- class MyClass
- {
- $$
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassSnippetInStructTest()
- {
- var markupBeforeCommit =
- """
- struct MyStruct
- {
- $$
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- struct MyStruct
- {
- class MyClass
- {
- $$
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassSnippetInInterfaceTest()
- {
- var markupBeforeCommit =
- """
- interface MyInterface
- {
- $$
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- interface MyInterface
- {
- class MyClass
- {
- $$
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertClassSnippetWithModifiersTest()
- {
- var markupBeforeCommit =
- $@"
-
-
-
-$$
-
-
-root = true
-
-[*]
-# IDE0008: Use explicit type
-dotnet_style_require_accessibility_modifiers = always
-
-
-";
- var expectedCodeAfterCommit =
- $@"
-public class MyClass
-{{
- $$
-}}
-";
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoClassSnippetInEnumTest()
- {
- var markupBeforeCommit =
- """
- enum MyEnum
- {
- $$
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoClassSnippetInMethodTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- $$
- }
- }
- """;
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoClassSnippetInConstructorTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public Program()
- {
- $$
- }
- }
- """;
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("public")]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- [InlineData("protected internal")]
- public async Task AfterAccessibilityModifier(string modifier)
- {
- var markupBeforeCommit = $"{modifier} $$";
-
- var expectedCodeAfterCommit = $$"""
- {{modifier}} class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("public")]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- [InlineData("protected internal")]
- public async Task AfterAccessibilityModifier_RequireAccessibilityModifiers(string modifier)
- {
- var markupBeforeCommit = $$"""
-
-
- {{modifier}} $$
-
- root = true
-
- [*]
- # IDE0008: Use explicit type
- dotnet_style_require_accessibility_modifiers = always
-
-
-
- """;
-
- var expectedCodeAfterCommit = $$"""
- {{modifier}} class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("abstract")]
- [InlineData("sealed")]
- [InlineData("static")]
- [InlineData("unsafe")]
- public async Task InsertClassSnippetAfterValidModifiersTest(string modifier)
- {
- var markupBeforeCommit = $"{modifier} $$";
-
- var expectedCodeAfterCommit = $$"""
- {{modifier}} class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("ref")]
- [InlineData("readonly")]
- public async Task NoClassSnippetAfterInvalidModifiersTest(string modifier)
- {
- var markupBeforeCommit = $"{modifier} $$";
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/69600")]
- [InlineData("public")]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- [InlineData("protected internal")]
- public async Task NoAdditionalAccessibilityModifiersIfAfterPartialKeywordTest(string modifier)
- {
- var markupBeforeCommit = $$"""
-
-
- {{modifier}} partial $$
-
- root = true
-
- [*]
- # IDE0008: Use explicit type
- dotnet_style_require_accessibility_modifiers = always
-
-
-
- """;
-
- var expectedCodeAfterCommit = $$"""
- {{modifier}} partial class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/69600")]
- public async Task EnsureCorrectModifierOrderAfterPartialKeywordTest()
- {
- var markupBeforeCommit = """
-
-
- partial $$
-
- root = true
-
- [*]
- # IDE0008: Use explicit type
- dotnet_style_require_accessibility_modifiers = always
-
-
-
- """;
-
- var expectedCodeAfterCommit = """
- public partial class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/69600")]
- public async Task EnsureCorrectModifierOrderAfterPartialKeywordTest_InvalidPreferredModifiersList()
- {
- var markupBeforeCommit = """
-
-
- partial $$
-
- [*]
- dotnet_style_require_accessibility_modifiers = always
-
- csharp_preferred_modifier_order = invalid!
-
-
-
- """;
-
- var expectedCodeAfterCommit = """
- public partial class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task EnsureCorrectModifierOrderFromOptionsTest_PublicModifierBeforeAllOthers()
- {
- var markupBeforeCommit = """
-
-
- sealed unsafe $$
-
- [*]
- dotnet_style_require_accessibility_modifiers = always
-
- csharp_preferred_modifier_order = public,sealed,unsafe
-
-
-
- """;
-
- var expectedCodeAfterCommit = """
- public sealed unsafe class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task EnsureCorrectModifierOrderFromOptionsTest_PublicModifierBeforeAllOthers_NotAllModifiersInTheList()
- {
- var markupBeforeCommit = """
-
-
- sealed unsafe $$
-
- [*]
- dotnet_style_require_accessibility_modifiers = always
-
- csharp_preferred_modifier_order = public,sealed
-
-
-
- """;
-
- var expectedCodeAfterCommit = """
- public sealed unsafe class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task EnsureCorrectModifierOrderFromOptionsTest_PublicModifierBetweenOthers()
- {
- var markupBeforeCommit = """
-
-
- sealed unsafe $$
-
- [*]
- dotnet_style_require_accessibility_modifiers = always
-
- csharp_preferred_modifier_order = sealed,public,unsafe
-
-
-
- """;
-
- var expectedCodeAfterCommit = """
- sealed public unsafe class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task EnsureCorrectModifierOrderFromOptionsTest_PublicModifierAfterAllOthers()
- {
- var markupBeforeCommit = """
-
-
- sealed unsafe $$
-
- [*]
- dotnet_style_require_accessibility_modifiers = always
-
- csharp_preferred_modifier_order = sealed,unsafe,public
-
-
-
- """;
-
- var expectedCodeAfterCommit = """
- sealed unsafe public class MyClass
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-}
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs
deleted file mode 100644
index 43a98dac711ff..0000000000000
--- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs
+++ /dev/null
@@ -1,584 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Threading.Tasks;
-using Microsoft.CodeAnalysis.Test.Utilities;
-using Roslyn.Test.Utilities;
-using Xunit;
-
-namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets;
-
-[Trait(Traits.Feature, Traits.Features.Completion)]
-public class CSharpConsoleSnippetCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests
-{
- protected override string ItemToCommit => "cw";
-
- [WpfFact]
- public async Task InsertConsoleSnippetInMethodTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- Wr$$
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- class Program
- {
- public void Method()
- {
- Console.WriteLine($$);
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertNormalConsoleSnippetInAsyncContextTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public async Task MethodAsync()
- {
- Wr$$
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- class Program
- {
- public async Task MethodAsync()
- {
- Console.WriteLine($$);
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertConsoleSnippetGlobalTest()
- {
- var markupBeforeCommit =
- """
- $$
- class Program
- {
- public async Task MethodAsync()
- {
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- Console.WriteLine($$);
- class Program
- {
- public async Task MethodAsync()
- {
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInBlockNamespaceTest()
- {
- var markupBeforeCommit =
- """
- namespace Namespace
- {
- $$
- class Program
- {
- public async Task MethodAsync()
- {
- }
- }
- }
- """;
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInFileScopedNamespaceTest()
- {
- var markupBeforeCommit =
- """
- namespace Namespace;
- $$
- class Program
- {
- public async Task MethodAsync()
- {
- }
- }
- """;
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task InsertConsoleSnippetInConstructorTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public Program()
- {
- var x = 5;
- $$
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- class Program
- {
- public Program()
- {
- var x = 5;
- Console.WriteLine($$);
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertConsoleSnippetInLocalFunctionTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- var x = 5;
- void LocalMethod()
- {
- $$
- }
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- class Program
- {
- public void Method()
- {
- var x = 5;
- void LocalMethod()
- {
- Console.WriteLine($$);
- }
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertConsoleSnippetInAnonymousFunctionTest()
- {
- var markupBeforeCommit =
- """
- public delegate void Print(int value);
-
- static void Main(string[] args)
- {
- Print print = delegate(int val) {
- $$
- };
-
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- public delegate void Print(int value);
-
- static void Main(string[] args)
- {
- Print print = delegate(int val) {
- Console.WriteLine($$);
- };
-
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertConsoleSnippetInParenthesizedLambdaExpressionTest()
- {
- var markupBeforeCommit =
- """
- Func testForEquality = (x, y) =>
- {
- $$
- return x == y;
- };
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- Func testForEquality = (x, y) =>
- {
- Console.WriteLine($$);
- return x == y;
- };
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInSwitchExpression()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- var operation = 2;
-
- var result = operation switch
- {
- $$
- 1 => "Case 1",
- 2 => "Case 2",
- 3 => "Case 3",
- 4 => "Case 4",
- };
- }
- }
- """;
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInSingleLambdaExpression()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- Func f = x => $$;
- }
- }
- """;
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInStringTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- var str = "$$";
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInObjectInitializerTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- var str = new Test($$);
- }
- }
-
- class Test
- {
- private string val;
-
- public Test(string val)
- {
- this.val = val;
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInParameterListTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method(int x, $$)
- {
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInRecordDeclarationTest()
- {
- var markupBeforeCommit =
- """
- public record Person
- {
- $$
- public string FirstName { get; init; } = default!;
- public string LastName { get; init; } = default!;
- };
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoConsoleSnippetInVariableDeclarationTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- var x = $$
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task InsertConsoleSnippetWithInvocationBeforeAndAfterCursorTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- Wr$$Blah
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- class Program
- {
- public void Method()
- {
- Console.WriteLine($$);
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertConsoleSnippetWithInvocationUnderscoreBeforeAndAfterCursorTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public void Method()
- {
- _Wr$$Blah_
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- class Program
- {
- public void Method()
- {
- Console.WriteLine($$);
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- ///
- /// We want to fix this case and insert the fully qualified namespace
- /// in a future fix.
- ///
- [WpfFact]
- public async Task InsertConsoleSnippetWithPropertyNamedConsoleTest()
- {
- var markupBeforeCommit =
- """
- class Program
- {
- public int Console { get; set; }
-
- public void Method()
- {
- $$
- }
- }
- """;
-
- var expectedCodeAfterCommit =
- """
- using System;
-
- class Program
- {
- public int Console { get; set; }
-
- public void Method()
- {
- Console.WriteLine($$);
- }
- }
- """;
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/72266")]
- public async Task InsertConsoleSnippetInVoidReturningLambdaTest1()
- {
- var markupBeforeCommit = """
- using System;
-
- M(() => $$);
-
- void M(Action a)
- {
- }
- """;
-
- var expectedCodeAfterCommit = """
- using System;
-
- M(() => Console.WriteLine($$));
-
- void M(Action a)
- {
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/72266")]
- public async Task InsertConsoleSnippetInVoidReturningLambdaTest2()
- {
- var markupBeforeCommit = """
- using System;
-
- Action action = () => $$
- """;
-
- var expectedCodeAfterCommit = """
- using System;
-
- Action action = () => Console.WriteLine($$)
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/72266")]
- public async Task InsertConsoleSnippetInVoidReturningLambdaTest_TypeInference()
- {
- var markupBeforeCommit = """
- using System;
-
- var action = () => $$
- """;
-
- var expectedCodeAfterCommit = """
- using System;
-
- var action = () => Console.WriteLine($$)
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/72266")]
- public async Task NoConsoleSnippetInNonVoidReturningLambdaTest1()
- {
- var markupBeforeCommit = """
- using System;
-
- M(() => $$);
-
- void M(Func f)
- {
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/72266")]
- public async Task NoConsoleSnippetInNonVoidReturningLambdaTest2()
- {
- var markupBeforeCommit = """
- using System;
-
- Func f = () => $$
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-}
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpDoSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpDoSnippetCompletionProviderTests.cs
deleted file mode 100644
index e1ae704c239b1..0000000000000
--- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpDoSnippetCompletionProviderTests.cs
+++ /dev/null
@@ -1,709 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Threading.Tasks;
-using Microsoft.CodeAnalysis.Test.Utilities;
-using Roslyn.Test.Utilities;
-using Xunit;
-
-namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets;
-
-[Trait(Traits.Feature, Traits.Features.Completion)]
-public class CSharpDoSnippetCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests
-{
- protected override string ItemToCommit => "do";
-
- [WpfFact]
- public async Task InsertSnippetInMethodTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- $$
- }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class Program
- {
- public void Method()
- {
- do
- {
- $$
- }
- while (true);
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertSnippetInGlobalContextTest()
- {
- var markupBeforeCommit = """
- Ins$$
- """;
-
- var expectedCodeAfterCommit = """
- do
- {
- $$
- }
- while (true);
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInBlockNamespaceTest()
- {
- var markupBeforeCommit = """
- namespace Namespace
- {
- $$
- class Program
- {
- public async Task MethodAsync()
- {
- }
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInFileScopedNamespaceTest()
- {
- var markupBeforeCommit = """
- namespace Namespace;
- $$
- class Program
- {
- public async Task MethodAsync()
- {
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task InsertSnippetInConstructorTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public Program()
- {
- var x = 5;
- $$
- }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class Program
- {
- public Program()
- {
- var x = 5;
- do
- {
- $$
- }
- while (true);
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertSnippetInLocalFunctionTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- var x = 5;
- void LocalMethod()
- {
- $$
- }
- }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class Program
- {
- public void Method()
- {
- var x = 5;
- void LocalMethod()
- {
- do
- {
- $$
- }
- while (true);
- }
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertSnippetInAnonymousFunctionTest()
- {
- var markupBeforeCommit = """
- public delegate void Print(int value);
-
- static void Main(string[] args)
- {
- Print print = delegate(int val) {
- $$
- };
-
- }
- """;
-
- var expectedCodeAfterCommit = """
- public delegate void Print(int value);
-
- static void Main(string[] args)
- {
- Print print = delegate(int val) {
- do
- {
- $$
- }
- while (true);
- };
-
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertSnippetInParenthesizedLambdaExpressionTest()
- {
- var markupBeforeCommit = """
- Func testForEquality = (x, y) =>
- {
- $$
- return x == y;
- };
- """;
-
- var expectedCodeAfterCommit = """
- Func testForEquality = (x, y) =>
- {
- do
- {
- $$
- }
- while (true);
- return x == y;
- };
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInSwitchExpression()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- var operation = 2;
-
- var result = operation switch
- {
- $$
- 1 => "Case 1",
- 2 => "Case 2",
- 3 => "Case 3",
- 4 => "Case 4",
- };
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInSingleLambdaExpression()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- Func f = x => $$;
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInStringTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- var str = "$$";
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInObjectInitializerTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- var str = new Test($$);
- }
- }
-
- class Test
- {
- private string val;
-
- public Test(string val)
- {
- this.val = val;
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInParameterListTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method(int x, $$)
- {
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInRecordDeclarationTest()
- {
- var markupBeforeCommit = """
- public record Person
- {
- $$
- public string FirstName { get; init; } = default!;
- public string LastName { get; init; } = default!;
- };
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoSnippetInVariableDeclarationTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- var x = $$
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task InsertSnippetWithInvocationBeforeAndAfterCursorTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- Wr$$Blah
- }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class Program
- {
- public void Method()
- {
- do
- {
- $$
- }
- while (true);
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertSnippetWithInvocationUnderscoreBeforeAndAfterCursorTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- public void Method()
- {
- _Wr$$Blah_
- }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class Program
- {
- public void Method()
- {
- do
- {
- $$
- }
- while (true);
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertInlineSnippetForCorrectTypeTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- void M(bool arg)
- {
- arg.$$
- }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class Program
- {
- void M(bool arg)
- {
- do
- {
- $$
- }
- while (arg);
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoInlineSnippetForIncorrectTypeTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- void M(int arg)
- {
- arg.$$
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoInlineSnippetWhenNotDirectlyExpressionStatementTest()
- {
- var markupBeforeCommit = """
- class Program
- {
- void M(bool arg)
- {
- System.Console.WriteLine(arg.$$);
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("// comment")]
- [InlineData("/* comment */")]
- [InlineData("#region test")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInMethodTest1(string trivia)
- {
- var markupBeforeCommit = $$"""
- class Program
- {
- void M(bool arg)
- {
- {{trivia}}
- arg.$$
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class Program
- {
- void M(bool arg)
- {
- {{trivia}}
- do
- {
- $$
- }
- while (arg);
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("#if true")]
- [InlineData("#pragma warning disable CS0108")]
- [InlineData("#nullable enable")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInMethodTest2(string trivia)
- {
- var markupBeforeCommit = $$"""
- class Program
- {
- void M(bool arg)
- {
- {{trivia}}
- arg.$$
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class Program
- {
- void M(bool arg)
- {
- {{trivia}}
- do
- {
- $$
- }
- while (arg);
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("// comment")]
- [InlineData("/* comment */")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInGlobalStatementTest1(string trivia)
- {
- var markupBeforeCommit = $$"""
- {{trivia}}
- true.$$
- """;
-
- var expectedCodeAfterCommit = $$"""
- {{trivia}}
- do
- {
- $$
- }
- while (true);
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("#region test")]
- [InlineData("#if true")]
- [InlineData("#pragma warning disable CS0108")]
- [InlineData("#nullable enable")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInGlobalStatementTest2(string trivia)
- {
- var markupBeforeCommit = $$"""
- {{trivia}}
- true.$$
- """;
-
- var expectedCodeAfterCommit = $$"""
-
- {{trivia}}
- do
- {
- $$
- }
- while (true);
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/69598")]
- public async Task InsertInlineSnippetWhenDottingBeforeContextualKeywordTest1()
- {
- var markupBeforeCommit = """
- using System.Collections.Generic;
-
- class C
- {
- void M(bool flag)
- {
- flag.$$
- var a = 0;
- }
- }
- """;
-
- var expectedCodeAfterCommit = """
- using System.Collections.Generic;
-
- class C
- {
- void M(bool flag)
- {
- do
- {
- $$
- }
- while (flag);
- var a = 0;
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/69598")]
- public async Task InsertInlineSnippetWhenDottingBeforeContextualKeywordTest2()
- {
- var markupBeforeCommit = """
- using System.Collections.Generic;
-
- class C
- {
- void M(bool flag, Task t)
- {
- flag.$$
- await t;
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M(bool flag, Task t)
- {
- do
- {
- $$
- }
- while (flag);
- await t;
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/69598")]
- [InlineData("Task")]
- [InlineData("Task")]
- [InlineData("System.Threading.Tasks.Task")]
- public async Task InsertInlineSnippetWhenDottingBeforeNameSyntaxTest(string nameSyntax)
- {
- var markupBeforeCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M(bool flag)
- {
- flag.$$
- {{nameSyntax}} t = null;
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M(bool flag)
- {
- do
- {
- $$
- }
- while (flag);
- {{nameSyntax}} t = null;
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-}
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpEnumSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpEnumSnippetCompletionProviderTests.cs
deleted file mode 100644
index 98e1635773035..0000000000000
--- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpEnumSnippetCompletionProviderTests.cs
+++ /dev/null
@@ -1,285 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Threading.Tasks;
-using Roslyn.Test.Utilities;
-using Xunit;
-
-namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets;
-
-public class CSharpEnumSnippetCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests
-{
- protected override string ItemToCommit => "enum";
-
- [WpfFact]
- public async Task InsertEnumSnippetInNamespaceTest()
- {
- await VerifyCustomCommitProviderAsync("""
- namespace Namespace
- {
- $$
- }
- """, ItemToCommit, """
- namespace Namespace
- {
- enum MyEnum
- {
- $$
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumSnippetInFileScopedNamespaceTest()
- {
- await VerifyCustomCommitProviderAsync("""
- namespace Namespace;
-
- $$
- """, ItemToCommit, """
- namespace Namespace;
-
- enum MyEnum
- {
- $$
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumSnippetTest()
- {
- await VerifyCustomCommitProviderAsync("""
- $$
- """, ItemToCommit, """
- enum MyEnum
- {
- $$
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumTopLevelSnippetTest()
- {
- await VerifyCustomCommitProviderAsync("""
- System.Console.WriteLine();
- $$
- """, ItemToCommit, """
- System.Console.WriteLine();
- enum MyEnum
- {
- $$
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumSnippetInClassTest()
- {
- await VerifyCustomCommitProviderAsync("""
- class MyClass
- {
- $$
- }
- """, ItemToCommit, """
- class MyClass
- {
- enum MyEnum
- {
- $$
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumSnippetInRecordTest()
- {
- await VerifyCustomCommitProviderAsync("""
- record MyRecord
- {
- $$
- }
- """, ItemToCommit, """
- record MyRecord
- {
- enum MyEnum
- {
- $$
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumSnippetInStructTest()
- {
- await VerifyCustomCommitProviderAsync("""
- struct MyStruct
- {
- $$
- }
- """, ItemToCommit, """
- struct MyStruct
- {
- enum MyEnum
- {
- $$
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumSnippetInInterfaceTest()
- {
- await VerifyCustomCommitProviderAsync("""
- interface MyInterface
- {
- $$
- }
- """, ItemToCommit, """
- interface MyInterface
- {
- enum MyEnum
- {
- $$
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertEnumSnippetWithModifiersTest()
- {
- await VerifyCustomCommitProviderAsync("""
-
-
- $$
-
- root = true
-
- [*]
- # IDE0008: Use explicit type
- dotnet_style_require_accessibility_modifiers = always
-
-
-
- """, ItemToCommit, """
- public enum MyEnum
- {
- $$
- }
- """);
- }
-
- [WpfFact]
- public async Task NoEnumSnippetInEnumTest()
- {
- await VerifyItemIsAbsentAsync("""
- enum MyEnum
- {
- $$
- }
- """, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoEnumSnippetInMethodTest()
- {
- await VerifyItemIsAbsentAsync("""
- class Program
- {
- public void Method()
- {
- $$
- }
- }
- """, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoEnumSnippetInConstructorTest()
- {
- await VerifyItemIsAbsentAsync("""
- class Program
- {
- public Program()
- {
- $$
- }
- }
- """, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("public")]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- [InlineData("protected internal")]
- public async Task AfterAccessibilityModifier(string modifier)
- {
- var markupBeforeCommit = $"{modifier} $$";
-
- var expectedCodeAfterCommit = $$"""
- {{modifier}} enum MyEnum
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("public")]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- [InlineData("protected internal")]
- public async Task AfterAccessibilityModifier_RequireAccessibilityModifiers(string modifier)
- {
- var markupBeforeCommit = $$"""
-
-
- {{modifier}} $$
-
- root = true
-
- [*]
- # IDE0008: Use explicit type
- dotnet_style_require_accessibility_modifiers = always
-
-
-
- """;
-
- var expectedCodeAfterCommit = $$"""
- {{modifier}} enum MyEnum
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("abstract")]
- [InlineData("partial")]
- [InlineData("sealed")]
- [InlineData("static")]
- [InlineData("ref")]
- [InlineData("readonly")]
- [InlineData("unsafe")]
- public async Task NoEnumSnippetAfterInvalidModifiersTest(string modifier)
- {
- var markupBeforeCommit = $"{modifier} $$";
-
- await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
- }
-}
diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpForSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpForSnippetCompletionProviderTests.cs
deleted file mode 100644
index e8a806a99f557..0000000000000
--- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpForSnippetCompletionProviderTests.cs
+++ /dev/null
@@ -1,1281 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Microsoft.CodeAnalysis.Test.Utilities;
-using Roslyn.Test.Utilities;
-using Xunit;
-
-namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets;
-
-[Trait(Traits.Feature, Traits.Features.Completion)]
-public class CSharpForSnippetCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests
-{
- protected override string ItemToCommit => "for";
-
- [WpfFact]
- public async Task InsertForSnippetInMethodTest()
- {
- await VerifyCustomCommitProviderAsync("""
- class Program
- {
- public void Method()
- {
- $$
- }
- }
- """, ItemToCommit, """
- class Program
- {
- public void Method()
- {
- for (int i = 0; i < length; i++)
- {
- $$
- }
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertForSnippetInMethodUsedIncrementorTest()
- {
- await VerifyCustomCommitProviderAsync("""
- class Program
- {
- public void Method()
- {
- int i;
- $$
- }
- }
- """, ItemToCommit, """
- class Program
- {
- public void Method()
- {
- int i;
- for (int j = 0; j < length; j++)
- {
- $$
- }
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertForSnippetInMethodUsedIncrementorsTest()
- {
- await VerifyCustomCommitProviderAsync("""
- class Program
- {
- public void Method()
- {
- int i, j, k;
- $$
- }
- }
- """, ItemToCommit, """
- class Program
- {
- public void Method()
- {
- int i, j, k;
- for (int i1 = 0; i1 < length; i1++)
- {
- $$
- }
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertForSnippetInGlobalContextTest()
- {
- await VerifyCustomCommitProviderAsync("""
- $$
- """, ItemToCommit, """
- for (int i = 0; i < length; i++)
- {
- $$
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertForSnippetInConstructorTest()
- {
- await VerifyCustomCommitProviderAsync("""
- class Program
- {
- public Program()
- {
- $$
- }
- }
- """, ItemToCommit, """
- class Program
- {
- public Program()
- {
- for (int i = 0; i < length; i++)
- {
- $$
- }
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertForSnippetInLocalFunctionTest()
- {
- // TODO: fix this test when bug with simplifier failing to find correct node is fixed
- await VerifyCustomCommitProviderAsync("""
- class Program
- {
- public void Method()
- {
- void LocalFunction()
- {
- $$
- }
- }
- }
- """, ItemToCommit, """
- class Program
- {
- public void Method()
- {
- void LocalFunction()
- {
- for (global::System.Int32 i = 0; i < length; i++)
- {
- $$
- }
- }
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertForSnippetInAnonymousFunctionTest()
- {
- // TODO: fix this test when bug with simplifier failing to find correct node is fixed
- await VerifyCustomCommitProviderAsync("""
- class Program
- {
- public void Method()
- {
- var action = delegate()
- {
- $$
- };
- }
- }
- """, ItemToCommit, """
- class Program
- {
- public void Method()
- {
- var action = delegate()
- {
- for (global::System.Int32 i = 0; i < length; i++)
- {
- $$
- }
- };
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task InsertForSnippetInParenthesizedLambdaExpressionTest()
- {
- // TODO: fix this test when bug with simplifier failing to find correct node is fixed
- await VerifyCustomCommitProviderAsync("""
- class Program
- {
- public void Method()
- {
- var action = () =>
- {
- $$
- };
- }
- }
- """, ItemToCommit, """
- class Program
- {
- public void Method()
- {
- var action = () =>
- {
- for (global::System.Int32 i = 0; i < length; i++)
- {
- $$
- }
- };
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task ProduceVarWithSpecificCodeStyleTest()
- {
- await VerifyCustomCommitProviderAsync("""
-
-
- class Program
- {
- public void Method()
- {
- $$
- }
- }
-
- root = true
-
- [*]
- # IDE0008: Use explicit type
- csharp_style_var_for_built_in_types = true
-
-
-
- """, ItemToCommit, """
- class Program
- {
- public void Method()
- {
- for (var i = 0; i < length; i++)
- {
- $$
- }
- }
- }
- """);
- }
-
- [WpfTheory]
- [MemberData(nameof(IntegerTypes))]
- public async Task InsertInlineForSnippetInMethodTest(string inlineExpressionType)
- {
- await VerifyCustomCommitProviderAsync($$"""
- class Program
- {
- public void Method({{inlineExpressionType}} l)
- {
- l.$$
- }
- }
- """, ItemToCommit, $$"""
- class Program
- {
- public void Method({{inlineExpressionType}} l)
- {
- for ({{inlineExpressionType}} i = 0; i < l; i++)
- {
- $$
- }
- }
- }
- """);
- }
-
- [WpfTheory]
- [MemberData(nameof(IntegerTypes))]
- public async Task InsertInlineForSnippetInGlobalContextTest(string inlineExpressionType)
- {
- await VerifyCustomCommitProviderAsync($$"""
- {{inlineExpressionType}} l;
- l.$$
- """, ItemToCommit, $$"""
- {{inlineExpressionType}} l;
- for ({{inlineExpressionType}} i = 0; i < l; i++)
- {
- $$
- }
- """);
- }
-
- [WpfTheory]
- [MemberData(nameof(NotIntegerTypes))]
- public async Task NoInlineForSnippetForIncorrectTypeInMethodTest(string inlineExpressionType)
- {
- var markup = $$"""
- class Program
- {
- public void Method({{inlineExpressionType}} l)
- {
- l.$$
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [MemberData(nameof(NotIntegerTypes))]
- public async Task NoInlineForSnippetForIncorrectTypeInGlobalContextTest(string inlineExpressionType)
- {
- var markup = $$"""
- {{inlineExpressionType}} l;
- l.$$
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfFact]
- public async Task ProduceVarWithSpecificCodeStyleForInlineSnippetTest()
- {
- await VerifyCustomCommitProviderAsync("""
-
-
- class Program
- {
- public void Method(int l)
- {
- l.$$
- }
- }
-
- root = true
-
- [*]
- # IDE0008: Use explicit type
- csharp_style_var_for_built_in_types = true
-
-
-
- """, ItemToCommit, """
- class Program
- {
- public void Method(int l)
- {
- for (var i = 0; i < l; i++)
- {
- $$
- }
- }
- }
- """);
- }
-
- [WpfFact]
- public async Task NoInlineForSnippetNotDirectlyExpressionStatementTest()
- {
- var markup = """
- class Program
- {
- public void Method(int l)
- {
- System.Console.WriteLine(l.$$);
- }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("// comment")]
- [InlineData("/* comment */")]
- [InlineData("#region test")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInMethodTest1(string trivia)
- {
- var markupBeforeCommit = $$"""
- class Program
- {
- void M(int len)
- {
- {{trivia}}
- len.$$
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class Program
- {
- void M(int len)
- {
- {{trivia}}
- for (int i = 0; i < len; i++)
- {
- $$
- }
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("#if true")]
- [InlineData("#pragma warning disable CS0108")]
- [InlineData("#nullable enable")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInMethodTest2(string trivia)
- {
- var markupBeforeCommit = $$"""
- class Program
- {
- void M(int len)
- {
- {{trivia}}
- len.$$
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class Program
- {
- void M(int len)
- {
- {{trivia}}
- for (int i = 0; i < len; i++)
- {
- $$
- }
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("// comment")]
- [InlineData("/* comment */")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInGlobalStatementTest1(string trivia)
- {
- var markupBeforeCommit = $$"""
- {{trivia}}
- 10.$$
- """;
-
- var expectedCodeAfterCommit = $$"""
- {{trivia}}
- for (int i = 0; i < 10; i++)
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("#region test")]
- [InlineData("#if true")]
- [InlineData("#pragma warning disable CS0108")]
- [InlineData("#nullable enable")]
- public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInGlobalStatementTest2(string trivia)
- {
- var markupBeforeCommit = $$"""
- {{trivia}}
- 10.$$
- """;
-
- var expectedCodeAfterCommit = $$"""
-
- {{trivia}}
- for (int i = 0; i < 10; i++)
- {
- $$
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/69598")]
- [MemberData(nameof(IntegerTypes))]
- public async Task InsertInlineForSnippetWhenDottingBeforeContextualKeywordTest1(string intType)
- {
- var markupBeforeCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M({{intType}} @int)
- {
- @int.$$
- var a = 0;
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M({{intType}} @int)
- {
- for ({{intType}} i = 0; i < @int; i++)
- {
- $$
- }
- var a = 0;
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/69598")]
- [MemberData(nameof(IntegerTypes))]
- public async Task InsertInlineForSnippetWhenDottingBeforeContextualKeywordTest2(string intType)
- {
- var markupBeforeCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M({{intType}} @int, Task t)
- {
- @int.$$
- await t;
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M({{intType}} @int, Task t)
- {
- for ({{intType}} i = 0; i < @int; i++)
- {
- $$
- }
- await t;
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/69598")]
- [InlineData("Task")]
- [InlineData("Task")]
- [InlineData("System.Threading.Tasks.Task")]
- public async Task InsertInlineForSnippetWhenDottingBeforeNameSyntaxTest(string nameSyntax)
- {
- var markupBeforeCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M(int @int)
- {
- @int.$$
- {{nameSyntax}} t = null;
- }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- using System.Collections.Generic;
-
- class C
- {
- void M(int @int)
- {
- for (int i = 0; i < @int; i++)
- {
- $$
- }
- {{nameSyntax}} t = null;
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("int[]")]
- [InlineData("Span")]
- [InlineData("ReadOnlySpan")]
- [InlineData("ImmutableArray")]
- public async Task InsertInlineForSnippetForCommonTypesWithLengthPropertyTest(string type)
- {
- var markupBeforeCommit = $$"""
-
-
- using System;
- using System.Collections.Generic;
- using System.Collections.Immutable;
-
- public class C
- {
- void M({{type.Replace("<", "<").Replace(">", ">")}} type)
- {
- type.$$
- }
- }
-
-
- """;
-
- var expectedCodeAfterCommit = $$"""
- using System;
- using System.Collections.Generic;
- using System.Collections.Immutable;
-
- public class C
- {
- void M({{type}} type)
- {
- for (int i = 0; i < type.Length; i++)
- {
- $$
- }
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("public")]
- [InlineData("internal")]
- [InlineData("protected internal")]
- public async Task InsertInlineForSnippetForTypeWithAccessibleLengthPropertyTest(string lengthPropertyAccessibility)
- {
- var markupBeforeCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- {{lengthPropertyAccessibility}} int Length { get; }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- for (int i = 0; i < type.Length; i++)
- {
- $$
- }
- }
- }
-
- public class MyType
- {
- {{lengthPropertyAccessibility}} int Length { get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("")]
- [InlineData("internal")]
- [InlineData("protected internal")]
- public async Task InsertInlineForSnippetForTypeWithAccessibleLengthPropertyGetterTest(string getterAccessibility)
- {
- var markupBeforeCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public int Length { {{getterAccessibility}} get; }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- for (int i = 0; i < type.Length; i++)
- {
- $$
- }
- }
- }
-
- public class MyType
- {
- public int Length { {{getterAccessibility}} get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [MemberData(nameof(IntegerTypes))]
- public async Task InsertInlineForSnippetForTypesWithLengthPropertyOfDifferentIntegerTypesTest(string integerType)
- {
- var markupBeforeCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public {{integerType}} Length { get; }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- for ({{integerType}} i = 0; i < type.Length; i++)
- {
- $$
- }
- }
- }
-
- public class MyType
- {
- public {{integerType}} Length { get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertInlineForSnippetForTypeWithLengthPropertyInBaseClassTest()
- {
- var markupBeforeCommit = """
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType : MyTypeBase
- {
- }
-
- public class MyTypeBase
- {
- public int Length { get; }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class C
- {
- void M(MyType type)
- {
- for (int i = 0; i < type.Length; i++)
- {
- $$
- }
- }
- }
-
- public class MyType : MyTypeBase
- {
- }
-
- public class MyTypeBase
- {
- public int Length { get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoInlineForSnippetWhenLengthPropertyHasNoGetterTest()
- {
- var markup = """
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public int Length { set { } }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- public async Task NoInlineForSnippetForInaccessibleLengthPropertyTest(string lengthPropertyAccessibility)
- {
- var markup = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- {{lengthPropertyAccessibility}} int Length { get; }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- public async Task NoInlineForSnippetForInaccessibleLengthPropertyGetterTest(string getterAccessibility)
- {
- var markup = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public int Length { {{getterAccessibility}} get; }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [MemberData(nameof(NotIntegerTypes))]
- public async Task NoInlineForSnippetForLengthPropertyOfIncorrectTypeTest(string notIntegerType)
- {
- var markup = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public {{notIntegerType}} Length { get; }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("List")]
- [InlineData("HashSet")]
- [InlineData("Dictionary")]
- [InlineData("ImmutableList")]
- public async Task InsertInlineForSnippetForCommonTypesWithCountPropertyTest(string type)
- {
- var markupBeforeCommit = $$"""
-
-
- using System;
- using System.Collections.Generic;
- using System.Collections.Immutable;
-
- public class C
- {
- void M({{type.Replace("<", "<").Replace(">", ">")}} type)
- {
- type.$$
- }
- }
-
-
- """;
-
- var expectedCodeAfterCommit = $$"""
- using System;
- using System.Collections.Generic;
- using System.Collections.Immutable;
-
- public class C
- {
- void M({{type}} type)
- {
- for (int i = 0; i < type.Count; i++)
- {
- $$
- }
- }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("public")]
- [InlineData("internal")]
- [InlineData("protected internal")]
- public async Task InsertInlineForSnippetForTypeWithAccessibleCountPropertyTest(string countPropertyAccessibility)
- {
- var markupBeforeCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- {{countPropertyAccessibility}} int Count { get; }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- for (int i = 0; i < type.Count; i++)
- {
- $$
- }
- }
- }
-
- public class MyType
- {
- {{countPropertyAccessibility}} int Count { get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [InlineData("")]
- [InlineData("internal")]
- [InlineData("protected internal")]
- public async Task InsertInlineForSnippetForTypeWithAccessibleCountPropertyGetterTest(string getterAccessibility)
- {
- var markupBeforeCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public int Count { {{getterAccessibility}} get; }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- for (int i = 0; i < type.Count; i++)
- {
- $$
- }
- }
- }
-
- public class MyType
- {
- public int Count { {{getterAccessibility}} get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfTheory]
- [MemberData(nameof(IntegerTypes))]
- public async Task InsertInlineForSnippetForTypesWithCountPropertyOfDifferentIntegerTypesTest(string integerType)
- {
- var markupBeforeCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public {{integerType}} Count { get; }
- }
- """;
-
- var expectedCodeAfterCommit = $$"""
- class C
- {
- void M(MyType type)
- {
- for ({{integerType}} i = 0; i < type.Count; i++)
- {
- $$
- }
- }
- }
-
- public class MyType
- {
- public {{integerType}} Count { get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task InsertInlineForSnippetForTypeWithCountPropertyInBaseClassTest()
- {
- var markupBeforeCommit = """
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType : MyTypeBase
- {
- }
-
- public class MyTypeBase
- {
- public int Count { get; }
- }
- """;
-
- var expectedCodeAfterCommit = """
- class C
- {
- void M(MyType type)
- {
- for (int i = 0; i < type.Count; i++)
- {
- $$
- }
- }
- }
-
- public class MyType : MyTypeBase
- {
- }
-
- public class MyTypeBase
- {
- public int Count { get; }
- }
- """;
-
- await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
- }
-
- [WpfFact]
- public async Task NoInlineForSnippetWhenCountPropertyHasNoGetterTest()
- {
- var markup = """
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public int Count { set { } }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- public async Task NoInlineForSnippetForInaccessibleCountPropertyTest(string countPropertyAccessibility)
- {
- var markup = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- {{countPropertyAccessibility}} int Count { get; }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [InlineData("private")]
- [InlineData("protected")]
- [InlineData("private protected")]
- public async Task NoInlineForSnippetForInaccessibleCountPropertyGetterTest(string getterAccessibility)
- {
- var markup = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public int Count { {{getterAccessibility}} get; }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfTheory]
- [MemberData(nameof(NotIntegerTypes))]
- public async Task NoInlineForSnippetForCountPropertyOfIncorrectTypeTest(string notIntegerType)
- {
- var markup = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public {{notIntegerType}} Count { get; }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- [WpfFact]
- public async Task NoInlineForSnippetForTypeWithBothLengthAndCountPropertyTest()
- {
- var markup = $$"""
- class C
- {
- void M(MyType type)
- {
- type.$$
- }
- }
-
- public class MyType
- {
- public int Length { get; }
- public int Count { get; }
- }
- """;
-
- await VerifyItemIsAbsentAsync(markup, ItemToCommit);
- }
-
- public static IEnumerable