~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ConvertToInitializer/ConvertToInitializerTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ConvertToInitializerTests.cs
 
3
//
 
4
// Author:
 
5
//       Simon Lindgren <simon.n.lindgren@gmail.com>
 
6
//
 
7
// Copyright (c) 2012 Simon Lindgren
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
using NUnit.Framework;
 
27
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
28
using ICSharpCode.NRefactory.PatternMatching;
 
29
using System;
 
30
 
 
31
namespace ICSharpCode.NRefactory.CSharp.CodeActions
 
32
{
 
33
        [TestFixture]
 
34
        public class ConvertToInitializerTests : ContextActionTestBase
 
35
        {
 
36
                // TODO: Remove this when the formatter handles object and collection initializers
 
37
                // This tests the expected code vs the actual code based on their ASTs instead of the text they produce.
 
38
                public new void Test<T>(string input, string output, int action = 0, bool expectErrors = false)
 
39
                        where T : ICodeActionProvider, new ()
 
40
                {
 
41
                        string result = RunContextAction(new T(), HomogenizeEol(input), action, expectErrors);
 
42
 
 
43
                        var expectedContext = TestRefactoringContext.Create(output, expectErrors);
 
44
                        var actualContext = TestRefactoringContext.Create(result, expectErrors);
 
45
 
 
46
                        bool passed = expectedContext.RootNode.IsMatch(actualContext.RootNode);
 
47
                        if (!passed) {
 
48
                                Console.WriteLine("-----------Expected:");
 
49
                                Console.WriteLine(output);
 
50
                                Console.WriteLine("-----------Got:");
 
51
                                Console.WriteLine(result);
 
52
                        }
 
53
                        Assert.IsTrue(passed, "The generated code and the expected code was not syntactically identical. See output for details.");
 
54
                }
 
55
 
 
56
                string baseText = @"
 
57
class TestClass
 
58
{
 
59
        public string Property { get; set; }
 
60
 
 
61
        public TestClass Nested { get; set; }
 
62
 
 
63
        void F ()
 
64
        {
 
65
                ";
 
66
                
 
67
                [Test]
 
68
                public void SimpleObject()
 
69
                {
 
70
                        Test<ConvertToInitializerAction>(baseText + @"
 
71
                var variable = new Test$Class ();
 
72
                variable.Property = ""Value"";
 
73
        }
 
74
}", baseText + @"
 
75
                var variable = new TestClass () {
 
76
                        Property = ""Value""
 
77
                };
 
78
        }
 
79
}");
 
80
                }
 
81
                
 
82
                [Test]
 
83
                public void SimpleCollection()
 
84
                {
 
85
                        Test<ConvertToInitializerAction>(baseText + @"
 
86
                var collection = new System.Collections.Generic.List$<string> ();
 
87
                collection.Add(""string1"");
 
88
                collection.Add(""string2"");
 
89
        }
 
90
}", baseText + @"
 
91
                var collection = new System.Collections.Generic.List<string> () {
 
92
                        ""string1"",
 
93
                        ""string2""
 
94
                };
 
95
        }
 
96
}");
 
97
                }
 
98
                
 
99
                [Test]
 
100
                public void MultiElementCollection()
 
101
                {
 
102
                        Test<ConvertToInitializerAction>(baseText + @"
 
103
                var tc0 = new TestClass();
 
104
                var collection = new System.Collections.Generic.Dictionary$<string, TestClass> ();
 
105
                var tc1 = new TestClass();
 
106
                tc1.Property = ""tc1"";
 
107
                collection.Add(""string1"", tc1);
 
108
                var tc2 = new TestClass();
 
109
                tc2.Property = ""tc2"";
 
110
                collection.Add(""string2"", tc2);
 
111
                collection.Add(""string0"", tc0);
 
112
        }
 
113
}", baseText + @"
 
114
                var tc0 = new TestClass();
 
115
                var collection = new System.Collections.Generic.Dictionary<string, TestClass> () {
 
116
                        {""string1"", new TestClass() { Property = ""tc1"" }},
 
117
                        {""string2"", new TestClass() { Property = ""tc2"" }}
 
118
                };
 
