~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBNetConverterTest.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 System.Text;
 
6
using System.IO;
 
7
using NUnit.Framework;
 
8
using ICSharpCode.NRefactory.Parser;
 
9
using ICSharpCode.NRefactory.Ast;
 
10
using ICSharpCode.NRefactory.PrettyPrinter;
 
11
using ICSharpCode.NRefactory.Visitors;
 
12
 
 
13
namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
 
14
{
 
15
        [TestFixture]
 
16
        public class CSharpToVBNetConverterTest
 
17
        {
 
18
                public void TestProgram(string input, string expectedOutput)
 
19
                {
 
20
                        IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input));
 
21
                        parser.Parse();
 
22
                        Assert.AreEqual("", parser.Errors.ErrorOutput);
 
23
                        var specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
 
24
                        PreprocessingDirective.CSharpToVB(specials);
 
25
                        parser.CompilationUnit.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
 
26
                        parser.CompilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), null);
 
27
                        VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
 
28
                        outputVisitor.Options.IndentationChar = ' ';
 
29
                        outputVisitor.Options.IndentSize = 2;
 
30
                        outputVisitor.Options.OutputByValModifier = true;
 
31
                        using (SpecialNodesInserter.Install(specials, outputVisitor)) {
 
32
                                outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
 
33
                        }
 
34
                        Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
 
35
                        Assert.AreEqual(expectedOutput.Replace("\r", ""), outputVisitor.Text.Replace("\r", ""));
 
36
                }
 
37
                
 
38
                public void TestMember(string input, string expectedOutput)
 
39
                {
 
40
                        StringBuilder b = new StringBuilder();
 
41
                        b.AppendLine("Class tmp1");
 
42
                        using (StringReader r = new StringReader(expectedOutput)) {
 
43
                                string line;
 
44
                                while ((line = r.ReadLine()) != null) {
 
45
                                        b.Append("  ");
 
46
                                        b.AppendLine(line);
 
47
                                }
 
48
                        }
 
49
                        b.AppendLine("End Class");
 
50
                        TestProgram("class tmp1 { \n" + input + "\n}", b.ToString());
 
51
                }
 
52
                
 
53
                public void TestStatement(string input, string expectedOutput)
 
54
                {
 
55
                        StringBuilder b = new StringBuilder();
 
56
                        b.AppendLine("Class tmp1");
 
57
                        b.AppendLine("  Private Sub tmp2()");
 
58
                        using (StringReader r = new StringReader(expectedOutput)) {
 
59
                                string line;
 
60
                                while ((line = r.ReadLine()) != null) {
 
61
                                        b.Append("    ");
 
62
                                        b.AppendLine(line);
 
63
                                }
 
64
                        }
 
65
                        b.AppendLine("  End Sub");
 
66
                        b.AppendLine("End Class");
 
67
                        TestProgram("class tmp1 { void tmp2() {\n" + input + "\n}}", b.ToString());
 
68
                }
 
69
                
 
70
                [Test]
 
71
                public void MoveImportsStatement()
 
72
                {
 
73
                        TestProgram("namespace test { using SomeNamespace; }",
 
74
                                    "Imports SomeNamespace" + Environment.NewLine +
 
75
                                    "Namespace test" + Environment.NewLine +
 
76
                                    "End Namespace" + Environment.NewLine);
 
77
                }
 
78
                
 
79
                [Test]
 
80
                public void ClassImplementsInterface()
 
81
                {
 
82
                        TestProgram("class test : IComparable { }",
 
83
                                    "Class test" + Environment.NewLine +
 
84
                                    "  Implements IComparable" + Environment.NewLine +
 
85
                                    "End Class" + Environment.NewLine);
 
86
                }
 
87
                
 
88
                [Test]
 
89
                public void ClassImplementsInterface2()
 
90
                {
 
91
                        TestProgram("class test : System.IComparable { }",
 
92
                                    "Class test" + Environment.NewLine +
 
93
                                    "  Implements System.IComparable" + Environment.NewLine +
 
94
                                    "End Class" + Environment.NewLine);
 
95
                }
 
96
                
 
97
                [Test]
 
98
                public void ClassInheritsClass()
 
