Skip to content

Commit

Permalink
Merge pull request #70305 from sharwell/continuations
Browse files Browse the repository at this point in the history
Add line continuation tests for string concatenation
  • Loading branch information
sharwell authored Dec 27, 2023
2 parents f7b468d + a7164ee commit 2ed08d4
Showing 1 changed file with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.CodeCleanup.Providers;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.VisualBasic;
Expand Down Expand Up @@ -1298,6 +1297,74 @@ End Module
await VerifyAsync(code, expected);
}

[Theory]
[InlineData("_")]
[InlineData("_ ' Comment")]
[WorkItem("https://github.com/dotnet/roslyn/issues/69696")]
public async Task LineContinuationInString1(string continuation)
{
var code = $@"[|
Module Program
Dim x = ""1"" {continuation}
& ""2"" {continuation}
& ""3""
End Module
|]";

var expected = $@"
Module Program
Dim x = ""1"" {continuation}
& ""2"" {continuation}
& ""3""
End Module
";
await VerifyAsync(code, expected);
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/69696")]
public async Task LineContinuationInString2()
{
var code = $@"[|
Module Program
Dim x = ""1"" & _
""2"" & _
""3""
End Module
|]";

var expected = $@"
Module Program
Dim x = ""1"" &
""2"" &
""3""
End Module
";
await VerifyAsync(code, expected);
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/69696")]
public async Task LineContinuationInString3()
{
var code = $@"[|
Module Program
Dim x = ""1"" & ' Comment
""2"" & ' Comment
""3""
End Module
|]";

var expected = $@"
Module Program
Dim x = ""1"" & ' Comment
""2"" & ' Comment
""3""
End Module
";
await VerifyAsync(code, expected);
}

[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1085887")]
public async Task DoNotRemoveLineContinuationInVisualBasic9()
{
Expand Down Expand Up @@ -1378,8 +1445,8 @@ private static async Task VerifyAsync(string codeWithMarker, string expectedResu

var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], CodeCleanupOptions.GetDefault(document.Project.Services), codeCleanups);

var actualResult = (await cleanDocument.GetSyntaxRootAsync()).ToFullString();
Assert.Equal(expectedResult, actualResult);
var actualResult = (await cleanDocument.GetRequiredSyntaxRootAsync(CancellationToken.None)).ToFullString();
AssertEx.EqualOrDiff(expectedResult, actualResult);
}

private static Document CreateDocument(string code, string language, LanguageVersion langVersion)
Expand All @@ -1388,8 +1455,9 @@ private static Document CreateDocument(string code, string language, LanguageVer
var projectId = ProjectId.CreateNewId();
var project = solution
.AddProject(projectId, "Project", "Project.dll", language)
.GetProject(projectId);
.GetRequiredProject(projectId);

AssertEx.NotNull(project.ParseOptions);
var parseOptions = (VisualBasicParseOptions)project.ParseOptions;
parseOptions = parseOptions.WithLanguageVersion(langVersion);
project = project.WithParseOptions(parseOptions);
Expand Down

0 comments on commit 2ed08d4

Please sign in to comment.