119
                collection.Add(""string0"", tc0);
 
120
        }
 
121
}");
 
122
                }
 
123
                
 
124
                [Test]
 
125
                public void CollectionOfObjects()
 
126
                {
 
127
                        Test<ConvertToInitializerAction>(baseText + @"
 
128
                var collection = new System.Collections.Generic.List$<string> ();
 
129
                var item = new TestClass ();
 
130
                item.Property = ""Value1"";
 
131
                collection.Add(item);
 
132
                item = new TestClass ();
 
133
                item.Property = ""Value2"";
 
134
                item.Nested = new TestClass ();
 
135
                item.Nested.Property = ""Value3"";
 
136
                collection.Add(item);
 
137
        }
 
138
}", baseText + @"
 
139
                var collection = new System.Collections.Generic.List<string> () {
 
140
                        new TestClass () {
 
141
                                Property = ""Value1""
 
142
                        },
 
143
                        new TestClass () {
 
144
                                Property = ""Value2"",
 
145
                                Nested = new TestClass () {
 
146
                                        Property = ""Value3""
 
147
                                }
 
148
                        }
 
149
                };
 
150
        }
 
151
}");
 
152
                }
 
153
                
 
154
                [Test]
 
155
                public void UnknownTargetForAdd()
 
156
                {
 
157
                        Test<ConvertToInitializerAction>(baseText + @"
 
158
                var collection = new System.Collections.Generic.List<string> ();
 
159
                var item $= new TestClass ();
 
160
                item.Property = ""Value1"";
 
161
                collection.Add(item);
 
162
        }
 
163
}", baseText + @"
 
164
                var collection = new System.Collections.Generic.List<string> ();
 
165
                var item = new TestClass () {
 
166
                        Property = ""Value1""
 
167
                };
 
168
                collection.Add(item);
 
169
        }
 
170
}");
 
171
                }
 
172
 
 
173
                [Test]
 
174
                public void ObjectContainingCollections()
 
175
                {
 
176
                        Test<ConvertToInitializerAction>(baseText + @"
 
177
                var variable = new Test$Class ();
 
178
                variable.Property = ""Value1"";
 
179
                var collection = new System.Collections.Generic.List<TestClass>();
 
180
                collection.Add (new TestClass());
 
181
                collection.Add (new TestClass());
 
182
                collection.Add (new TestClass());
 
183
                variable.Children = collection;
 
184
        }
 
185
        
 
186
        public System.Collections.Generic.IList<TestClass> Children;
 
187
}", baseText + @"
 
188
                var variable = new TestClass () {
 
189
                        Property = ""Value1"",
 
190
                        Children = new System.Collections.Generic.List<TestClass> () {
 
191
                                new TestClass (),
 
192
                                new TestClass (),
 
193
                                new TestClass ()
 
194
                        }
 
195
                };
 
196
        }
 
197
        
 
198
        public System.Collections.Generic.IList<TestClass> Children;
 
199
}");
 
200
                }
 
201
 
 
202
                [Test]
 
203
                public void SplitAssignmentAndInitialization()
 
204
                {
 
205
                        Test<ConvertToInitializerAction>(baseText + @"
 
206
                TestClass variable;
 
207
                variable = new Test$Class ();
 
208
                variable.Property = ""Value"";
 
209
        }
 
210
}", baseText + @"
 
211
                TestClass variable;
 
212
                variable = new TestClass () {
 
213
                        Property = ""Value""
 
214
                };
 
215
        }
 
216
}");
 
217
                }
 
218
                
 
219
                [Test]
 
220
                public void MemberAssignment()
 
221
                {
 
222
                        Test<ConvertToInitializerAction>(baseText + @"
 
223
                Nested = new Test$Class ();
 
224
                Nested.Property = ""Value"";
 
225
        }
 
226
}", baseText + @"
 
227
                Nested = new TestClass () {
 
228
                        Property = ""Value""
 
229
                };
 
230
        }
 
231
}");
 
232
                }
 
233
                
 
234
                [Test]
 
235
                public void MultipleMemberAssignments()
 
