1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
7
namespace NRefactoryToBooConverter.Tests
10
public class MemberTests : TestHelper
13
public void EnumerationMember()
15
Test("public enum Trool { No, Maybe, Yes }", "public enum Trool:\n\tNo\n\tMaybe\n\tYes");
19
public void EnumerationMemberWithAttribute()
21
Test("public enum Trool { No, [XXX] Maybe, Yes }", "public enum Trool:\n\tNo\n\t[XXX]\n\tMaybe\n\tYes");
25
public void EnumerationMemberWithValue()
27
Test("public enum Trool { No = 0, Maybe = 2, Yes = 4 }", "public enum Trool:\n\tNo = 0\n\tMaybe = 2\n\tYes = 4");
33
TestInClass("MyType o;", "private o as MyType");
37
public void MultipleFields()
39
TestInClass("MyType a, b, c;", "private a as MyType\nprivate b as MyType\nprivate c as MyType");
43
public void PrimitiveField()
45
TestInClass("int num;", "private num as System.Int32");
49
public void ArrayField()
51
TestInClass("Field[] Core;", "private Core as (Field)");
55
public void FieldWithModifier()
57
TestInClass("public static int num;", "public static num as System.Int32");
61
public void ConstantField()
63
TestInClass("public const int num = 3;", "public static final num as System.Int32 = 3");
67
public void FullyQualifiedField()
69
TestInClass("System.IDisposable d;", "private d as System.IDisposable");
73
public void GenericField()
75
TestInClass("Dictionary<Dictionary<T, List<K>>, List<J>> d;",
76
"private d as Dictionary[of Dictionary[of T, List[of K]], List[of J]]");
80
public void FieldWithInitializer()
82
TestInClass("MyType o = null;", "private o as MyType = null");
88
TestInClass("void Main() {}", "private def Main() as System.Void:\n\tpass");
92
public void ExplicitInterfaceImplementationMethod()
94
TestInClass("void IDisposable.Dispose() {}", "def IDisposable.Dispose() as System.Void:\n\tpass");
98
public void MethodWithAttribute()
100
TestInClass("[Test] void Main() {}", "[Test]\nprivate def Main() as System.Void:\n\tpass");
104
public void MethodWithParameters()
106
TestInClass("void Main(int a, MyType b) {}", "private def Main(a as System.Int32, b as MyType) as System.Void:\n\tpass");
110
public void MethodWithRefParameters()
112
TestInClass("void Main(ref int a, out MyType b) {}", "private def Main(ref a as System.Int32, ref b as MyType) as System.Void:\n\tpass");
116
public void MethodWithParamsParameters()
118
TestInClass("void Main(int a, params string[] args) {}", "private def Main(a as System.Int32, *args as (System.String)) as System.Void:\n\tpass");
122
public void MethodWithReturnType()
124
TestInClass("MyType Main() {}", "private def Main() as MyType:\n\tpass");
128
public void MethodWithModifier()
130
TestInClass("public static void Run() {}", "public static def Run() as System.Void:\n\tpass");
134
public void AbstractMethod()
136
TestInClass("public abstract void Run();", "public abstract def Run() as System.Void:\n\tpass");
140
// [Ignore("Fix requires change to Boo.Lang.Compiler.dll")]
141
public void AbstractMethodInInterface()
143
TestInInterface("void Run();", "def Run() as System.Void");
147
public void StaticMethodInStaticClass()
149
Test("public static class MainClass { public static void Run() {} }",
150
"public static class MainClass:\n\tpublic static def Run() as System.Void:\n\t\tpass");
154
public void Constructor()
156
TestInClass("ClassName() {}", "private def constructor():\n\tpass");
160
public void ConstructorWithAttribute()
162
TestInClass("[Test] ClassName() {}", "[Test]\nprivate def constructor():\n\tpass");
166
public void ConstructorWithParameters()
168
TestInClass("ClassName(int a, MyType b) {}", "private def constructor(a as System.Int32, b as MyType):\n\tpass");
172
public void ConstructorWithModifier()
174
TestInClass("public static ClassName() {}", "public static def constructor():\n\tpass");
178
public void ConstructorWithThisCall()
180
TestInClass("public ClassName() : this(5) {}", "public def constructor():\n\tself(5)");
184
public void ConstructorWithBaseCall()
186
TestInClass("public ClassName() : base(5) {}", "public def constructor():\n\tsuper(5)");
190
public void Destructor()
192
TestInClass("~ClassName() {}", "def destructor():\n\tpass");
196
public void DestructorWithAttribute()
198
TestInClass("[Test] ~ClassName() {}", "[Test]\ndef destructor():\n\tpass");
202
public void ReadOnlyProperty()
204
TestInClass("public string Text { get { } }", "public Text as System.String:\n\tget:\n\t\tpass");
208
public void WriteOnlyProperty()
210
TestInClass("public string Text { set { } }", "public Text as System.String:\n\tset:\n\t\tpass");
214
public void Property()
216
TestInClass("public string Text { get {} set { } }", "public Text as System.String:\n\tget:\n\t\tpass\n\tset:\n\t\tpass");
220
public void PropertyWithAttributes()
222
TestInClass("[AA] public string Text { [BB] get {} [CC] set { } }",
223
"[AA]\npublic Text as System.String:\n\t[BB]\n\tget:\n\t\tpass\n\t[CC]\n\tset:\n\t\tpass");
227
public void PropertyWithProtectedSetter()
229
TestInClass("public string Text { get {} protected set { } }",
230
"public Text as System.String:\n\tget:\n\t\tpass\n\tprotected set:\n\t\tpass");
234
public void AbstractProperty()
236
TestInClass("public abstract string Prop { get; }", "public abstract Prop as System.String:\n\tget:\n\t\tpass");
240
// [Ignore("Fix requires change to Boo.Lang.Compiler.dll")]
241
public void AbstractPropertyInInterface()
243
TestInInterface("string Prop { get; }", "Prop as System.String:\n\tget");
247
public void ReadOnlyIndexer()
249
TestInClass("public string this[int index] { get { } }", "public self[index as System.Int32] as System.String:\n\tget:\n\t\tpass");
253
public void WriteOnlyIndexer()
255
TestInClass("public string this[int index] { set { } }", "public self[index as System.Int32] as System.String:\n\tset:\n\t\tpass");
259
public void Indexer()
261
TestInClass("public string this[int index] { get {} set { } }", "public self[index as System.Int32] as System.String:\n\tget:\n\t\tpass\n\tset:\n\t\tpass");
265
public void IndexerWithAttributes()
267
TestInClass("[AA] public string this[int index] { [BB] get {} [CC] set { } }",
268
"[AA]\npublic self[index as System.Int32] as System.String:\n\t[BB]\n\tget:\n\t\tpass\n\t[CC]\n\tset:\n\t\tpass");
274
TestInClass("public event EventHandler Closed;", "public event Closed as EventHandler");
278
public void EventWithAttribute()
280
TestInClass("[LookHere] event EventHandler Closed;", "[LookHere]\nprivate event Closed as EventHandler");
284
// [Ignore("Fix requires change to Boo.Lang.Compiler.dll")]
285
public void EventInInterface()
287
TestInInterface("event EventHandler Closed;", "event Closed as EventHandler");
291
public void PInvoke()
293
TestInClass("[DllImport(\"User32.dll\", CharSet = CharSet.Auto)]\n" +
294
"static extern IntPtr MessageBox(int etc);",
295
"[DllImport('User32.dll', CharSet: CharSet.Auto)]\n" +
296
"private static def MessageBox(etc as System.Int32) as IntPtr:\n" +