99
                {
 
100
                        TestProgram("class test : InvalidDataException { }",
 
101
                                    "Class test" + Environment.NewLine +
 
102
                                    "  Inherits InvalidDataException" + Environment.NewLine +
 
103
                                    "End Class"+ Environment.NewLine);
 
104
                }
 
105
                
 
106
                [Test]
 
107
                public void ClassInheritsClass2()
 
108
                {
 
109
                        TestProgram("class test : System.IO.InvalidDataException { }",
 
110
                                    "Class test" + Environment.NewLine +
 
111
                                    "  Inherits System.IO.InvalidDataException" + Environment.NewLine +
 
112
                                    "End Class" + Environment.NewLine);
 
113
                }
 
114
                
 
115
                [Test]
 
116
                public void ForWithUnknownConditionAndSingleStatement()
 
117
                {
 
118
                        TestStatement("for (i = 0; unknownCondition; i++) b[i] = s[i];",
 
119
                                      "i = 0\n" +
 
120
                                      "While unknownCondition\n" +
 
121
                                      "  b(i) = s(i)\n" +
 
122
                                      "  i += 1\n" +
 
123
                                      "End While");
 
124
                }
 
125
                
 
126
                [Test]
 
127
                public void ForWithUnknownConditionAndBlock()
 
128
                {
 
129
                        TestStatement("for (i = 0; unknownCondition; i++) { b[i] = s[i]; }",
 
130
                                      "i = 0\n" +
 
131
                                      "While unknownCondition\n" +
 
132
                                      "  b(i) = s(i)\n" +
 
133
                                      "  i += 1\n" +
 
134
                                      "End While");
 
135
                }
 
136
                
 
137
                [Test]
 
138
                public void ForWithSingleStatement()
 
139
                {
 
140
                        TestStatement("for (i = 0; i < end; i++) b[i] = s[i];",
 
141
                                      "For i = 0 To [end] - 1\n" +
 
142
                                      "  b(i) = s(i)\n" +
 
143
                                      "Next");
 
144
                }
 
145
                [Test]
 
146
                public void ForWithBlock()
 
147
                {
 
148
                        TestStatement("for (i = 0; i < end; i++) { b[i] = s[i]; }",
 
149
                                      "For i = 0 To [end] - 1\n" +
 
150
                                      "  b(i) = s(i)\n" +
 
151
                                      "Next");
 
152
                }
 
153
                
 
154
                [Test]
 
155
                public void RaiseEvent()
 
156
                {
 
157
                        TestStatement("if (MyEvent != null) MyEvent(this, EventArgs.Empty);",
 
158
                                      "RaiseEvent MyEvent(Me, EventArgs.Empty)");
 
159
                        TestStatement("if ((MyEvent != null)) MyEvent(this, EventArgs.Empty);",
 
160
                                      "RaiseEvent MyEvent(Me, EventArgs.Empty)");
 
161
                        TestStatement("if (null != MyEvent) { MyEvent(this, EventArgs.Empty); }",
 
162
                                      "RaiseEvent MyEvent(Me, EventArgs.Empty)");
 
163
                        TestStatement("if (this.MyEvent != null) MyEvent(this, EventArgs.Empty);",
 
164
                                      "RaiseEvent MyEvent(Me, EventArgs.Empty)");
 
165
                        TestStatement("if (MyEvent != null) this.MyEvent(this, EventArgs.Empty);",
 
166
                                      "RaiseEvent MyEvent(Me, EventArgs.Empty)");
 
167
                        TestStatement("if ((this.MyEvent != null)) { this.MyEvent(this, EventArgs.Empty); }",
 
168
                                      "RaiseEvent MyEvent(Me, EventArgs.Empty)");
 
169
                }
 
170
                
 
171
                [Test]
 
172
                public void IfStatementSimilarToRaiseEvent()
 