236
                {
 
237
                        Test<ConvertToInitializerAction>(baseText + @"
 
238
                Nested = new Test$Class ();
 
239
                Nested = new TestClass ();
 
240
                Nested.Property = ""Value"";
 
241
        }
 
242
}", baseText + @"
 
243
                Nested = new TestClass () {
 
244
                        Property = ""Value""
 
245
                };
 
246
        }
 
247
}");
 
248
                }
 
249
 
 
250
                [Test]
 
251
                public void NonCreatingInitialization()
 
252
                {
 
253
                        Test<ConvertToInitializerAction>(baseText + @"
 
254
                var variable = new Test$Class ();
 
255
                variable.Nested.Nested.Property = ""Value"";
 
256
        }
 
257
}", baseText + @"
 
258
                var variable = new TestClass () {
 
259
                        Nested = {
 
260
                                Nested = {
 
261
                                        Property = ""Value""
 
262
                                }
 
263
                        }
 
264
                };
 
265
        }
 
266
}");
 
267
                }
 
268
 
 
269
                [Test]
 
270
                public void IgnoresLinesPreceedingInitialization()
 
271
                {
 
272
                        Test<ConvertToInitializerAction>(baseText + @"
 
273
                System.Console.WriteLine(""One"");
 
274
                for(;;) {
 
275
                        System.Console.WriteLine(""Two"");
 
276
                }
 
277
                System.Console.WriteLine(""Three"");
 
278
                TestClass variable = new Test$Class ();
 
279
                variable.Property = ""Value"";
 
280
        }
 
281
}", baseText + @"
 
282
                System.Console.WriteLine(""One"");
 
283
                for(;;) {
 
284
                        System.Console.WriteLine(""Two"");
 
285
                }
 
286
                System.Console.WriteLine(""Three"");
 
287
                TestClass variable = new TestClass () {
 
288
                        Property = ""Value""
 
289
                };
 
290
        }
 
291
}");
 
292
                }
 
293
 
 
294
                [Test]
 
295
                public void NestedObject()
 
296
                {
 
297
                        Test<ConvertToInitializerAction>(baseText + @"
 
298
                var variable = new Test$Class ();
 
299
                variable.Property = ""Value"";
 
300
                variable.Nested = new TestClass();
 
301
                variable.Nested.Property = ""NestedValue"";
 
302
                variable.Nested.Nested = new TestClass();
 
303
                variable.Nested.Nested.Property = ""NestedNestedValue"";
 
304
        }
 
305
}", baseText + @"
 
306
                var variable = new TestClass () {
 
307
                        Property = ""Value"",
 
308
                        Nested = new TestClass () {
 
309
                                Property = ""NestedValue"",
 
310
                                Nested = new TestClass () {
 
311
                                        Property = ""NestedNestedValue""
 
312
                                }
 
313
                        }
 
314
                };
 
315
        }
 
316
}");
 
317
                }
 
318
 
 
319
                [Test]
 
320
                public void NestedObjectWithSkippedLevel()
 
321
                {
 
322
                        Test<ConvertToInitializerAction>(baseText + @"
 
323
                var variable = new Test$Class ();
 
324
                variable.Property = ""Value"";
 
325
                variable.Nested.Nested = new TestClass();
 
326
                variable.Nested.Nested.Property = ""NestedNestedValue"";
 
327
        }
 
328
}", baseText + @"
 
329
                var variable = new TestClass () {
 
330
                        Property = ""Value"",
 
331
                        Nested = {
 
332
                                Nested = new TestClass () {
 
333
                                        Property = ""NestedNestedValue""
 
334
                                }
 
335
                        }
 
336
                };
 
337
        }
 
338
}");
 
339
                }
 
340
 
 
341
                [Test]
 
342
                public void KeepsOriginalInitializer()
 
343
                {
 
344
                        Test<ConvertToInitializerAction>(baseText + @"
 
345
                var variable = new Test$Class () {
 
346
                        Property = ""Value""
 
347
                };
 
348
                variable.Nested = new TestClass();
 
349
        }
 
350
}", baseText + @"
 
351
                var variable = new TestClass () {
 
352
                        Property = ""Value"",
 
353
                        Nested = new TestClass ()
 
354
                };
 
