@@ -144,294 +144,6 @@ public class C
144144}" ) ;
145145 }
146146
147- [ Fact ]
148- public void TestReplaceWithTracking ( )
149- {
150- // ReplaceNode overload #1
151- TestReplaceWithTrackingCore ( ( SyntaxNode node , SyntaxNode newNode , SyntaxEditor editor ) =>
152- {
153- editor . ReplaceNode ( node , newNode ) ;
154- } ) ;
155-
156- // ReplaceNode overload #2
157- TestReplaceWithTrackingCore ( ( SyntaxNode node , SyntaxNode newNode , SyntaxEditor editor ) =>
158- {
159- editor . ReplaceNode ( node , computeReplacement : ( originalNode , generator ) => newNode ) ;
160- } ) ;
161-
162- // ReplaceNode overload #3
163- TestReplaceWithTrackingCore ( ( SyntaxNode node , SyntaxNode newNode , SyntaxEditor editor ) =>
164- {
165- editor . ReplaceNode ( node ,
166- computeReplacement : ( originalNode , generator , argument ) => newNode ,
167- argument : ( object ) null ) ;
168- } ) ;
169- }
170-
171- private void TestReplaceWithTrackingCore ( Action < SyntaxNode , SyntaxNode , SyntaxEditor > replaceNodeWithTracking )
172- {
173- var code = @"
174- public class C
175- {
176- public int X;
177- }" ;
178-
179- var cu = SyntaxFactory . ParseCompilationUnit ( code ) ;
180- var cls = cu . Members [ 0 ] ;
181-
182- var editor = GetEditor ( cu ) ;
183- var fieldX = editor . Generator . GetMembers ( cls ) [ 0 ] ;
184- var newFieldY = editor . Generator . FieldDeclaration ( "Y" , editor . Generator . TypeExpression ( SpecialType . System_String ) , Accessibility . Public ) ;
185- replaceNodeWithTracking ( fieldX , newFieldY , editor ) ;
186-
187- var newRoot = editor . GetChangedRoot ( ) ;
188- VerifySyntax < CompilationUnitSyntax > (
189- newRoot ,
190- @"
191- public class C
192- {
193- public string Y;
194- }" ) ;
195- var newFieldYType = newFieldY . DescendantNodes ( ) . Single ( n => n . ToString ( ) == "string" ) ;
196- var newType = editor . Generator . TypeExpression ( SpecialType . System_Char ) ;
197- replaceNodeWithTracking ( newFieldYType , newType , editor ) ;
198-
199- newRoot = editor . GetChangedRoot ( ) ;
200- VerifySyntax < CompilationUnitSyntax > (
201- newRoot ,
202- @"
203- public class C
204- {
205- public char Y;
206- }" ) ;
207-
208- editor . RemoveNode ( newFieldY ) ;
209-
210- newRoot = editor . GetChangedRoot ( ) ;
211- VerifySyntax < CompilationUnitSyntax > (
212- newRoot ,
213- @"
214- public class C
215- {
216- }" ) ;
217- }
218-
219- [ Fact ]
220- public void TestReplaceWithTracking_02 ( )
221- {
222- var code = @"
223- public class C
224- {
225- public int X;
226- public string X2;
227- public char X3;
228- }" ;
229-
230- var cu = SyntaxFactory . ParseCompilationUnit ( code ) ;
231-
232- var editor = GetEditor ( cu ) ;
233-
234- var cls = cu . Members [ 0 ] ;
235- var fieldX = editor . Generator . GetMembers ( cls ) [ 0 ] ;
236- var fieldX2 = editor . Generator . GetMembers ( cls ) [ 1 ] ;
237- var fieldX3 = editor . Generator . GetMembers ( cls ) [ 2 ] ;
238-
239- var newFieldY = editor . Generator . FieldDeclaration ( "Y" , editor . Generator . TypeExpression ( SpecialType . System_String ) , Accessibility . Public ) ;
240- editor . ReplaceNode ( fieldX , newFieldY ) ;
241-
242- var newRoot = editor . GetChangedRoot ( ) ;
243- VerifySyntax < CompilationUnitSyntax > (
244- newRoot ,
245- @"
246- public class C
247- {
248- public string Y;
249- public string X2;
250- public char X3;
251- }" ) ;
252- var newFieldYType = newFieldY . DescendantNodes ( ) . Single ( n => n . ToString ( ) == "string" ) ;
253- var newType = editor . Generator . TypeExpression ( SpecialType . System_Char ) ;
254- editor . ReplaceNode ( newFieldYType , newType ) ;
255-
256- newRoot = editor . GetChangedRoot ( ) ;
257- VerifySyntax < CompilationUnitSyntax > (
258- newRoot ,
259- @"
260- public class C
261- {
262- public char Y;
263- public string X2;
264- public char X3;
265- }" ) ;
266-
267- var newFieldY2 = editor . Generator . FieldDeclaration ( "Y2" , editor . Generator . TypeExpression ( SpecialType . System_Boolean ) , Accessibility . Private ) ;
268- editor . ReplaceNode ( fieldX2 , newFieldY2 ) ;
269-
270- newRoot = editor . GetChangedRoot ( ) ;
271- VerifySyntax < CompilationUnitSyntax > (
272- newRoot ,
273- @"
274- public class C
275- {
276- public char Y;
277- private bool Y2;
278- public char X3;
279- }" ) ;
280-
281- var newFieldZ = editor . Generator . FieldDeclaration ( "Z" , editor . Generator . TypeExpression ( SpecialType . System_Boolean ) , Accessibility . Public ) ;
282- editor . ReplaceNode ( newFieldY , newFieldZ ) ;
283-
284- newRoot = editor . GetChangedRoot ( ) ;
285- VerifySyntax < CompilationUnitSyntax > (
286- newRoot ,
287- @"
288- public class C
289- {
290- public bool Z;
291- private bool Y2;
292- public char X3;
293- }" ) ;
294-
295- var originalFieldX3Type = fieldX3 . DescendantNodes ( ) . Single ( n => n . ToString ( ) == "char" ) ;
296- newType = editor . Generator . TypeExpression ( SpecialType . System_Boolean ) ;
297- editor . ReplaceNode ( originalFieldX3Type , newType ) ;
298-
299- newRoot = editor . GetChangedRoot ( ) ;
300- VerifySyntax < CompilationUnitSyntax > (
301- newRoot ,
302- @"
303- public class C
304- {
305- public bool Z;
306- private bool Y2;
307- public bool X3;
308- }" ) ;
309-
310- editor . RemoveNode ( newFieldY2 ) ;
311- editor . RemoveNode ( fieldX3 ) ;
312-
313- newRoot = editor . GetChangedRoot ( ) ;
314- VerifySyntax < CompilationUnitSyntax > (
315- newRoot ,
316- @"
317- public class C
318- {
319- public bool Z;
320- }" ) ;
321- }
322-
323- [ Fact ]
324- public void TestInsertAfterWithTracking ( )
325- {
326- // InsertAfter overload #1
327- TestInsertAfterWithTrackingCore ( ( SyntaxNode node , SyntaxNode newNode , SyntaxEditor editor ) =>
328- {
329- editor . InsertAfter ( node , newNode ) ;
330- } ) ;
331-
332- // InsertAfter overload #2
333- TestInsertAfterWithTrackingCore ( ( SyntaxNode node , SyntaxNode newNode , SyntaxEditor editor ) =>
334- {
335- editor . InsertAfter ( node , new [ ] { newNode } ) ;
336- } ) ;
337- }
338-
339- private void TestInsertAfterWithTrackingCore ( Action < SyntaxNode , SyntaxNode , SyntaxEditor > insertAfterWithTracking )
340- {
341- var code = @"
342- public class C
343- {
344- public int X;
345- }" ;
346-
347- var cu = SyntaxFactory . ParseCompilationUnit ( code ) ;
348- var cls = cu . Members [ 0 ] ;
349-
350- var editor = GetEditor ( cu ) ;
351- var fieldX = editor . Generator . GetMembers ( cls ) [ 0 ] ;
352- var newFieldY = editor . Generator . FieldDeclaration ( "Y" , editor . Generator . TypeExpression ( SpecialType . System_String ) , Accessibility . Public ) ;
353- insertAfterWithTracking ( fieldX , newFieldY , editor ) ;
354-
355- var newRoot = editor . GetChangedRoot ( ) ;
356- VerifySyntax < CompilationUnitSyntax > (
357- newRoot ,
358- @"
359- public class C
360- {
361- public int X;
362- public string Y;
363- }" ) ;
364-
365- var newFieldZ = editor . Generator . FieldDeclaration ( "Z" , editor . Generator . TypeExpression ( SpecialType . System_String ) , Accessibility . Public ) ;
366- editor . ReplaceNode ( newFieldY , newFieldZ ) ;
367-
368- newRoot = editor . GetChangedRoot ( ) ;
369- VerifySyntax < CompilationUnitSyntax > (
370- newRoot ,
371- @"
372- public class C
373- {
374- public int X;
375- public string Z;
376- }" ) ;
377- }
378-
379- [ Fact ]
380- public void TestInsertBeforeWithTracking ( )
381- {
382- // InsertBefore overload #1
383- TestInsertBeforeWithTrackingCore ( ( SyntaxNode node , SyntaxNode newNode , SyntaxEditor editor ) =>
384- {
385- editor . InsertBefore ( node , newNode ) ;
386- } ) ;
387-
388- // InsertBefore overload #2
389- TestInsertBeforeWithTrackingCore ( ( SyntaxNode node , SyntaxNode newNode , SyntaxEditor editor ) =>
390- {
391- editor . InsertBefore ( node , new [ ] { newNode } ) ;
392- } ) ;
393- }
394-
395- private void TestInsertBeforeWithTrackingCore ( Action < SyntaxNode , SyntaxNode , SyntaxEditor > insertBeforeWithTracking )
396- {
397- var code = @"
398- public class C
399- {
400- public int X;
401- }" ;
402-
403- var cu = SyntaxFactory . ParseCompilationUnit ( code ) ;
404- var cls = cu . Members [ 0 ] ;
405-
406- var editor = GetEditor ( cu ) ;
407- var fieldX = editor . Generator . GetMembers ( cls ) [ 0 ] ;
408- var newFieldY = editor . Generator . FieldDeclaration ( "Y" , editor . Generator . TypeExpression ( SpecialType . System_String ) , Accessibility . Public ) ;
409- insertBeforeWithTracking ( fieldX , newFieldY , editor ) ;
410-
411- var newRoot = editor . GetChangedRoot ( ) ;
412- VerifySyntax < CompilationUnitSyntax > (
413- newRoot ,
414- @"
415- public class C
416- {
417- public string Y;
418- public int X;
419- }" ) ;
420-
421- var newFieldZ = editor . Generator . FieldDeclaration ( "Z" , editor . Generator . TypeExpression ( SpecialType . System_String ) , Accessibility . Public ) ;
422- editor . ReplaceNode ( newFieldY , newFieldZ ) ;
423-
424- newRoot = editor . GetChangedRoot ( ) ;
425- VerifySyntax < CompilationUnitSyntax > (
426- newRoot ,
427- @"
428- public class C
429- {
430- public string Z;
431- public int X;
432- }" ) ;
433- }
434-
435147 [ Fact ]
436148 public void TestTrackNode ( )
437149 {
0 commit comments