1313using Microsoft . CodeAnalysis . Razor . ProjectSystem ;
1414using Microsoft . CodeAnalysis . Text ;
1515using Xunit ;
16+ using static Microsoft . CodeAnalysis . Razor . RazorDocumentExcerptService ;
1617
1718namespace Microsoft . CodeAnalysis . Razor
1819{
@@ -33,7 +34,7 @@ protected override void ConfigureLanguageServices(List<ILanguageService> service
3334 }
3435
3536 [ Fact ]
36- public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp ( )
37+ public async Task TryGetExcerptInternalAsync_SingleLine_CanClassifyCSharp ( )
3738 {
3839 // Arrange
3940 var ( sourceText , primarySpan ) = CreateText (
@@ -53,13 +54,19 @@ public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp()
5354 var secondarySpan = await GetSecondarySpanAsync ( primary , primarySpan , secondary ) ;
5455
5556 // Act
56- var result = await service . TryExcerptAsync ( secondary , secondarySpan , ExcerptMode . SingleLine , CancellationToken . None ) ;
57+ var result = await service . TryGetExcerptInternalAsync ( secondary , secondarySpan , ExcerptModeInternal . SingleLine , CancellationToken . None ) ;
5758
5859 // Assert
5960 Assert . NotNull ( result ) ;
6061 Assert . Equal ( secondarySpan , result . Value . Span ) ;
6162 Assert . Same ( secondary , result . Value . Document ) ;
6263
64+ // Verifies that the right part of the primary document will be highlighted.
65+ Assert . Equal (
66+ ( await secondary . GetTextAsync ( ) ) . GetSubText ( secondarySpan ) . ToString ( ) ,
67+ result . Value . Content . GetSubText ( result . Value . MappedSpan ) . ToString ( ) ,
68+ ignoreLineEndingDifferences : true ) ;
69+
6370 Assert . Equal ( @" var foo = ""Hello, World!"";" , result . Value . Content . ToString ( ) , ignoreLineEndingDifferences : true ) ;
6471 Assert . Collection (
6572 result . Value . ClassifiedSpans ,
@@ -91,7 +98,7 @@ public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp()
9198 }
9299
93100 [ Fact ]
94- public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp_ImplicitExpression ( )
101+ public async Task TryGetExcerptInternalAsync_SingleLine_CanClassifyCSharp_ImplicitExpression ( )
95102 {
96103 // Arrange
97104 var ( sourceText , primarySpan ) = CreateText (
@@ -111,13 +118,19 @@ public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp_ImplicitExpressio
111118 var secondarySpan = await GetSecondarySpanAsync ( primary , primarySpan , secondary ) ;
112119
113120 // Act
114- var result = await service . TryExcerptAsync ( secondary , secondarySpan , ExcerptMode . SingleLine , CancellationToken . None ) ;
121+ var result = await service . TryGetExcerptInternalAsync ( secondary , secondarySpan , ExcerptModeInternal . SingleLine , CancellationToken . None ) ;
115122
116123 // Assert
117124 Assert . NotNull ( result ) ;
118125 Assert . Equal ( secondarySpan , result . Value . Span ) ;
119126 Assert . Same ( secondary , result . Value . Document ) ;
120127
128+ // Verifies that the right part of the primary document will be highlighted.
129+ Assert . Equal (
130+ ( await secondary . GetTextAsync ( ) ) . GetSubText ( secondarySpan ) . ToString ( ) ,
131+ result . Value . Content . GetSubText ( result . Value . MappedSpan ) . ToString ( ) ,
132+ ignoreLineEndingDifferences : true ) ;
133+
121134 Assert . Equal ( @" <body>@foo</body>" , result . Value . Content . ToString ( ) , ignoreLineEndingDifferences : true ) ;
122135 Assert . Collection (
123136 result . Value . ClassifiedSpans ,
@@ -139,7 +152,7 @@ public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp_ImplicitExpressio
139152 }
140153
141154 [ Fact ]
142- public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp_ComplexLine ( )
155+ public async Task TryGetExcerptInternalAsync_SingleLine_CanClassifyCSharp_ComplexLine ( )
143156 {
144157 // Arrange
145158 var ( sourceText , primarySpan ) = CreateText (
@@ -159,13 +172,19 @@ public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp_ComplexLine()
159172 var secondarySpan = await GetSecondarySpanAsync ( primary , primarySpan , secondary ) ;
160173
161174 // Act
162- var result = await service . TryExcerptAsync ( secondary , secondarySpan , ExcerptMode . SingleLine , CancellationToken . None ) ;
175+ var result = await service . TryGetExcerptInternalAsync ( secondary , secondarySpan , ExcerptModeInternal . SingleLine , CancellationToken . None ) ;
163176
164177 // Assert
165178 Assert . NotNull ( result ) ;
166179 Assert . Equal ( secondarySpan , result . Value . Span ) ;
167180 Assert . Same ( secondary , result . Value . Document ) ;
168181
182+ // Verifies that the right part of the primary document will be highlighted.
183+ Assert . Equal (
184+ ( await secondary . GetTextAsync ( ) ) . GetSubText ( secondarySpan ) . ToString ( ) ,
185+ result . Value . Content . GetSubText ( result . Value . MappedSpan ) . ToString ( ) ,
186+ ignoreLineEndingDifferences : true ) ;
187+
169188 Assert . Equal ( @" <div>@(3 + 4)</div><div>@(foo + foo)</div>" , result . Value . Content . ToString ( ) , ignoreLineEndingDifferences : true ) ;
170189 Assert . Collection (
171190 result . Value . ClassifiedSpans ,
@@ -217,7 +236,7 @@ public async Task TryExcerptAsync_SingleLine_CanClassifyCSharp_ComplexLine()
217236 }
218237
219238 [ Fact ]
220- public async Task TryExcerptAsync_MultiLine_CanClassifyCSharp ( )
239+ public async Task TryGetExcerptInternalAsync_MultiLine_CanClassifyCSharp ( )
221240 {
222241 // Arrange
223242 var ( sourceText , primarySpan ) = CreateText (
@@ -226,8 +245,8 @@ public async Task TryExcerptAsync_MultiLine_CanClassifyCSharp()
226245@{
227246 var |foo| = ""Hello, World!"";
228247}
229- <body>@foo </body>
230- <div>@(3 + 4)</div><div>@(foo + foo) </div>
248+ <body></body>
249+ <div></div>
231250</html>
232251" ) ;
233252
@@ -237,25 +256,40 @@ public async Task TryExcerptAsync_MultiLine_CanClassifyCSharp()
237256 var secondarySpan = await GetSecondarySpanAsync ( primary , primarySpan , secondary ) ;
238257
239258 // Act
240- var result = await service . TryExcerptAsync ( secondary , secondarySpan , ExcerptMode . Tooltip , CancellationToken . None ) ;
259+ var result = await service . TryGetExcerptInternalAsync ( secondary , secondarySpan , ExcerptModeInternal . Tooltip , CancellationToken . None ) ;
241260
242261 // Assert
243262 Assert . NotNull ( result ) ;
244263 Assert . Equal ( secondarySpan , result . Value . Span ) ;
245264 Assert . Same ( secondary , result . Value . Document ) ;
246265
266+ // Verifies that the right part of the primary document will be highlighted.
247267 Assert . Equal (
248- @"@{
268+ ( await secondary . GetTextAsync ( ) ) . GetSubText ( secondarySpan ) . ToString ( ) ,
269+ result . Value . Content . GetSubText ( result . Value . MappedSpan ) . ToString ( ) ,
270+ ignoreLineEndingDifferences : true ) ;
271+
272+ Assert . Equal (
273+ @"
274+ <html>
275+ @{
249276 var foo = ""Hello, World!"";
250- }" ,
277+ }
278+ <body></body>
279+ <div></div>" ,
251280 result . Value . Content . ToString ( ) , ignoreLineEndingDifferences : true ) ;
252281
253282 Assert . Collection (
254283 result . Value . ClassifiedSpans ,
255284 c =>
256285 {
257286 Assert . Equal ( ClassificationTypeNames . Text , c . ClassificationType ) ;
258- Assert . Equal ( "@{" , result . Value . Content . GetSubText ( c . TextSpan ) . ToString ( ) ) ;
287+ Assert . Equal (
288+ @"
289+ <html>
290+ @{" ,
291+ result . Value . Content . GetSubText ( c . TextSpan ) . ToString ( ) ,
292+ ignoreLineEndingDifferences : true ) ;
259293 } ,
260294 c =>
261295 {
@@ -285,12 +319,17 @@ public async Task TryExcerptAsync_MultiLine_CanClassifyCSharp()
285319 c =>
286320 {
287321 Assert . Equal ( ClassificationTypeNames . Text , c . ClassificationType ) ;
288- Assert . Equal ( "}" , result . Value . Content . GetSubText ( c . TextSpan ) . ToString ( ) ) ;
322+ Assert . Equal (
323+ @"}
324+ <body></body>
325+ <div></div>" ,
326+ result . Value . Content . GetSubText ( c . TextSpan ) . ToString ( ) ,
327+ ignoreLineEndingDifferences : true ) ;
289328 } ) ;
290329 }
291330
292331 [ Fact ]
293- public async Task TryExcerptAsync_MultiLine_Boundaries_CanClassifyCSharp ( )
332+ public async Task TryGetExcerptInternalAsync_MultiLine_Boundaries_CanClassifyCSharp ( )
294333 {
295334 // Arrange
296335 var ( sourceText , primarySpan ) = CreateText ( @"@{ var |foo| = ""Hello, World!""; }" ) ;
@@ -301,13 +340,19 @@ public async Task TryExcerptAsync_MultiLine_Boundaries_CanClassifyCSharp()
301340 var secondarySpan = await GetSecondarySpanAsync ( primary , primarySpan , secondary ) ;
302341
303342 // Act
304- var result = await service . TryExcerptAsync ( secondary , secondarySpan , ExcerptMode . Tooltip , CancellationToken . None ) ;
343+ var result = await service . TryGetExcerptInternalAsync ( secondary , secondarySpan , ExcerptModeInternal . Tooltip , CancellationToken . None ) ;
305344
306345 // Assert
307346 Assert . NotNull ( result ) ;
308347 Assert . Equal ( secondarySpan , result . Value . Span ) ;
309348 Assert . Same ( secondary , result . Value . Document ) ;
310349
350+ // Verifies that the right part of the primary document will be highlighted.
351+ Assert . Equal (
352+ ( await secondary . GetTextAsync ( ) ) . GetSubText ( secondarySpan ) . ToString ( ) ,
353+ result . Value . Content . GetSubText ( result . Value . MappedSpan ) . ToString ( ) ,
354+ ignoreLineEndingDifferences : true ) ;
355+
311356 Assert . Equal (
312357@"@{ var foo = ""Hello, World!""; }" ,
313358 result . Value . Content . ToString ( ) , ignoreLineEndingDifferences : true ) ;
0 commit comments