355
        }
 
356
}");
 
357
                }
 
358
 
 
359
                [Test]
 
360
                [Ignore("The pattern matching comparison does not find differences in comments. UnIgnore this when the regular test method is used again.")]
 
361
                public void MovesComments()
 
362
                {
 
363
                        Test<ConvertToInitializerAction>(baseText + @"
 
364
                var variable = new Test$Class () {
 
365
                        Property = ""Value""
 
366
                };
 
367
                // This comment should be placed above the initializer corresponding to the statement below
 
368
                // This line should too.
 
369
                variable.Nested = new TestClass();
 
370
        }
 
371
}", baseText + @"
 
372
                var variable = new TestClass () {
 
373
                        Property = ""Value"",
 
374
                        // This comment should be placed above the initializer corresponding to the statement below
 
375
                        // This line should too.
 
376
                        Nested = new TestClass ()
 
377
                };
 
378
        }
 
379
}");
 
380
                }
 
381
 
 
382
                [Test]
 
383
                public void StopsAtArbitraryStatement()
 
384
                {
 
385
                        Test<ConvertToInitializerAction>(baseText + @"
 
386
                var variable = new Test$Class ();
 
387
                variable.Property = ""Value"";
 
388
                variable.Nested = new TestClass();
 
389
                System.Console.WriteLine("""");
 
390
                variable.Nested.Property = ""NestedValue"";
 
391
        }
 
392
}", baseText + @"
 
393
                var variable = new TestClass () {
 
394
                        Property = ""Value"",
 
395
                        Nested = new TestClass ()
 
396
                };
 
397
                System.Console.WriteLine("""");
 
398
                variable.Nested.Property = ""NestedValue"";
 
399
        }
 
400
}");
 
401
                }
 
402
 
 
403
                [Test]
 
404
                public void StopsAtVariableDependentStatement()
 
405
                {
 
406
                        Test<ConvertToInitializerAction>(baseText + @"
 
407
                var variable = new Test$Class ();
 
408
                variable.Property = ""Value"";
 
409
                variable.Nested = new TestClass();
 
410
                variable.Nested.Property = variable.ToString();
 
411
        }
 
412
}", baseText + @"
 
413
                var variable = new TestClass () {
 
414
                        Property = ""Value"",
 
415
                        Nested = new TestClass ()
 
416
                };
 
417
                variable.Nested.Property = variable.ToString();
 
418
        }
 
419
}");
 
420
                }
 
421
 
 
422
                [Test]
 
423
                public void StopsAtVariableDependentCreationStatement()
 
424
                {
 
425
                        Test<ConvertToInitializerAction>(baseText + @"
 
426
                var variable = new Test$Class ();
 
427
                variable.Property = ""Value"";
 
428
                var nested = new TestClass(variable);
 
429
                variable.Nested = nested;
 
430
        }
 
431
}", baseText + @"
 
432
                var variable = new TestClass () {
 
433
                        Property = ""Value""
 
434
                };
 
435
                var nested = new TestClass(variable);
 
436
                variable.Nested = nested;
 
437
        }
 
438
}");
 
439
                }
 
440
 
 
441
                [Test]
 
442
                public void HandlesIrrelevantAccessesAtTheEnd()
 
443
                {
 
444
                        Test<ConvertToInitializerAction>(baseText + @"
 
445
                var tc = new TestClass();
 
446
                tc.Property = ""1"";
 
447
                var tc$2 = new TestClass();
 
448
                tc2.Property = ""2"";
 
449
                tc2.Nested = new TestClass();
 
450
                tc2.Nested.Property = ""3"";
 
451
                tc.Nested = tc2;
 
452
        }
 
453
}", baseText + @"
 
454
                var tc = new TestClass();
 
455
                tc.Property = ""1"";
 
456
                var tc2 = new TestClass () {
 
457
                        Property = ""2"",
 
458
                        Nested = new TestClass () {
 
459
                                Property = ""3""
 
460
                        }
 
461
                };
 
462
                tc.Nested = tc2;
 
463
        }
 
464
}");
 