173
                {
 
174
                        TestStatement("if (FullImage != null) DrawImage();",
 
175
                                      "If FullImage IsNot Nothing Then\n" +
 
176
                                      "  DrawImage()\n" +
 
177
                                      "End If");
 
178
                        // regression test:
 
179
                        TestStatement("if (FullImage != null) e.DrawImage();",
 
180
                                      "If FullImage IsNot Nothing Then\n" +
 
181
                                      "  e.DrawImage()\n" +
 
182
                                      "End If");
 
183
                        // with braces:
 
184
                        TestStatement("if (FullImage != null) { DrawImage(); }",
 
185
                                      "If FullImage IsNot Nothing Then\n" +
 
186
                                      "  DrawImage()\n" +
 
187
                                      "End If");
 
188
                        TestStatement("if (FullImage != null) { e.DrawImage(); }",
 
189
                                      "If FullImage IsNot Nothing Then\n" +
 
190
                                      "  e.DrawImage()\n" +
 
191
                                      "End If");
 
192
                        // another bug related to the IfStatement code:
 
193
                        TestStatement("if (Tiles != null) foreach (Tile t in Tiles) this.TileTray.Controls.Remove(t);",
 
194
                                      "If Tiles IsNot Nothing Then\n" +
 
195
                                      "  For Each t As Tile In Tiles\n" +
 
196
                                      "    Me.TileTray.Controls.Remove(t)\n" +
 
197
                                      "  Next\n" +
 
198
                                      "End If");
 
199
                }
 
200
                
 
201
                [Test]
 
202
                public void ElseIfStatement()
 
203
                {
 
204
                        TestStatement("if (a) {} else if (b) {} else {}",
 
205
                                      "If a Then\n" +
 
206
                                      "ElseIf b Then\n" +
 
207
                                      "Else\n" +
 
208
                                      "End If");
 
209
                }
 
210
                
 
211
                [Test]
 
212
                public void AnonymousMethod()
 
213
                {
 
214
                        TestMember("void A() { Converter<int, int> i = delegate(int argument) { return argument * 2; }; }",
 
215
                                   "Private Sub A()\n" +
 
216
                                   "  Dim i As Converter(Of Integer, Integer) = Function(ByVal argument As Integer) argument * 2\n" +
 
217
                                   "End Sub");
 
218
                }
 
219
                
 
220
                [Test]
 
221
                public void StaticMethod()
 
222
                {
 
223
                        TestMember("static void A() {}",
 
224
                                   "Private Shared Sub A()\nEnd Sub");
 
225
                }
 
226
                
 
227
                [Test]
 
228
                public void PInvoke()
 
229
                {
 
230
                        TestMember("[DllImport(\"user32.dll\", CharSet = CharSet.Auto)]" + Environment.NewLine +
 
231
                                   "public static extern int MessageBox(IntPtr hwnd, string t, string caption, UInt32 t2);",
 
232
                                   "<DllImport(\"user32.dll\", CharSet := CharSet.Auto)> _" + Environment.NewLine +
 
233
                                   "Public Shared Function MessageBox(ByVal hwnd As IntPtr, ByVal t As String, ByVal caption As String, ByVal t2 As UInt32) As Integer\n" +
 
234
                                   "End Function");
 
235
                        
 
236
                        TestMember("[DllImport(\"user32.dll\", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]\n" +
 
237
                                   "public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
 
238
                                   "Public Declare Ansi Function SendMessage Lib \"user32.dll\" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr");
 
239
                        
 
240
                        TestMember("[DllImport(\"user32.dll\", SetLastError = true, ExactSpelling = true, EntryPoint = \"SendMessageW\")]\n" +
 
241
                                   "public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, UIntPtr wParam, IntPtr lParam);",
 
242
                                   "Public Declare Auto Function SendMessage Lib \"user32.dll\" Alias \"SendMessageW\" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr");
 
243
                }
 
244
                
 
245
                [Test]
 
246
                public void PInvokeSub()
 
247
                {
 
248
                        TestMember("[DllImport(\"kernel32\", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]\n" +
 
249
                                   "private static extern void Sleep(long dwMilliseconds);",
 
250
                                   "Private Declare Ansi Sub Sleep Lib \"kernel32\" (ByVal dwMilliseconds As Long)");
 
251
                }
 
252
                
 
253
                [Test]
 
254
                public void Constructor()
 
255
                {
 
256
                        TestMember("public tmp1() : base(1) { }",
 
257
                                   "Public Sub New()\n  MyBase.New(1)\nEnd Sub");
 
258
                        TestMember("public tmp1() : this(1) { }",
 
259
                                   "Public Sub New()\n  Me.New(1)\nEnd Sub");
 
260
                }
 
261
                
 
262
                [Test]
 
263
                public void StaticConstructor()
 
