1111
1212namespace Microsoft . CodeAnalysis . Razor . Completion ;
1313
14- public class DirectiveAttributeTransitionCompletionItemProviderTest : ToolingTestBase
14+ public class DirectiveAttributeTransitionCompletionItemProviderTest ( ITestOutputHelper testOutput ) : ToolingTestBase ( testOutput )
1515{
16- private readonly TagHelperDocumentContext _tagHelperDocumentContext ;
17- private readonly DirectiveAttributeTransitionCompletionItemProvider _provider ;
18-
19- public DirectiveAttributeTransitionCompletionItemProviderTest ( ITestOutputHelper testOutput )
20- : base ( testOutput )
21- {
22- _tagHelperDocumentContext = TagHelperDocumentContext . Create ( prefix : string . Empty , tagHelpers : [ ] ) ;
23- _provider = new DirectiveAttributeTransitionCompletionItemProvider ( TestLanguageServerFeatureOptions . Instance ) ;
24- }
16+ private readonly TagHelperDocumentContext _tagHelperDocumentContext = TagHelperDocumentContext . Create ( prefix : string . Empty , tagHelpers : [ ] ) ;
17+ private readonly DirectiveAttributeTransitionCompletionItemProvider _provider = new DirectiveAttributeTransitionCompletionItemProvider ( TestLanguageServerFeatureOptions . Instance ) ;
2518
2619 [ Fact ]
2720 public void IsValidCompletionPoint_AtPrefixLeadingEdge_ReturnsFalse ( )
@@ -129,7 +122,7 @@ public void IsValidCompletionPoint_OutsideOfNameAndPrefix_ReturnsFalse()
129122 public void GetCompletionItems_AttributeAreaInNonComponentFile_ReturnsEmptyList ( )
130123 {
131124 // Arrange
132- var context = CreateContext ( absoluteIndex : 7 , "<input />" , RazorFileKind . Legacy ) ;
125+ var context = CreateContext ( "<input $$ />" , RazorFileKind . Legacy ) ;
133126
134127 // Act
135128 var result = _provider . GetCompletionItems ( context ) ;
@@ -142,7 +135,7 @@ public void GetCompletionItems_AttributeAreaInNonComponentFile_ReturnsEmptyList(
142135 public void GetCompletionItems_NonAttribute_ReturnsEmptyList ( )
143136 {
144137 // Arrange
145- var context = CreateContext ( absoluteIndex : 2 , "<input />") ;
138+ var context = CreateContext ( "<i$$nput />") ;
146139
147140 // Act
148141 var result = _provider . GetCompletionItems ( context ) ;
@@ -155,7 +148,7 @@ public void GetCompletionItems_NonAttribute_ReturnsEmptyList()
155148 public void GetCompletionItems_ExistingAttribute_ReturnsEmptyList ( )
156149 {
157150 // Arrange
158- var context = CreateContext ( absoluteIndex : 8 , "<input @ />" ) ;
151+ var context = CreateContext ( "<input @$$ />" ) ;
159152
160153 // Act
161154 var result = _provider . GetCompletionItems ( context ) ;
@@ -168,8 +161,8 @@ public void GetCompletionItems_ExistingAttribute_ReturnsEmptyList()
168161 public void GetCompletionItems_InbetweenSelfClosingEnd_ReturnsEmptyList ( )
169162 {
170163 // Arrange
171- var context = CreateContext ( absoluteIndex : 8 , """
172- <input /
164+ var context = CreateContext ( """
165+ <input /$$
173166
174167 """ ) ;
175168
@@ -184,7 +177,7 @@ public void GetCompletionItems_InbetweenSelfClosingEnd_ReturnsEmptyList()
184177 public void GetCompletionItems_AttributeAreaInComponentFile_ReturnsTransitionCompletionItem ( )
185178 {
186179 // Arrange
187- var context = CreateContext ( absoluteIndex : 7 , "<input />" ) ;
180+ var context = CreateContext ( "<input $$ />" ) ;
188181
189182 // Act
190183 var result = _provider . GetCompletionItems ( context ) ;
@@ -198,7 +191,7 @@ public void GetCompletionItems_AttributeAreaInComponentFile_ReturnsTransitionCom
198191 public void GetCompletionItems_AttributeAreaEndOfSelfClosingTag_ReturnsTransitionCompletionItem ( )
199192 {
200193 // Arrange
201- var context = CreateContext ( absoluteIndex : 7 , "<input />" ) ;
194+ var context = CreateContext ( "<input $$ />" ) ;
202195
203196 // Act
204197 var result = _provider . GetCompletionItems ( context ) ;
@@ -212,7 +205,7 @@ public void GetCompletionItems_AttributeAreaEndOfSelfClosingTag_ReturnsTransitio
212205 public void GetCompletionItems_AttributeAreaEndOfOpeningTag_ReturnsTransitionCompletionItem ( )
213206 {
214207 // Arrange
215- var context = CreateContext ( absoluteIndex : 7 , "<input ></input>" ) ;
208+ var context = CreateContext ( "<input $$ ></input>" ) ;
216209
217210 // Act
218211 var result = _provider . GetCompletionItems ( context ) ;
@@ -226,7 +219,7 @@ public void GetCompletionItems_AttributeAreaEndOfOpeningTag_ReturnsTransitionCom
226219 public void GetCompletionItems_ExistingAttribute_LeadingEdge_ReturnsEmptyList ( )
227220 {
228221 // Arrange
229- var context = CreateContext ( absoluteIndex : 7 , "<input src=\" xyz\" />" ) ;
222+ var context = CreateContext ( "<input $$ src=\" xyz\" />" ) ;
230223
231224 // Act
232225 var result = _provider . GetCompletionItems ( context ) ;
@@ -239,7 +232,7 @@ public void GetCompletionItems_ExistingAttribute_LeadingEdge_ReturnsEmptyList()
239232 public void GetCompletionItems_ExistingAttribute_TrailingEdge_ReturnsEmptyList ( )
240233 {
241234 // Arrange
242- var context = CreateContext ( absoluteIndex : 16 , "<input src=\" xyz\" />" ) ;
235+ var context = CreateContext ( "<input src=\" xyz\" $$ />" ) ;
243236
244237 // Act
245238 var result = _provider . GetCompletionItems ( context ) ;
@@ -252,7 +245,7 @@ public void GetCompletionItems_ExistingAttribute_TrailingEdge_ReturnsEmptyList()
252245 public void GetCompletionItems_ExistingAttribute_TrailingEdgeOnSpace_ReturnsEmptyList ( )
253246 {
254247 // Arrange
255- var context = CreateContext ( absoluteIndex : 16 , "<input src=\" xyz\" />" ) ;
248+ var context = CreateContext ( "<input src=\" xyz\" $$ />" ) ;
256249
257250 // Act
258251 var result = _provider . GetCompletionItems ( context ) ;
@@ -265,7 +258,7 @@ public void GetCompletionItems_ExistingAttribute_TrailingEdgeOnSpace_ReturnsEmpt
265258 public void GetCompletionItems_ExistingAttribute_Partial_ReturnsEmptyList ( )
266259 {
267260 // Arrange
268- var context = CreateContext ( absoluteIndex : 9 , "<svg xml: ></svg>" ) ;
261+ var context = CreateContext ( "<svg xml:$$ ></svg>" ) ;
269262
270263 // Act
271264 var result = _provider . GetCompletionItems ( context ) ;
@@ -278,7 +271,7 @@ public void GetCompletionItems_ExistingAttribute_Partial_ReturnsEmptyList()
278271 public void GetCompletionItems_AttributeAreaInIncompleteAttributeTransition_ReturnsTransitionCompletionItem ( )
279272 {
280273 // Arrange
281- var context = CreateContext ( absoluteIndex : 7 , "<input @{" ) ;
274+ var context = CreateContext ( "<input $$ @{" ) ;
282275
283276 // Act
284277 var result = _provider . GetCompletionItems ( context ) ;
@@ -292,7 +285,7 @@ public void GetCompletionItems_AttributeAreaInIncompleteAttributeTransition_Retu
292285 public void GetCompletionItems_AttributeAreaInIncompleteComponent_ReturnsTransitionCompletionItem ( )
293286 {
294287 // Arrange
295- var context = CreateContext ( absoluteIndex : 5 , "<svg xml:base=\" d\" ></svg>" ) ;
288+ var context = CreateContext ( "<svg $$ xml:base=\" d\" ></svg>" ) ;
296289
297290 // Act
298291 var result = _provider . GetCompletionItems ( context ) ;
@@ -308,7 +301,7 @@ public void GetCompletionItems_AttributeAreaInIncompleteComponent_ReturnsTransit
308301 public void GetCompletionItems_WithAvoidExplicitCommitOption_ReturnsAppropriateCommitCharacters ( bool supportsSoftSelection )
309302 {
310303 // Arrange
311- var context = CreateContext ( absoluteIndex : 7 , "<input />" ) ;
304+ var context = CreateContext ( "<input $$ />" ) ;
312305 var provider = new DirectiveAttributeTransitionCompletionItemProvider ( new TestLanguageServerFeatureOptions ( supportsSoftSelectionInCompletion : supportsSoftSelection ) ) ;
313306
314307 // Act
@@ -327,11 +320,11 @@ public void GetCompletionItems_WithAvoidExplicitCommitOption_ReturnsAppropriateC
327320 }
328321 }
329322
330- private static RazorCodeDocument GetCodeDocument ( string text , RazorFileKind ? fileKind = null )
323+ private static RazorCodeDocument GetCodeDocument ( TestCode text , RazorFileKind ? fileKind = null )
331324 {
332325 var fileKindValue = fileKind ?? RazorFileKind . Component ;
333326
334- var sourceDocument = TestRazorSourceDocument . Create ( text ) ;
327+ var sourceDocument = TestRazorSourceDocument . Create ( text . Text ) ;
335328 var projectEngine = RazorProjectEngine . Create ( builder =>
336329 {
337330 builder . ConfigureParserOptions ( builder =>
@@ -343,9 +336,10 @@ private static RazorCodeDocument GetCodeDocument(string text, RazorFileKind? fil
343336 return projectEngine . Process ( sourceDocument , fileKindValue , importSources : default , tagHelpers : [ ] ) ;
344337 }
345338
346- private RazorCompletionContext CreateContext ( int absoluteIndex , string documentContent , RazorFileKind ? fileKind = null )
339+ private RazorCompletionContext CreateContext ( TestCode text , RazorFileKind ? fileKind = null )
347340 {
348- var codeDocument = GetCodeDocument ( documentContent , fileKind ) ;
341+ var absoluteIndex = text . Position ;
342+ var codeDocument = GetCodeDocument ( text . Text , fileKind ) ;
349343 var syntaxTree = codeDocument . GetRequiredSyntaxTree ( ) ;
350344 var owner = syntaxTree . Root . FindInnermostNode ( absoluteIndex , includeWhitespace : true , walkMarkersBack : true ) ;
351345 owner = AbstractRazorCompletionFactsService . AdjustSyntaxNodeForWordBoundary ( owner , absoluteIndex ) ;
0 commit comments