~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Test/MemberTests.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using NUnit.Framework;
 
6
 
 
7
namespace NRefactoryToBooConverter.Tests
 
8
{
 
9
        [TestFixture]
 
10
        public class MemberTests : TestHelper
 
11
        {
 
12
                [Test]
 
13
                public void EnumerationMember()
 
14
                {
 
15
                        Test("public enum Trool { No, Maybe, Yes }", "public enum Trool:\n\tNo\n\tMaybe\n\tYes");
 
16
                }
 
17
                
 
18
                [Test]
 
19
                public void EnumerationMemberWithAttribute()
 
20
                {
 
21
                        Test("public enum Trool { No, [XXX] Maybe, Yes }", "public enum Trool:\n\tNo\n\t[XXX]\n\tMaybe\n\tYes");
 
22
                }
 
23
                
 
24
                [Test]
 
25
                public void EnumerationMemberWithValue()
 
26
                {
 
27
                        Test("public enum Trool { No = 0, Maybe = 2, Yes = 4 }", "public enum Trool:\n\tNo = 0\n\tMaybe = 2\n\tYes = 4");
 
28
                }
 
29
                
 
30
                [Test]
 
31
                public void Field()
 
32
                {
 
33
                        TestInClass("MyType o;", "private o as MyType");
 
34
                }
 
35
                
 
36
                [Test]
 
37
                public void MultipleFields()
 
38
                {
 
39
                        TestInClass("MyType a, b, c;", "private a as MyType\nprivate b as MyType\nprivate c as MyType");
 
40
                }
 
41
                
 
42
                [Test]
 
43
                public void PrimitiveField()
 
44
                {
 
45
                        TestInClass("int num;", "private num as System.Int32");
 
46
                }
 
47
                
 
48
                [Test]
 
49
                public void ArrayField()
 
50
                {
 
51
                        TestInClass("Field[] Core;", "private Core as (Field)");
 
52
                }
 
53
                
 
54
                [Test]
 
55
                public void FieldWithModifier()
 
56
                {
 
57
                        TestInClass("public static int num;", "public static num as System.Int32");
 
58
                }
 
59
                
 
60
                [Test]
 
61
                public void ConstantField()
 
62
                {
 
63
                        TestInClass("public const int num = 3;", "public static final num as System.Int32 = 3");
 
64
                }
 
65
                
 
66
                [Test]
 
67
                public void FullyQualifiedField()
 
68
                {
 
69
                        TestInClass("System.IDisposable d;", "private d as System.IDisposable");
 
70
                }
 
71
                
 
72
                [Test]
 
73
                public void GenericField()
 
74
                {
 
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]]");
 
77
                }
 
78
                
 
79
                [Test]
 
80
                public void FieldWithInitializer()
 
81
                {
 
82
                        TestInClass("MyType o = null;", "private o as MyType = null");
 
83
                }
 
84
                
 
85
                [Test]
 
86
                public void Method()
 
87
                {
 
88
                        TestInClass("void Main() {}", "private def Main() as System.Void:\n\tpass");
 
89
                }
 
90
                
 
91
                [Test]
 
92
                public void ExplicitInterfaceImplementationMethod()
 
93
                {
 
94
                        TestInClass("void IDisposable.Dispose() {}", "def IDisposable.Dispose() as System.Void:\n\tpass");
 
95
                }
 
96
                
 
97
                [Test]
 
98
                public void MethodWithAttribute()
 
99
                {
 
100
                        TestInClass("[Test] void Main() {}", "[Test]\nprivate def Main() as System.Void:\n\tpass");
 
101
                }
 
102
                
 
103
                [Test]
 
104
                public void MethodWithParameters()
 
105
                {
 
106
                        TestInClass("void Main(int a, MyType b) {}", "private def Main(a as System.Int32, b as MyType) as System.Void:\n\tpass");
 
107
                }
 
108
                
 
109
                [Test]
 
110
                public void MethodWithRefParameters()
 
111
                {
 
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");
 
113
                }
 
114
                
 
115
                [Test]
 
116
                public void MethodWithParamsParameters()
 
117
                {
 
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");
 
119
                }
 
120
                
 
121
                [Test]
 
122
                public void MethodWithReturnType()
 
123
                {
 
124
                        TestInClass("MyType Main() {}", "private def Main() as MyType:\n\tpass");
 
125
                }
 
126
                
 
127
                [Test]
 
128
                public void MethodWithModifier()
 
129
                {
 
130
                        TestInClass("public static void Run() {}", "public static def Run() as System.Void:\n\tpass");
 
131
                }
 
132
                
 
133
                [Test]
 
134
                public void AbstractMethod()
 
135
                {
 
136
                        TestInClass("public abstract void Run();", "public abstract def Run() as System.Void:\n\tpass");
 
137
                }
 
138
                
 
139
                [Test]
 
140
//              [Ignore("Fix requires change to Boo.Lang.Compiler.dll")]
 
141
                public void AbstractMethodInInterface()
 
142
                {
 
143
                        TestInInterface("void Run();", "def Run() as System.Void");
 
144
                }
 
145
                
 
146
                [Test]
 
147
                public void StaticMethodInStaticClass()
 