264
                {
 
265
                        TestMember("static tmp1() { }",
 
266
                                   "Shared Sub New()\nEnd Sub");
 
267
                }
 
268
                
 
269
                [Test]
 
270
                public void Destructor()
 
271
                {
 
272
                        TestMember("~tmp1() { Dead(); }",
 
273
                                   "Protected Overrides Sub Finalize()\n" +
 
274
                                   "  Try\n" +
 
275
                                   "    Dead()\n" +
 
276
                                   "  Finally\n" +
 
277
                                   "    MyBase.Finalize()\n" +
 
278
                                   "  End Try\n" +
 
279
                                   "End Sub");
 
280
                }
 
281
                
 
282
                [Test]
 
283
                public void Indexer()
 
284
                {
 
285
                        TestMember("public CategoryInfo this[int index] { get { return List[index] as CategoryInfo; } }",
 
286
                                   "Public Default ReadOnly Property Item(ByVal index As Integer) As CategoryInfo\n" +
 
287
                                   "  Get\n" +
 
288
                                   "    Return TryCast(List(index), CategoryInfo)\n" +
 
289
                                   "  End Get\n" +
 
290
                                   "End Property");
 
291
                }
 
292
                
 
293
                [Test]
 
294
                public void RenameConflictingNames()
 
295
                {
 
296
                        TestMember("int count;" +
 
297
                                   "public int Count { get { return count; } }" +
 
298
                                   "void Test1(int count) { count = 3; }" +
 
299
                                   "void Test2() { int count; count = 3; }" +
 
300
                                   "void Test3() { foreach (int count in someList) { count = 3; } }",
 
301
                                   
 
302
                                   "Private m_count As Integer\n" +
 
303
                                   "Public ReadOnly Property Count() As Integer\n" +
 
304
                                   "  Get\n" +
 
305
                                   "    Return m_count\n" +
 
306
                                   "  End Get\n" +
 
307
                                   "End Property\n" +
 
308
                                   "Private Sub Test1(ByVal count As Integer)\n" +
 
309
                                   "  count = 3\n" +
 
310
                                   "End Sub\n" +
 
311
                                   "Private Sub Test2()\n" +
 
312
                                   "  Dim count As Integer\n" +
 
313
                                   "  count = 3\n" +
 
314
                                   "End Sub\n" +
 
315
                                   "Private Sub Test3()\n" +
 
316
                                   "  For Each count As Integer In someList\n" +
 
317
                                   "    count = 3\n" +
 
318
                                   "  Next\n" +
 
319
                                   "End Sub");
 
320
                }
 
321
                
 
322
                [Test]
 
323
                public void NullCoalescing()
 
324
                {
 
325
                        TestStatement("c = a ?? b;",
 
326
                                      "c = If(a, b)");
 
327
                }
 
328
                
 
329
                [Test]
 
330
                public void Ternary()
 
331
                {
 
332
                        TestStatement("d = a ? b : c;",
 
333
                                      "d = If(a, b, c)");
 
334
                }
 
335
                
 
336
                [Test]
 
337
                public void ConvertedLoop()
 
338
                {
 
339
                        TestStatement("while (cond) example();",
 
340
                                      "While cond\n" +
 
341
                                      "  example()\n" +
 
342
                                      "End While");
 
343
                }
 
344
                
 
345
                [Test]
 
346
                public void UIntVariableDeclaration()
 
347
                {
 
348
                        TestStatement("uint s = 0;", "Dim s As UInteger = 0");
 
349
                }
 
350
                
 
351
                [Test]
 
352
                public void BreakInWhileLoop()
 
353
                {
 
354
                        TestStatement("while (test != null) { break; }",
 
355
                                      "While test IsNot Nothing\n" +
 
356
                                      "  Exit While\n" +
 
357
                                      "End While");
 
358
                }
 
359
                
 
360
                [Test]
 
361
                public void BreakInDoLoop()
 
362
                {
 
363
                        TestStatement("do { break; } while (test != null);",
 
364
                                      "Do\n" +
 
365
                                      "  Exit Do\n" +
 
366
                                      "Loop While test IsNot Nothing");
 
367
                }
 
368
                
 
369
                [Test]
 
370
                public void StructFieldVisibility()
 
