Skip to content

Commit

Permalink
Semantic snippets tests (#74808)
Browse files Browse the repository at this point in the history
* Add infrustructure for semantic snippet testing

* Port `foreach` snippet

* Port `for` snippet

* Port `forr` snippet

* Port `lock` snippet

* Port `else` snippet

* Port `cw` snippet

* Port `ctor` snippet

* Port `svm` and `sim` snippets

* Port `class` snippet

* Port `struct` snippet

* Port `interface` snippet

* Port `enum` snippet

* Port `do` snippet

* Port `if` and `while` snippets

* Port `prop`, `propg` and `propi` snippets and remove leftover legacy snippet test infrastructure

* Do not show `enum` snippet after `partial` modifier

* Use common test data in a few more places

* Fix build

* Fix
  • Loading branch information
DoctorKrolic committed Aug 20, 2024
1 parent 76b0357 commit 5e6bb7a
Show file tree
Hide file tree
Showing 43 changed files with 5,198 additions and 6,910 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<Compile Include="..\..\..\..\Features\DiagnosticsTestUtilities\CodeActions\VisualBasicCodeRefactoringVerifier`1.cs" Link="VisualBasicCodeRefactoringVerifier`1.cs" />
<Compile Include="..\..\..\..\Features\DiagnosticsTestUtilities\Diagnostics\ParenthesesOptionsProvider.cs" Link="ParenthesesOptionsProvider.cs" />
<Compile Include="..\..\..\..\Features\DiagnosticsTestUtilities\NamingStyles\NamingStylesTestOptionSets.cs" Link="NamingStyles\NamingStylesTestOptionSets.cs" />
<Compile Include="..\..\..\..\Features\DiagnosticsTestUtilities\Utilities\StringSyntaxAttribute.cs" Link="Utilities\StringSyntaxAttribute.cs" />
<Compile Include="..\..\..\..\Features\TestUtilities\Utilities\StringSyntaxAttribute.cs" Link="Utilities\StringSyntaxAttribute.cs" />
<Compile Include="..\..\..\..\Workspaces\CoreTestUtilities\OptionsCollection.cs" Link="OptionsCollection.cs" />
</ItemGroup>
<ItemGroup Label="Project References">
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5e6bb7a

Please sign in to comment.