Skip to content

Commit e792c19

Browse files
committed
Fix tests
1 parent f0d28cf commit e792c19

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/WrapWithTag/RemoteWrapWithTagService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ValueTask<TextEditResponse> FixHtmlTextEditsAsync(
4545
context => FixHtmlTextEditsAsync(context, textEdits, cancellationToken),
4646
cancellationToken);
4747

48-
private async ValueTask<Response> GetValidWrappingRangeAsync(
48+
private static async ValueTask<Response> GetValidWrappingRangeAsync(
4949
RemoteDocumentContext context,
5050
LinePositionSpan range,
5151
CancellationToken cancellationToken)

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostWrapWithTagEndpointTest.cs

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Linq;
56
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Razor.Test.Common;
8+
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
69
using Microsoft.CodeAnalysis.Razor.Protocol;
7-
using Microsoft.CodeAnalysis.Testing;
810
using Microsoft.VisualStudio.Razor.LanguageClient.WrapWithTag;
11+
using Roslyn.Test.Utilities;
912
using Xunit;
1013
using Xunit.Abstractions;
1114

@@ -22,13 +25,14 @@ await VerifyWrapWithTagAsync(
2225
[||]
2326
</div>
2427
""",
28+
expected: """
29+
<div>
30+
<p></p>
31+
</div>
32+
""",
2533
htmlResponse: new VSInternalWrapWithTagResponse(
26-
LspFactory.CreateSingleLineRange(start: (0, 0), length: 10),
27-
[LspFactory.CreateTextEdit(position: (0, 0), "<p></p>")]
28-
),
29-
expected: new VSInternalWrapWithTagResponse(
30-
LspFactory.CreateSingleLineRange(start: (0, 0), length: 10),
31-
[LspFactory.CreateTextEdit(position: (0, 0), "<p></p>")]
34+
LspFactory.CreateSingleLineRange(start: (1, 4), length: 0),
35+
[LspFactory.CreateTextEdit(position: (1, 4), "<p></p>")]
3236
));
3337
}
3438

@@ -54,13 +58,14 @@ await VerifyWrapWithTagAsync(
5458
@[||]currentCount
5559
</div>
5660
""",
61+
expected: """
62+
<div>
63+
<span>@currentCount</span>
64+
</div>
65+
""",
5766
htmlResponse: new VSInternalWrapWithTagResponse(
58-
LspFactory.CreateSingleLineRange(start: (1, 4), length: 16),
59-
[LspFactory.CreateTextEdit(position: (1, 4), "<span>@currentCount</span>")]
60-
),
61-
expected: new VSInternalWrapWithTagResponse(
62-
LspFactory.CreateSingleLineRange(start: (1, 4), length: 16),
63-
[LspFactory.CreateTextEdit(position: (1, 4), "<span>@currentCount</span>")]
67+
LspFactory.CreateSingleLineRange(start: (1, 5), length: 13),
68+
[LspFactory.CreateTextEdit(1, 4, 1, 17, "<span>@currentCount</span>")]
6469
));
6570
}
6671

@@ -69,32 +74,32 @@ public async Task HtmlWithTildes_FixesTextEdits()
6974
{
7075
await VerifyWrapWithTagAsync(
7176
input: """
72-
<div>
73-
[||]
74-
</div>
75-
""",
77+
<div>
78+
@[||]currentCount
79+
</div>
80+
""",
81+
expected: """
82+
<div>
83+
<span>@currentCount</span>
84+
</div>
85+
""",
7686
htmlResponse: new VSInternalWrapWithTagResponse(
77-
LspFactory.CreateSingleLineRange(start: (0, 0), length: 10),
78-
[LspFactory.CreateTextEdit(position: (0, 0), "~~~<p>~~~~</p>~~~")]
79-
),
80-
expected: new VSInternalWrapWithTagResponse(
81-
LspFactory.CreateSingleLineRange(start: (0, 0), length: 10),
82-
[LspFactory.CreateTextEdit(position: (0, 0), "<p></p>")]
87+
LspFactory.CreateSingleLineRange(start: (1, 5), length: 13),
88+
[LspFactory.CreateTextEdit(1, 4, 1, 17, "<span>/*~~~~~~~~~*/</span>")]
8389
));
8490
}
8591

86-
private async Task VerifyWrapWithTagAsync(string input, VSInternalWrapWithTagResponse? htmlResponse, VSInternalWrapWithTagResponse? expected)
92+
private async Task VerifyWrapWithTagAsync(TestCode input, string? expected, VSInternalWrapWithTagResponse? htmlResponse)
8793
{
88-
TestFileMarkupParser.GetSpan(input, out input, out var span);
89-
var document = CreateProjectAndRazorDocument(input);
94+
var document = CreateProjectAndRazorDocument(input.Text);
9095
var sourceText = await document.GetTextAsync(DisposalToken);
9196

9297
var requestInvoker = new TestHtmlRequestInvoker([(LanguageServerConstants.RazorWrapWithTagEndpoint, htmlResponse)]);
9398

94-
var endpoint = new CohostWrapWithTagEndpoint(RemoteServiceInvoker, FilePathService, requestInvoker);
99+
var endpoint = new CohostWrapWithTagEndpoint(RemoteServiceInvoker, requestInvoker);
95100

96101
var request = new VSInternalWrapWithTagParams(
97-
sourceText.GetRange(span),
102+
sourceText.GetRange(input.Span),
98103
"div",
99104
new FormattingOptions(),
100105
new VersionedTextDocumentIdentifier()
@@ -111,8 +116,9 @@ private async Task VerifyWrapWithTagAsync(string input, VSInternalWrapWithTagRes
111116
else
112117
{
113118
Assert.NotNull(result);
114-
Assert.Equal(expected.TagRange, result.TagRange);
115-
Assert.Equal(expected.TextEdits, result.TextEdits);
119+
120+
var changedDoc = sourceText.WithChanges(result.TextEdits.Select(sourceText.GetTextChange));
121+
AssertEx.EqualOrDiff(expected, changedDoc.ToString());
116122
}
117123
}
118-
}
124+
}

0 commit comments

Comments
 (0)