1
- // Licensed to the .NET Foundation under one or more agreements.
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System ;
5
+ using System . Linq ;
5
6
using System . Threading . Tasks ;
7
+ using Microsoft . AspNetCore . Razor . Test . Common ;
8
+ using Microsoft . CodeAnalysis . ExternalAccess . Razor ;
6
9
using Microsoft . CodeAnalysis . Razor . Protocol ;
7
- using Microsoft . CodeAnalysis . Testing ;
8
10
using Microsoft . VisualStudio . Razor . LanguageClient . WrapWithTag ;
11
+ using Roslyn . Test . Utilities ;
9
12
using Xunit ;
10
13
using Xunit . Abstractions ;
11
14
@@ -22,13 +25,14 @@ await VerifyWrapWithTagAsync(
22
25
[||]
23
26
</div>
24
27
""" ,
28
+ expected : """
29
+ <div>
30
+ <p></p>
31
+ </div>
32
+ """ ,
25
33
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>" ) ]
32
36
) ) ;
33
37
}
34
38
@@ -54,13 +58,14 @@ await VerifyWrapWithTagAsync(
54
58
@[||]currentCount
55
59
</div>
56
60
""" ,
61
+ expected : """
62
+ <div>
63
+ <span>@currentCount</span>
64
+ </div>
65
+ """ ,
57
66
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>" ) ]
64
69
) ) ;
65
70
}
66
71
@@ -69,32 +74,32 @@ public async Task HtmlWithTildes_FixesTextEdits()
69
74
{
70
75
await VerifyWrapWithTagAsync (
71
76
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
+ """ ,
76
86
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>" ) ]
83
89
) ) ;
84
90
}
85
91
86
- private async Task VerifyWrapWithTagAsync ( string input , VSInternalWrapWithTagResponse ? htmlResponse , VSInternalWrapWithTagResponse ? expected )
92
+ private async Task VerifyWrapWithTagAsync ( TestCode input , string ? expected , VSInternalWrapWithTagResponse ? htmlResponse )
87
93
{
88
- TestFileMarkupParser . GetSpan ( input , out input , out var span ) ;
89
- var document = CreateProjectAndRazorDocument ( input ) ;
94
+ var document = CreateProjectAndRazorDocument ( input . Text ) ;
90
95
var sourceText = await document . GetTextAsync ( DisposalToken ) ;
91
96
92
97
var requestInvoker = new TestHtmlRequestInvoker ( [ ( LanguageServerConstants . RazorWrapWithTagEndpoint , htmlResponse ) ] ) ;
93
98
94
- var endpoint = new CohostWrapWithTagEndpoint ( RemoteServiceInvoker , FilePathService , requestInvoker ) ;
99
+ var endpoint = new CohostWrapWithTagEndpoint ( RemoteServiceInvoker , requestInvoker ) ;
95
100
96
101
var request = new VSInternalWrapWithTagParams (
97
- sourceText . GetRange ( span ) ,
102
+ sourceText . GetRange ( input . Span ) ,
98
103
"div" ,
99
104
new FormattingOptions ( ) ,
100
105
new VersionedTextDocumentIdentifier ( )
@@ -111,8 +116,9 @@ private async Task VerifyWrapWithTagAsync(string input, VSInternalWrapWithTagRes
111
116
else
112
117
{
113
118
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 ( ) ) ;
116
122
}
117
123
}
118
- }
124
+ }
0 commit comments