This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 262
/
NameLookupTests.cs
809 lines (724 loc) · 21 KB
/
NameLookupTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Resolver
{
[TestFixture]
public class NameLookupTests : ResolverTestBase
{
[Test]
public void SimpleNameLookupWithoutContext()
{
// nothing should be found without specifying any UsingScope - however, the resolver also must not crash
resolver.UsingScope = null;
Assert.IsTrue(resolver.ResolveSimpleName("System", new IType[0]).IsError);
}
[Test]
public void SimpleNamespaceLookup()
{
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("System", new IType[0]);
Assert.AreEqual("System", nrr.NamespaceName);
Assert.AreSame(SharedTypes.UnknownType, nrr.Type);
}
[Test]
public void NamespaceInParentNamespaceLookup()
{
resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("Text", new IType[0]);
Assert.AreEqual("System.Text", nrr.NamespaceName);
}
[Test]
public void NamespacesAreNotImported()
{
AddUsing("System");
Assert.IsTrue(resolver.ResolveSimpleName("Collections", new IType[0]).IsError);
}
[Test]
public void ImportedType()
{
AddUsing("System");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("String", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
}
[Test]
public void UnknownIdentifierTest()
{
UnknownIdentifierResolveResult uirr = (UnknownIdentifierResolveResult)resolver.ResolveSimpleName("xyz", new IType[0]);
Assert.IsTrue(uirr.IsError);
Assert.AreEqual("xyz", uirr.Identifier);
}
[Test]
public void GlobalIsUnknownIdentifier()
{
Assert.IsTrue(resolver.ResolveSimpleName("global", new IType[0]).IsError);
}
[Test]
public void GlobalIsAlias()
{
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveAlias("global");
Assert.AreEqual("", nrr.NamespaceName);
}
[Test]
public void AliasToImportedType()
{
AddUsing("System");
AddUsingAlias("x", "String");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("x", new IType[0]);
// Unknown type (as String isn't looked up in System)
Assert.AreSame(SharedTypes.UnknownType, trr.Type);
}
[Test]
public void AliasToImportedType2()
{
AddUsing("System");
resolver.UsingScope = new UsingScope(resolver.UsingScope, "SomeNamespace");
AddUsingAlias("x", "String");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("x", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
}
[Test]
public void AliasOperatorOnTypeAlias()
{
AddUsingAlias("x", "System.String");
Assert.IsTrue(resolver.ResolveAlias("x").IsError);
}
[Test]
public void AliasOperatorOnNamespaceAlias()
{
AddUsingAlias("x", "System.Collections.Generic");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveAlias("x");
Assert.AreEqual("System.Collections.Generic", nrr.NamespaceName);
}
[Test]
public void AliasOperatorOnNamespace()
{
Assert.IsTrue(resolver.ResolveAlias("System").IsError);
}
[Test]
public void FindClassInCurrentNamespace()
{
resolver.UsingScope = MakeUsingScope("System.Collections");
TypeResolveResult trr = (TypeResolveResult)resolver.ResolveSimpleName("String", new IType[0]);
Assert.AreEqual("System.String", trr.Type.FullName);
}
[Test]
public void FindNeighborNamespace()
{
resolver.UsingScope = MakeUsingScope("System.Collections");
NamespaceResolveResult nrr = (NamespaceResolveResult)resolver.ResolveSimpleName("Text", new IType[0]);
Assert.AreEqual("System.Text", nrr.NamespaceName);
}
[Test]
public void FindTypeParameters()
{
resolver.UsingScope = MakeUsingScope("System.Collections.Generic");
resolver.CurrentTypeDefinition = context.GetTypeDefinition(typeof(List<>));
resolver.CurrentMember = resolver.CurrentTypeDefinition.Methods.Single(m => m.Name == "ConvertAll");
TypeResolveResult trr;
trr = (TypeResolveResult)resolver.ResolveSimpleName("TOutput", new IType[0]);
Assert.AreSame(((IMethod)resolver.CurrentMember).TypeParameters[0], trr.Type);
trr = (TypeResolveResult)resolver.ResolveSimpleName("T", new IType[0]);
Assert.AreSame(resolver.CurrentTypeDefinition.TypeParameters[0], trr.Type);
}
[Test]
public void SimpleParameter()
{
string program = @"class A {
void Method(string a) {
string b = $a$;
}
}
";
LocalResolveResult result = Resolve<LocalResolveResult>(program);
Assert.AreEqual("a", result.Variable.Name);
Assert.IsTrue(result.IsParameter);
Assert.AreEqual("System.String", result.Type.FullName);
}
[Test]
public void SimpleLocalVariable()
{
string program = @"class A {
void Method() {
string a;
string b = $a$;
}
}
";
LocalResolveResult result = Resolve<LocalResolveResult>(program);
Assert.AreEqual("a", result.Variable.Name);
Assert.IsFalse(result.IsParameter);
Assert.AreEqual("System.String", result.Type.FullName);
}
[Test]
public void UnknownTypeTest()
{
string program = @"class A {
void Method($StringBuilder$ b) {
}
}
";
UnknownIdentifierResolveResult result = Resolve<UnknownIdentifierResolveResult>(program);
Assert.AreEqual("StringBuilder", result.Identifier);
Assert.AreSame(SharedTypes.UnknownType, result.Type);
}
[Test]
public void PropertyNameAmbiguousWithTypeName()
{
string program = @"class A {
public Color Color { get; set; }
void Method() {
$
}
}
class Color { public static readonly Color Empty = null; }
";
TypeResolveResult trr = Resolve<TypeResolveResult>(program.Replace("$", "$Color$ c;"));
Assert.AreEqual("Color", trr.Type.Name);
MemberResolveResult mrr = Resolve<MemberResolveResult>(program.Replace("$", "x = $Color$;"));
Assert.AreEqual("Color", mrr.Member.Name);
Resolve<MemberResolveResult>(program.Replace("$", "$Color$ = Color.Empty;"));
Resolve<TypeResolveResult>(program.Replace("$", "Color = $Color$.Empty;"));
Resolve<MemberResolveResult>(program.Replace("$", "x = $Color$.ToString();"));
}
[Test]
public void ValueInsideSetterTest()
{
string program = @"class A {
public string Property {
set {
var a = $value$;
}
}
}
";
LocalResolveResult result = Resolve<LocalResolveResult>(program);
Assert.AreEqual("System.String", result.Type.FullName);
Assert.AreEqual("value", result.Variable.Name);
}
[Test]
public void ValueInsideEventTest()
{
string program = @"using System; class A {
public event EventHandler Ev {
add {
var a = $value$;
}
remove {}
}
}
";
LocalResolveResult result = Resolve<LocalResolveResult>(program);
Assert.AreEqual("System.EventHandler", result.Type.FullName);
Assert.AreEqual("value", result.Variable.Name);
}
[Test]
public void ValueInsideIndexerSetterTest()
{
string program = @"using System; class A {
public string this[int arg] {
set {
var a = $value$;
}
}
}
";
LocalResolveResult result = Resolve<LocalResolveResult>(program);
Assert.AreEqual("System.String", result.Type.FullName);
Assert.AreEqual("value", result.Variable.Name);
}
[Test, Ignore("Anonymous methods not supported in resolver")]
public void AnonymousMethodParameters()
{
string program = @"using System;
class A {
void Method() {
SomeEvent += delegate(object sender, EventArgs e) {
$e$.ToString();
};
} }
";
LocalResolveResult result = Resolve<LocalResolveResult>(program);
Assert.AreEqual("System.EventArgs", result.Type.FullName);
Assert.AreEqual("e", result.Variable.Name);
}
[Test]
public void DefaultTypeCSharp()
{
string program = @"class A {
void Method() {
$int$ a;
} }
";
TypeResolveResult result = Resolve<TypeResolveResult>(program);
Assert.AreEqual("System.Int32", result.Type.FullName);
}
[Test]
public void LoopVariableScopeTest()
{
string program = @"using System;
class TestClass {
void Test() {
for (int i = 0; i < 10; i++) {
$1$.ToString();
}
for (long i = 0; i < 10; i++) {
$2$.ToString();
}
}
}
";
LocalResolveResult lr = Resolve<LocalResolveResult>(program.Replace("$1$", "$i$").Replace("$2$", "i"));
Assert.AreEqual("System.Int32", lr.Type.ReflectionName);
lr = Resolve<LocalResolveResult>(program.Replace("$1$", "i").Replace("$2$", "$i$"));
Assert.AreEqual("System.Int64", lr.Type.ReflectionName);
}
[Test]
public void NamespacePreferenceTest()
{
// Classes in the current namespace are preferred over classes from
// imported namespaces
string program = @"using System;
namespace Testnamespace {
class A {
$Activator$ a;
}
class Activator {
}
}
";
var result = Resolve<TypeResolveResult>(program);
Assert.AreEqual("Testnamespace.Activator", result.Type.FullName);
}
[Test]
public void ParentNamespaceTypeLookup()
{
string program = @"using System;
namespace Root {
class Alpha {}
}
namespace Root.Child {
class Beta {
$Alpha$ a;
}
}
";
var result = Resolve<TypeResolveResult>(program);
Assert.AreEqual("Root.Alpha", result.Type.FullName);
}
[Test]
public void ImportAliasTest()
{
string program = @"using COL = System.Collections;
class TestClass {
COL.ArrayList ff;
}
";
TypeResolveResult type = Resolve<TypeResolveResult>(program, "COL.ArrayList");
Assert.IsNotNull(type, "COL.ArrayList should resolve to a type");
Assert.AreEqual("System.Collections.ArrayList", type.Type.FullName, "TypeResolveResult");
MemberResolveResult member = Resolve<MemberResolveResult>(program, "ff");
Assert.AreEqual("System.Collections.ArrayList", member.Type.FullName, "the full type should be resolved");
}
[Test]
public void ImportAliasNamespaceResolveTest()
{
NamespaceResolveResult ns;
string program = "using COL = System.Collections;\r\nclass A {\r\n$.ArrayList a;\r\n}\r\n";
ns = Resolve<NamespaceResolveResult>(program.Replace("$", "$COL$"));
Assert.AreEqual("System.Collections", ns.NamespaceName, "COL");
ns = Resolve<NamespaceResolveResult>(program.Replace("$", "$COL.Generic$"));
Assert.AreEqual("System.Collections.Generic", ns.NamespaceName, "COL.Generic");
}
[Test]
public void ImportAliasClassResolveTest()
{
string program = @"using COL = System.Collections.ArrayList;
class TestClass {
void Test() {
COL a = new COL();
}
}
";
TypeResolveResult trr = Resolve<TypeResolveResult>(program.Replace("COL a", "$COL$ a"));
Assert.AreEqual("System.Collections.ArrayList", trr.Type.FullName, "COL");
ResolveResult rr = Resolve<ResolveResult>(program.Replace("new COL()", "$new COL()$"));
Assert.AreEqual("System.Collections.ArrayList", rr.Type.FullName, "a");
}
[Test]
public void ImportSubnamespaceWithAliasTest()
{
string program = @"namespace PC
{
// Define an alias for the nested namespace.
using Project = PC.MyCompany.Project;
class A
{
Project.MyClass M()
{
// Use the alias
$Project.MyClass$ mc = new Project.MyClass();
return mc;
}
}
namespace MyCompany
{
namespace Project
{
public class MyClass { }
}
}
}
";
var mrr = Resolve(program);
Assert.AreEqual("PC.MyCompany.Project.MyClass", mrr.Type.FullName);
}
[Test]
public void ResolveNamespaceSD_863()
{
string program = @"using System;
namespace A.C { class D {} }
namespace A.B.C { class D {} }
namespace A.B {
class TestClass {
void Test() {
C.D x;
}
}
}
";
NamespaceResolveResult nrr = Resolve<NamespaceResolveResult>(program.Replace("C.D", "$C$.D"));
Assert.AreEqual("A.B.C", nrr.NamespaceName, "nrr.Name");
TypeResolveResult trr = Resolve<TypeResolveResult>(program.Replace("C.D", "$C.D$"));
Assert.AreEqual("A.B.C.D", trr.Type.FullName);
}
[Test]
public void ResolveTypeSD_863()
{
string program = @"using System;
namespace A { class C {} }
namespace A.B {
class C {}
class TestClass {
void Test() {
$C$ a;
}
}
}
";
TypeResolveResult trr = Resolve<TypeResolveResult>(program);
Assert.AreEqual("A.B.C", trr.Type.FullName);
}
[Test]
public void InnerTypeResolve ()
{
string program = @"public class C<T> { public class Inner { } }
class TestClass {
void Test() {
$C<string>.Inner$ a;
}
}
";
TypeResolveResult trr = Resolve<TypeResolveResult>(program);
Assert.AreEqual("C.Inner", trr.Type.FullName);
program = @"public class C<T> { public class D<S,U> { public class Inner { } }}
class TestClass {
void Test() {
$C<string>.D<int,TestClass>.Inner$ a;
}
}
";
trr = Resolve<TypeResolveResult>(program);
Assert.AreEqual("C.D.Inner", trr.Type.FullName);
}
[Test, Ignore("parser is broken and produces IdentifierExpression instead of PrimitiveType")]
public void ShortMaxValueTest()
{
string program = @"using System;
class TestClass {
object a = $short.MaxValue$;
}
";
MemberResolveResult rr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("System.Int16", rr.Type.FullName);
Assert.AreEqual("System.Int16.MaxValue", rr.Member.FullName);
Assert.AreEqual(short.MaxValue, rr.ConstantValue);
}
[Test]
public void ClassWithSameNameAsNamespace()
{
string program = @"using System; namespace XX {
class Test {
static void X() {
a = $;
}
}
class XX {
public static void Test() {}
} }";
TypeResolveResult trr = Resolve<TypeResolveResult>(program.Replace("$", "$XX$"));
Assert.AreEqual("XX.XX", trr.Type.FullName);
NamespaceResolveResult nrr = Resolve<NamespaceResolveResult>(program.Replace("$", "$global::XX$.T"));
Assert.AreEqual("XX", nrr.NamespaceName);
trr = Resolve<TypeResolveResult>(program.Replace("$", "$global::XX.XX$"));
Assert.AreEqual("XX.XX", trr.Type.FullName);
MemberResolveResult mrr = Resolve<MemberResolveResult>(program.Replace("$", "$XX.Test()$"));
Assert.AreEqual("XX.XX.Test", mrr.Member.FullName);
}
[Test]
public void ClassNameLookup1()
{
string program = @"namespace MainNamespace {
using Test.Subnamespace;
class Program {
static void M($Test.TheClass$ c) {}
}
}
namespace Test { public class TheClass { } }
namespace Test.Subnamespace {
public class Test { public class TheClass { } }
}
";
TypeResolveResult trr = Resolve<TypeResolveResult>(program);
Assert.AreEqual("Test.Subnamespace.Test.TheClass", trr.Type.FullName);
}
[Test]
public void ClassNameLookup2()
{
string program = @"using Test.Subnamespace;
namespace MainNamespace {
class Program {
static void M($Test.TheClass$ c) {}
}
}
namespace Test { public class TheClass { } }
namespace Test.Subnamespace {
public class Test { public class TheClass { } }
}
";
TypeResolveResult trr = Resolve<TypeResolveResult>(program);
Assert.AreEqual("Test.TheClass", trr.Type.FullName);
}
[Test]
public void ClassNameLookup3()
{
string program = @"namespace MainNamespace {
using Test.Subnamespace;
class Program {
static void M($Test$ c) {}
}
}
namespace Test { public class TheClass { } }
namespace Test.Subnamespace {
public class Test { public class TheClass { } }
}
";
TypeResolveResult trr = Resolve<TypeResolveResult>(program);
Assert.AreEqual("Test.Subnamespace.Test", trr.Type.FullName);
}
[Test]
public void ClassNameLookup4()
{
string program = @"using Test.Subnamespace;
namespace MainNamespace {
class Program {
static void M($Test$ c) {}
}
}
namespace Test { public class TheClass { } }
namespace Test.Subnamespace {
public class Test { public class TheClass { } }
}
";
NamespaceResolveResult nrr = Resolve<NamespaceResolveResult>(program);
Assert.AreEqual("Test", nrr.NamespaceName);
}
[Test]
public void ClassNameLookup5()
{
string program = @"namespace MainNamespace {
using A;
class M {
void X($Test$ a) {}
}
namespace Test { class B {} }
}
namespace A {
class Test {}
}";
NamespaceResolveResult nrr = Resolve<NamespaceResolveResult>(program);
Assert.AreEqual("MainNamespace.Test", nrr.NamespaceName);
}
[Test]
public void InvocableRule()
{
string program = @"using System;
class DerivedClass : BaseClass {
static void X() {
a = $;
}
private static new int Test;
}
class BaseClass {
public static string Test() {}
}";
MemberResolveResult mrr = Resolve<MemberResolveResult>(program.Replace("$", "$BaseClass.Test()$"));
Assert.AreEqual("BaseClass.Test", mrr.Member.FullName);
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$Test$"));
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName);
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$DerivedClass.Test$"));
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName);
// returns BaseClass.Test because DerivedClass.Test is not invocable
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$DerivedClass.Test()$"));
Assert.AreEqual("BaseClass.Test", mrr.Member.FullName);
}
[Test]
public void InvocableRule2()
{
string program = @"using System;
class DerivedClass : BaseClass {
static void X() {
a = $;
}
private static new int Test;
}
delegate string SomeDelegate();
class BaseClass {
public static SomeDelegate Test;
}";
MemberResolveResult mrr = Resolve<MemberResolveResult>(program.Replace("$", "$BaseClass.Test$()"));
Assert.AreEqual("BaseClass.Test", mrr.Member.FullName);
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$Test$"));
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName);
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$DerivedClass.Test$"));
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName);
// returns BaseClass.Test because DerivedClass.Test is not invocable
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$DerivedClass.Test$()"));
Assert.AreEqual("BaseClass.Test", mrr.Member.FullName);
}
[Test]
public void AccessibleRule()
{
string program = @"using System;
class BaseClass {
static void X() {
a = $DerivedClass.Test$;
}
public static int Test;
}
class DerivedClass : BaseClass {
private static new int Test;
}
";
// returns BaseClass.Test because DerivedClass.Test is not accessible
MemberResolveResult mrr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("BaseClass.Test", mrr.Member.FullName);
}
[Test]
public void FieldHidingProperty()
{
string program = @"using System;
class DerivedClass : BaseClass {
static void X() {
a = $Test$;
}
public static new int Test;
}
class BaseClass {
public static int Test { get { return 0; } }
}
";
MemberResolveResult mrr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName);
}
[Test]
public void PropertyHidingField()
{
string program = @"using System;
class DerivedClass : BaseClass {
static void X() {
a = $Test$;
}
public static new int Test { get { return 0; } }
}
class BaseClass {
public static int Test;
}
";
MemberResolveResult mrr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName);
}
[Test, Ignore("Resolver Bug")]
public void SD_1487()
{
string program = @"using System;
class C2 : C1 {
public static void M() {
a = $;
}
}
class C1 {
protected static int Field;
}";
MemberResolveResult mrr;
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$Field$"));
Assert.AreEqual("C1.Field", mrr.Member.FullName);
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$C1.Field$"));
Assert.AreEqual("C1.Field", mrr.Member.FullName);
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$C2.Field$"));
Assert.AreEqual("C1.Field", mrr.Member.FullName);
}
[Test]
public void NullableValue()
{
string program = @"using System;
class Test {
public static void M(int? a) {
$a.Value$.ToString();
}
}";
MemberResolveResult rr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("System.Nullable.Value", rr.Member.FullName);
Assert.AreEqual("System.Int32", rr.Member.ReturnType.Resolve(context).FullName);
}
[Test, Ignore("Resolver bug")]
public void MethodHidesEvent()
{
// see SD-1542
string program = @"using System;
class Test : Form {
public Test() {
a = $base.KeyDown$;
}
void KeyDown(object sender, EventArgs e) {}
}
class Form {
public event EventHandler KeyDown;
}";
var mrr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("Form.KeyDown", mrr.Member.FullName);
var mgrr = Resolve<MethodGroupResolveResult>(program.Replace("base", "this"));
Assert.AreEqual("Test.KeyDown", mgrr.Methods.Single().FullName);
}
[Test, Ignore("partial classes not yet supported")]
public void ProtectedMemberVisibleWhenBaseTypeReferenceIsInOtherPart()
{
string program = @"using System;
partial class A {
void M1() {
$x$ = 0;
}
}
partial class A : B { }
class B
{
protected int x;
}";
var mrr = Resolve<MemberResolveResult>(program);
Assert.AreEqual("B.x", mrr.Member.FullName);
}
}
}