371
                {
 
372
                        TestMember("public struct A { int field; }",
 
373
                                   "Public Structure A\n" +
 
374
                                   "  Private field As Integer\n" +
 
375
                                   "End Structure");
 
376
                }
 
377
                
 
378
                [Test]
 
379
                public void InnerClassVisibility()
 
380
                {
 
381
                        TestMember("class Inner\n{\n}",
 
382
                                   "Private Class Inner\n" +
 
383
                                   "End Class");
 
384
                }
 
385
                
 
386
                [Test]
 
387
                public void InnerDelegateVisibility()
 
388
                {
 
389
                        TestMember("delegate void Test();",
 
390
                                   "Private Delegate Sub Test()");
 
391
                }
 
392
                
 
393
                [Test]
 
394
                public void InterfaceVisibility()
 
395
                {
 
396
                        TestMember("public interface ITest {\n" +
 
397
                                   "  void Test();\n" +
 
398
                                   "  string Name { get; set; }\n" +
 
399
                                   "}",
 
400
                                   "Public Interface ITest\n" +
 
401
                                   "  Sub Test()\n" +
 
402
                                   "  Property Name() As String\n" +
 
403
                                   "End Interface");
 
404
                }
 
405
                
 
406
                [Test]
 
407
                public void ImportAliasPrimitiveType()
 
408
                {
 
409
                        TestProgram("using T = System.Boolean;", "Imports T = System.Boolean"+ Environment.NewLine);
 
410
                }
 
411
                
 
412
                [Test]
 
413
                public void DefaultExpression()
 
414
                {
 
415
                        TestStatement("T oldValue = default(T);", "Dim oldValue As T = Nothing");
 
416
                }
 
417
                
 
418
                [Test]
 
419
                public void StaticClass()
 
420
                {
 
421
                        TestProgram("public static class Test {}", @"Public NotInheritable Class Test" + Environment.NewLine +
 
422
                                    "  Private Sub New()" + Environment.NewLine +
 
423
                                    "  End Sub" + Environment.NewLine +
 
424
                                    "End Class" + Environment.NewLine);
 
425
                }
 
426
                
 
427
                [Test]
 
428
                public void GlobalTypeReference()
 
429
                {
 
430
                        TestStatement("global::System.String a;", "Dim a As Global.System.String");
 
431
                }
 
432
                
 
433
                [Test]
 
434
                public void TestMethodCallOnCastExpression()
 
435
                {
 
436
                        TestStatement("((IDisposable)o).Dispose();", "DirectCast(o, IDisposable).Dispose()");
 
437
                }
 
438
                
 
439
                [Test]
 
440
                public void CaseConflictingMethod()
 
441
                {
 
442
                        TestMember("void T(int v) { int V = v; M(V, v); }",
 
443
                                   "Private Sub T(ByVal v__1 As Integer)\n" +
 
444
                                   "  Dim V__2 As Integer = v__1\n" +
 
445
                                   "  M(V__2, v__1)\n" +
 
446
                                   "End Sub");
 
447
                }
 
448
                
 
449
                [Test]
 
450
                public void ArrayCreationUpperBound()
 
451
                {
 
452
                        TestStatement("string[] i = new string[2];",
 
453
                                      "Dim i As String() = New String(1) {}");
 
454
                        TestStatement("string[] i = new string[2] { \"0\", \"1\" };",
 
455
                                      "Dim i As String() = New String(1) {\"0\", \"1\"}");
 
456
                        TestStatement("string[,] i = new string[6, 6];",
 
457
                                      "Dim i As String(,) = New String(5, 5) {}");
 
458
                }
 
459
                
 
460
                [Test]
 
461
                public void VariableNamedRem()
 
462
                {
 
463
                        TestStatement("int rem;", "Dim [rem] As Integer");
 
464
                        TestStatement("int Rem;", "Dim [Rem] As Integer");
 
465
                        TestStatement("int a = rem;", "Dim a As Integer = [rem]");
 
466
                }
 
467
                
 
468
                [Test]
 
469
                public void ArrayCast()
 
470
                {
 
471
                        TestStatement("string[] i = (string[])obj;",
 
472
                                      "Dim i As String() = DirectCast(obj, String())");
 
473
                        
 
474
                        // ensure the converter does not use CInt:
 
475
                        TestStatement("int[] i = (int[])obj;",
 
476
                                      "Dim i As Integer() = DirectCast(obj, Integer())");
 
477
                }
 