148
                {
 
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");
 
151
                }
 
152
                
 
153
                [Test]
 
154
                public void Constructor()
 
155
                {
 
156
                        TestInClass("ClassName() {}", "private def constructor():\n\tpass");
 
157
                }
 
158
                
 
159
                [Test]
 
160
                public void ConstructorWithAttribute()
 
161
                {
 
162
                        TestInClass("[Test] ClassName() {}", "[Test]\nprivate def constructor():\n\tpass");
 
163
                }
 
164
                
 
165
                [Test]
 
166
                public void ConstructorWithParameters()
 
167
                {
 
168
                        TestInClass("ClassName(int a, MyType b) {}", "private def constructor(a as System.Int32, b as MyType):\n\tpass");
 
169
                }
 
170
                
 
171
                [Test]
 
172
                public void ConstructorWithModifier()
 
173
                {
 
174
                        TestInClass("public static ClassName() {}", "public static def constructor():\n\tpass");
 
175
                }
 
176
                
 
177
                [Test]
 
178
                public void ConstructorWithThisCall()
 
179
                {
 
180
                        TestInClass("public ClassName() : this(5) {}", "public def constructor():\n\tself(5)");
 
181
                }
 
182
                
 
183
                [Test]
 
184
                public void ConstructorWithBaseCall()
 
185
                {
 
186
                        TestInClass("public ClassName() : base(5) {}", "public def constructor():\n\tsuper(5)");
 
187
                }
 
188
                
 
189
                [Test]
 
190
                public void Destructor()
 
191
                {
 
192
                        TestInClass("~ClassName() {}", "def destructor():\n\tpass");
 
193
                }
 
194
                
 
195
                [Test]
 
196
                public void DestructorWithAttribute()
 
197
                {
 
198
                        TestInClass("[Test] ~ClassName() {}", "[Test]\ndef destructor():\n\tpass");
 
199
                }
 
200
                
 
201
                [Test]
 
202
                public void ReadOnlyProperty()
 
203
                {
 
204
                        TestInClass("public string Text { get { } }", "public Text as System.String:\n\tget:\n\t\tpass");
 
205
                }
 
206
                
 
207
                [Test]
 
208
                public void WriteOnlyProperty()
 
209
                {
 
210
                        TestInClass("public string Text { set { } }", "public Text as System.String:\n\tset:\n\t\tpass");
 
211
                }
 
212
                
 
213
                [Test]
 
214
                public void Property()
 
215
                {
 
216
                        TestInClass("public string Text { get {} set { } }", "public Text as System.String:\n\tget:\n\t\tpass\n\tset:\n\t\tpass");
 
217
                }
 
218
                
 
219
                [Test]
 
220
                public void PropertyWithAttributes()
 
221
                {
 
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");
 
224
                }
 
225
                
 
226
                [Test]
 
227
                public void PropertyWithProtectedSetter()
 
228
                {
 
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");
 
231
                }
 
232
                
 
233
                [Test]
 
234
                public void AbstractProperty()
 
235
                {
 
236
                        TestInClass("public abstract string Prop { get; }", "public abstract Prop as System.String:\n\tget:\n\t\tpass");
 
237
                }
 
238
                
 
239
                [Test]
 
240
//              [Ignore("Fix requires change to Boo.Lang.Compiler.dll")]
 
241
                public void AbstractPropertyInInterface()
 
242
                {
 
243
                        TestInInterface("string Prop { get; }", "Prop as System.String:\n\tget");
 
244
                }
 
245
                
 
246
                [Test]
 
247
                public void ReadOnlyIndexer()
 
248
                {
 
249
                        TestInClass("public string this[int index] { get { } }", "public self[index as System.Int32] as System.String:\n\tget:\n\t\tpass");
 
250
                }
 
251
                
 
252
                [Test]
 
253
                public void WriteOnlyIndexer()
 
254
                {
 
255
                        TestInClass("public string this[int index] { set { } }", "public self[index as System.Int32] as System.String:\n\tset:\n\t\tpass");
 
256
                }
 
257
                
 
258
                [Test]
 
259
                public void Indexer()
 
260
                {
 
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");
 
262
                }
 
263
                
 
264
                [Test]
 
265
                public void IndexerWithAttributes()
 
266
                {
 
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");
 
269
                }
 
270
                
 
271
                [Test]
 
272
                public void Event()
 
273
                {
 
274
                        TestInClass("public event EventHandler Closed;", "public event Closed as EventHandler");
 
275
                }
 
276
                
 
277
                [Test]
 
278
                public void EventWithAttribute()
 
279
                {
 
280
                        TestInClass("[LookHere] event EventHandler Closed;", "[LookHere]\nprivate event Closed as EventHandler");
 
281
                }
 
282
                
 
283
                [Test]
 
284
//              [Ignore("Fix requires change to Boo.Lang.Compiler.dll")]
 
285
                public void EventInInterface()
 
286
                {
 
287
                        TestInInterface("event EventHandler Closed;", "event Closed as EventHandler");
 
288
                }
 
289
                
 
290
                [Test]
 
291
                public void PInvoke()
 
292
                {
 
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" +
 
297
                                    "\tpass");
 
298
                }
 
299
        }
 
300
}