465
                }
 
466
                
 
467
                [Test]
 
468
                public void HandlesAssignmentWhereRightExpressionIsNotVisited()
 
469
                {
 
470
                        Test<ConvertToInitializerAction>(baseText + @"
 
471
                var tc = new TestClass();
 
472
                tc.Property = ""1"";
 
473
                var tc$2 = new TestClass();
 
474
                tc2.Property = ""2"";
 
475
                tc2.Nested = tc;
 
476
                tc.Nested = tc2;
 
477
        }
 
478
}", baseText + @"
 
479
                var tc = new TestClass();
 
480
                tc.Property = ""1"";
 
481
                var tc2 = new TestClass () {
 
482
                        Property = ""2"",
 
483
                        Nested = tc
 
484
                };
 
485
                tc.Nested = tc2;
 
486
        }
 
487
}");
 
488
                }
 
489
 
 
490
                [Test]
 
491
                public void HandlesAssignmentToExistingVariable()
 
492
                {
 
493
                        Test<ConvertToInitializerAction>(baseText + @"
 
494
                var variable = new Test$Class ();
 
495
                variable.Property = ""Value"";
 
496
                variable = new TestClass();
 
497
                variable.Nested = new TestClass();
 
498
        }
 
499
}", baseText + @"
 
500
                var variable = new TestClass () {
 
501
                        Nested = new TestClass ()
 
502
                };
 
503
        }
 
504
}");
 
505
                }
 
506
                
 
507
                [Test]
 
508
                public void HandlesAssignmentToFinalVariable()
 
509
                {
 
510
                        Test<ConvertToInitializerAction>(baseText + @"
 
511
                var _variable = new Test$Class ();
 
512
                _variable.Property = ""Value"";
 
513
                var variable = _variable;
 
514
        }
 
515
}", baseText + @"
 
516
                var variable = new TestClass () {
 
517
                        Property = ""Value""
 
518
                };
 
519
        }
 
520
}");
 
521
                }
 
522
                
 
523
                [Test]
 
524
                public void FinalVariableAssignmentOfOtherInitializer()
 
525
                {
 
526
                        Test<ConvertToInitializerAction>(baseText + @"
 
527
                var tc $= new TestClass ();
 
528
                tc.Property = ""Value"";
 
529
                var _variable = new TestClass ();
 
530
                var variable = _variable;
 
531
        }
 
532
}", baseText + @"
 
533
                var tc = new TestClass () {
 
534
                        Property = ""Value""
 
535
                };
 
536
                var _variable = new TestClass ();
 
537
                var variable = _variable;
 
538
        }
 
539
}");
 
540
                }
 
541
 
 
542
                [Test]
 
543
                public void StopsAtMemberDependentStatement()
 
544
                {
 
545
                        Test<ConvertToInitializerAction>(baseText + @"
 
546
                Nested = new Test$Class ();
 
547
                Nested.Nested = new TestClass();
 
548
                Nested.Property = ""Value"";
 
549
                Nested.Nested.Property = Nested.Property;
 
550
                Nested.Nested.Nested = new TestClass();
 
551
        }
 
552
}", baseText + @"
 
553
                Nested = new TestClass () {
 
554
                        Nested = new TestClass (),
 
555
                        Property = ""Value""
 
556
                };
 
557
                Nested.Nested.Property = Nested.Property;
 
558
                Nested.Nested.Nested = new TestClass();
 
559
        }
 
560
}");
 
561
                }
 
562
 
 
563
                [Test]
 
564
                public void KeepsStatementsWhichAreNotAdded()
 
565
                {
 
566
                        Test<ConvertToInitializerAction>(baseText + @"
 
567
                var collection = new System.Collections.Generic.List$<string> ();
 
568
                var item = new TestClass ();
 
569
                item.Property = ""Value1"";
 
570
                collection.Add(item);
 
571
                item = new TestClass ();
 
572
                item.Property = ""Value2"";
 
573
                item.Nested = new TestClass ();
 
574
                item.Nested.Property = ""Value3"";
 
575
                collection.Add(item);
 
576
                // This should stay here
 
577
                item = new TestClass();
 
578
        }
 
579
}", baseText + @"
 