478
                
 
479
                
 
480
                [Test]
 
481
                public void PrimitiveCast()
 
482
                {
 
483
                        TestStatement("int a = (int)number;", "Dim a As Integer = CInt(number)");
 
484
                        TestStatement("byte i = (byte)obj;", "Dim i As Byte = CByte(obj)");
 
485
                        TestStatement("short i = (short)obj;", "Dim i As Short = CShort(obj)");
 
486
                        TestStatement("long i = (long)obj;", "Dim i As Long = CLng(obj)");
 
487
                }
 
488
                
 
489
                [Test]
 
490
                public void PrimitiveUnsignedCast()
 
491
                {
 
492
                        TestStatement("uint i = (uint)obj;", "Dim i As UInteger = CUInt(obj)");
 
493
                        TestStatement("sbyte i = (sbyte)obj;", "Dim i As SByte = CSByte(obj)");
 
494
                        TestStatement("ushort i = (ushort)obj;", "Dim i As UShort = CUShort(obj)");
 
495
                        TestStatement("ulong i = (ulong)obj;", "Dim i As ULong = CULng(obj)");
 
496
                }
 
497
                
 
498
                [Test]
 
499
                public void InlineAssignment()
 
500
                {
 
501
                        TestProgram(@"public class Convert { void Run(string s) { char c; if ((c = s[0]) == '\n') { c = ' '; } } }",
 
502
                                    @"Public Class Convert" + Environment.NewLine +
 
503
                                    "  Private Sub Run(ByVal s As String)" + Environment.NewLine +
 
504
                                    "    Dim c As Char" + Environment.NewLine +
 
505
                                    "    If (InlineAssignHelper(c, s(0))) = ControlChars.Lf Then" + Environment.NewLine +
 
506
                                    "      c = \" \"C" + Environment.NewLine +
 
507
                                    "    End If" + Environment.NewLine +
 
508
                                    "  End Sub" + Environment.NewLine +
 
509
                                    "  Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T" + Environment.NewLine +
 
510
                                    "    target = value" + Environment.NewLine +
 
511
                                    "    Return value" + Environment.NewLine +
 
512
                                    "  End Function" + Environment.NewLine +
 
513
                                    "End Class" + Environment.NewLine);
 
514
                }
 
515
                
 
516
                [Test]
 
517
                public void StandaloneBlockStatement()
 
518
                {
 
519
                        TestStatement("{ int a; } { string a; }",
 
520
                                      "If True Then\n" +
 
521
                                      "  Dim a As Integer\n" +
 
522
                                      "End If\n" +
 
523
                                      "If True Then\n" +
 
524
                                      "  Dim a As String\n" +
 
525
                                      "End If");
 
526
                }
 
527
                
 
528
                [Test]
 
529
                public void CSharpLinefeedToVBString()
 
530
                {
 
531
                        TestStatement(@"string Test = ""My Test\n"";",
 
532
                                      @"Dim Test As String = ""My Test"" & vbLf");
 
533
                }
 
534
                
 
535
                [Test]
 
536
                public void CSharpTabToVBString()
 
537
                {
 
538
                        TestStatement(@"string Test = ""\t\a"";",
 
539
                                      @"Dim Test As String = vbTab & ChrW(7)");
 
540
                }
 
541
                
 
542
                [Test]
 
543
                public void SizeOfInt32()
 
544
                {
 
545
                        TestStatement(@"byte[] ret = new byte[IntPtr.Size * sizeof(int)];",
 
546
                                      @"Dim ret As Byte() = New Byte(IntPtr.Size * 4 - 1) {}");
 
547
                }
 
548
                
 
549
                [Test]
 
550
                public void AutomaticProperty()
 