580
                var collection = new System.Collections.Generic.List<string> () {
 
581
                        new TestClass () {
 
582
                                Property = ""Value1""
 
583
                        },
 
584
                        new TestClass () {
 
585
                                Property = ""Value2"",
 
586
                                Nested = new TestClass () {
 
587
                                        Property = ""Value3""
 
588
                                }
 
589
                        }
 
590
                };
 
591
                // This should stay here
 
592
                item = new TestClass();
 
593
        }
 
594
}");
 
595
                }
 
596
                
 
597
                [Test]
 
598
                public void StopsAtUnresolvableAssignmentTarget()
 
599
                {
 
600
                        Test<ConvertToInitializerAction>(baseText + @"
 
601
                var variable = new Test$Class ();
 
602
                variable.Property = ""Value"";
 
603
                Variable.Nested = new TestClass();
 
604
        }
 
605
}", baseText + @"
 
606
                var variable = new TestClass () {
 
607
                        Property = ""Value""
 
608
                };
 
609
                Variable.Nested = new TestClass();
 
610
        }
 
611
}"
 
612
                                                         );
 
613
                }
 
614
                
 
615
                [Test]
 
616
                public void NoActionForSingleStepInitializers()
 
617
                {
 
618
                        TestWrongContext<ConvertToInitializerAction>(baseText + @"
 
619
                var variable = new Test$Class ();
 
620
                var s = string.Empty;
 
621
        }
 
622
}");
 
623
                }
 
624
 
 
625
                [Test]
 
626
                public void IgnoresNonCreation()
 
627
                {
 
628
                        TestWrongContext<ConvertToInitializerAction>(@"
 
629
class TestClass
 
630
{
 
631
        void F()
 
632
        {
 
633
                System.Console.$WriteLine("""");
 
634
                var variable = new TestClass();
 
635
        }
 
636
}");
 
637
                }
 
638
                
 
639
                [Test]
 
640
                public void IgnoresSingleCreation()
 
641
                {
 
642
                        TestWrongContext<ConvertToInitializerAction>(@"
 
643
class TestClass
 
644
{
 
645
        void F()
 
646
        {
 
647
                var variable = new $TestClass();
 
648
        }
 
649
}");
 
650
                }
 
651
                
 
652
                [Test]
 
653
                public void DoesNotCrashOnDeclarationInitializedToVariable()
 
654
                {
 
655
                        TestWrongContext<ConvertToInitializerAction>(@"
 
656
class TestClass
 
657
{
 
658
        void F()
 
659
        {
 
660
                var s = """";
 
661
                s$ = ""2"";
 
662
                // And another statement to make the converter even try
 
663
                s = """";
 
664
        }
 
665
}");
 
666
                }
 
667
                
 
668
                [Test]
 
669
                public void DoesNotCrashOnVariableDeclarationWithoutInitializer()
 
670
                {
 
671
                        TestWrongContext<ConvertToInitializerAction>(@"
 
672
class TestClass
 
673
{
 
674
        void F()
 
675
        {
 
676
                TestClass $s1 = new TestClass();
 
677
                TestClass s2;
 
678
        }
 
679
}");
 
680
                }
 
681
                
 
682
                [Test]
 
683
                public void DoesNotCrashOnDelegateAssignment()
 
684
                {
 
685
                        TestWrongContext<ConvertToInitializerAction>(@"
 
686
using System;
 
687
using System.Collections.Generic;
 
688
class TestClass {
 
689
        void F() {
 
690
                ((CheckBox)ControlDictionary[""ReplaceCheckBox""]).CheckedChanged = new E$ventHandler(ReplaceCheckBox_CheckedChanged);
 
691
        }
 
692
        Dictionary<string, Control> ControlDictionary;
 
693
        void ReplaceCheckBox_CheckedChanged(object sender, EventArgs e) {}
 
694
}
 
695
class Control {}
 
696
class CheckBox : Control {
 
697
        public EventHandler CheckedChanged;
 
698
}
 
699
");
 
700
                        
 
701
                }
 
702
        }
 
703
}
 
704