551
                {
 
552
                        TestMember(@"public string Name { get; set; }",
 
553
                                   @"Public Property Name() As String
 
554
  Get
 
555
    Return m_Name
 
556
  End Get
 
557
  Set
 
558
    m_Name = Value
 
559
  End Set
 
560
End Property
 
561
Private m_Name As String");
 
562
                }
 
563
                
 
564
                [Test]
 
565
                public void AutomaticPropertyPrivateSetter()
 
566
                {
 
567
                        TestMember(@"public string Name { get; private set; }",
 
568
                                   @"Public Property Name() As String
 
569
  Get
 
570
    Return m_Name
 
571
  End Get
 
572
  Private Set
 
573
    m_Name = Value
 
574
  End Set
 
575
End Property
 
576
Private m_Name As String");
 
577
                }
 
578
                
 
579
                [Test]
 
580
                public void DefaultValueExpression()
 
581
                {
 
582
                        TestStatement(@"object x = default(int);",
 
583
                                      @"Dim x As Object = 0");
 
584
                }
 
585
                
 
586
                [Test]
 
587
                public void BaseIndexerAccess()
 
588
                {
 
589
                        TestStatement("object a = base[0];", "Dim a As Object = MyBase.Item(0)");
 
590
                }
 
591
                
 
592
                [Test]
 
593
                public void TestMemberHiding()
 
594
                {
 
595
                        TestMember("public new void Remove() {}", "Public Shadows Sub Remove()\nEnd Sub");
 
596
                }
 
597
                
 
598
                [Test]
 
599
                public void TestImplicitlyTypedVariable()
 
600
                {
 
601
                        TestStatement("var i = 0;", "Dim i = 0");
 
602
                }
 
603
                
 
604
                [Test]
 
605
                public void TestAnonymousType()
 
606
                {
 
607
                        TestStatement("var x = new { i = 0, abc, abc.Test };",
 
608
                                      "Dim x = New With { _\n" +
 
609
                                      "  Key .i = 0, _\n" +
 
610
                                      "  abc, _\n" +
 
611
                                      "  abc.Test _\n" +
 
612
                                      "}");
 
613
                }
 
614
                
 
615
                [Test]
 
616
                public void CollectionAndObjectInitializer()
 
617
                {
 
618
                        TestStatement("List<X> l = new List<X> { new X { A = 1 }, new X { A = 2 } };",
 
619
                                      "Dim l As New List(Of X)() From { _\n" +
 
620
                                      "  New X() With { _\n" +
 
621
                                      "    Key .A = 1 _\n" +
 
622
                                      "  }, _\n" +
 
623
                                      "  New X() With { _\n" +
 
624
                                      "    Key .A = 2 _\n" +
 
625
                                      "  } _\n" +
 
626
                                      "}");
 
627
                }
 
628
                
 
629
                [Test]
 
630
                public void SD2_970()
 
631
                {
 
632
                        TestProgram(
 
633
                                @"namespace MyNamespace
 
634
{
 
635
      #region ""Test""
 
636
            using System;
 
637
            public partial class MainForm
 
638
            {
 
639
                  object x;
 
640
            }
 
641
      #endregion
 
642
}",
 
643
                                @"Imports System
 
644
Namespace MyNamespace
 
645
  #Region ""Test""
 
646
  Public Partial Class MainForm
 
647
    Private x As Object
 
648
  End Class
 
649
  #End Region
 
650
End Namespace
 
651
"
 
652
                        );
 
653
                }
 
654
                
 
655
                [Test]
 
656
                public void SD2_1424()
 
657
                {
 
658
                        TestMember(
 
659
                                @"public int Min()
 
660
{
 
661
  int min = 5;
 
662
  return min;
 
663
}",
 
664
                                @"Public Function Min() As Integer
 
665
  Dim min__1 As Integer = 5
 
666
  Return min__1
 
667
End Function"
 
668
                        );
 
669
                }
 
670
                
 
671
                [Test]
 
672
                public void GenericConstraint()
 
673
                {
 
674
                        TestProgram(
 
675
                                @"using System;
 
676
using System.Collections;
 
677
using System.Text;
 
678
 
 
679
namespace Generics
 
680
{
 
681
        public class List<T> : CollectionBase where T : IDisposable
 
682
        {
 
683
        }
 
684
}",
 
685
                                @"Imports System
 
686
Imports System.Collections
 
687
Imports System.Text
 
688
 
 
689
Namespace Generics
 
690
  Public Class List(Of T As IDisposable)
 
691
    Inherits CollectionBase
 
692
  End Class
 
693
End Namespace
 
694
"
 
695
                        );
 
696
                }
 
697
        }
 
698
}