Browse Source

* Output/SnippetConversion.cs:

* Output/VBNet/CSharpToVBNetConverterTest.cs:
* Output/CSharp/VBNetToCSharpConverterTest.cs: Fixed some unit tests
  so that they run on non windows platforms.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3841 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 17 years ago
parent
commit
ec18084e7a
  1. 10
      src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs
  2. 114
      src/Libraries/NRefactory/Test/Output/SnippetConversion.cs
  3. 70
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBNetConverterTest.cs

10
src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs

@ -625,7 +625,7 @@ static int static_Test2_j = 0;");
[Test] [Test]
public void ImportAliasPrimitiveType() public void ImportAliasPrimitiveType()
{ {
TestProgram("Imports T = System.Boolean", "using T = System.Boolean;\r\n"); TestProgram("Imports T = System.Boolean", "using T = System.Boolean;" + Environment.NewLine);
} }
[Test] [Test]
@ -696,10 +696,10 @@ static int static_Test2_j = 0;");
public void ConstModuleMember() public void ConstModuleMember()
{ {
TestProgram("Module Test : Public Const C As Integer = 0 : End Module", TestProgram("Module Test : Public Const C As Integer = 0 : End Module",
"static class Test\r\n" + "static class Test" + Environment.NewLine +
"{\r\n" + "{" + Environment.NewLine +
" public const int C = 0;\r\n" + " public const int C = 0;" + Environment.NewLine +
"}\r\n"); "}" + Environment.NewLine);
} }
} }
} }

114
src/Libraries/NRefactory/Test/Output/SnippetConversion.cs

@ -30,6 +30,7 @@ namespace ICSharpCode.NRefactory.Tests.Output
node.AcceptVisitor(new ToVBNetConvertVisitor(), null); node.AcceptVisitor(new ToVBNetConvertVisitor(), null);
VBNetOutputVisitor output = new VBNetOutputVisitor(); VBNetOutputVisitor output = new VBNetOutputVisitor();
using (SpecialNodesInserter.Install(parser.Specials, output)) { using (SpecialNodesInserter.Install(parser.Specials, output)) {
node.AcceptVisitor(output, null); node.AcceptVisitor(output, null);
} }
@ -66,38 +67,38 @@ namespace ICSharpCode.NRefactory.Tests.Output
public void CompilationUnitCS2VB() public void CompilationUnitCS2VB()
{ {
CS2VB( CS2VB(
@"using System; @"using System;" + Environment.NewLine +
"" + Environment.NewLine +
"public class MyClass" + Environment.NewLine +
"{" + Environment.NewLine +
" string abc;" + Environment.NewLine +
"" + Environment.NewLine +
" public string Abc { get { return abc; } }" + Environment.NewLine +
"" + Environment.NewLine +
" // This is a test method" + Environment.NewLine +
" static void M<T>(params T[] args) where T : IDisposable" + Environment.NewLine +
" {" + Environment.NewLine +
" Console.WriteLine(\"Hello!\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}",
public class MyClass @"Imports System" + Environment.NewLine +
{ "" + Environment.NewLine +
string abc; "Public Class [MyClass]" + Environment.NewLine +
" Private m_abc As String" + Environment.NewLine +
public string Abc { get { return abc; } } "" + Environment.NewLine +
" Public ReadOnly Property Abc() As String" + Environment.NewLine +
// This is a test method " Get" + Environment.NewLine +
static void M<T>(params T[] args) where T : IDisposable " Return m_abc" + Environment.NewLine +
{ " End Get" + Environment.NewLine +
Console.WriteLine(""Hello!""); " End Property" + Environment.NewLine +
} "" + Environment.NewLine +
}", " ' This is a test method" + Environment.NewLine +
" Private Shared Sub M(Of T As IDisposable)(ParamArray args As T())" + Environment.NewLine +
@"Imports System " Console.WriteLine(\"Hello!\")" + Environment.NewLine +
" End Sub" + Environment.NewLine +
Public Class [MyClass] "End Class" + Environment.NewLine +
Private m_abc As String ""
Public ReadOnly Property Abc() As String
Get
Return m_abc
End Get
End Property
' This is a test method
Private Shared Sub M(Of T As IDisposable)(ParamArray args As T())
Console.WriteLine(""Hello!"")
End Sub
End Class
"
); );
} }
@ -108,14 +109,14 @@ End Class
public void TypeMembersCS2VB() public void TypeMembersCS2VB()
{ {
CS2VB( CS2VB(
"void Test() {}\n" + "void Test() {}" + Environment.NewLine +
"void Test2() {}", "void Test2() {}",
@"Private Sub Test() @"Private Sub Test()" + Environment.NewLine +
End Sub "End Sub" + Environment.NewLine +
Private Sub Test2() "Private Sub Test2()" + Environment.NewLine +
End Sub "End Sub" + Environment.NewLine
"
); );
} }
@ -123,12 +124,11 @@ End Sub
public void StatementsCS2VB() public void StatementsCS2VB()
{ {
CS2VB( CS2VB(
"int a = 3;\n" + "int a = 3;" + Environment.NewLine +
"a++;", "a++;",
@"Dim a As Integer = 3 @"Dim a As Integer = 3" + Environment.NewLine +
a += 1 "a += 1" + Environment.NewLine
"
); );
} }
@ -137,18 +137,17 @@ a += 1
public void TypeMembersVB2CS() public void TypeMembersVB2CS()
{ {
VB2CS( VB2CS(
@"Sub Test() @"Sub Test()" + Environment.NewLine +
End Sub "End Sub" + Environment.NewLine +
Sub Test2() "Sub Test2()" + Environment.NewLine +
End Sub "End Sub" + Environment.NewLine,
", @"public void Test()" + Environment.NewLine +
@"public void Test() "{" + Environment.NewLine +
{ "}" + Environment.NewLine +
} "public void Test2()" + Environment.NewLine +
public void Test2() "{" + Environment.NewLine +
{ "}" + Environment.NewLine
}
"
); );
} }
@ -156,11 +155,10 @@ public void Test2()
public void StatementsVB2CS() public void StatementsVB2CS()
{ {
VB2CS( VB2CS(
@"Dim a As Integer = 3 @"Dim a As Integer = 3" + Environment.NewLine +
a += 1 "a += 1" + Environment.NewLine,
", "int a = 3;" + Environment.NewLine +
"int a = 3;\r\n" + "a += 1;" + Environment.NewLine
"a += 1;\r\n"
); );
} }
} }

70
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBNetConverterTest.cs

@ -71,45 +71,45 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void MoveImportsStatement() public void MoveImportsStatement()
{ {
TestProgram("namespace test { using SomeNamespace; }", TestProgram("namespace test { using SomeNamespace; }",
"Imports SomeNamespace\r\n" + "Imports SomeNamespace" + Environment.NewLine +
"Namespace test\r\n" + "Namespace test" + Environment.NewLine +
"End Namespace\r\n"); "End Namespace" + Environment.NewLine);
} }
[Test] [Test]
public void ClassImplementsInterface() public void ClassImplementsInterface()
{ {
TestProgram("class test : IComparable { }", TestProgram("class test : IComparable { }",
"Class test\r\n" + "Class test" + Environment.NewLine +
" Implements IComparable\r\n" + " Implements IComparable" + Environment.NewLine +
"End Class\r\n"); "End Class" + Environment.NewLine);
} }
[Test] [Test]
public void ClassImplementsInterface2() public void ClassImplementsInterface2()
{ {
TestProgram("class test : System.IComparable { }", TestProgram("class test : System.IComparable { }",
"Class test\r\n" + "Class test" + Environment.NewLine +
" Implements System.IComparable\r\n" + " Implements System.IComparable" + Environment.NewLine +
"End Class\r\n"); "End Class" + Environment.NewLine);
} }
[Test] [Test]
public void ClassInheritsClass() public void ClassInheritsClass()
{ {
TestProgram("class test : InvalidDataException { }", TestProgram("class test : InvalidDataException { }",
"Class test\r\n" + "Class test" + Environment.NewLine +
" Inherits InvalidDataException\r\n" + " Inherits InvalidDataException" + Environment.NewLine +
"End Class\r\n"); "End Class"+ Environment.NewLine);
} }
[Test] [Test]
public void ClassInheritsClass2() public void ClassInheritsClass2()
{ {
TestProgram("class test : System.IO.InvalidDataException { }", TestProgram("class test : System.IO.InvalidDataException { }",
"Class test\r\n" + "Class test" + Environment.NewLine +
" Inherits System.IO.InvalidDataException\r\n" + " Inherits System.IO.InvalidDataException" + Environment.NewLine +
"End Class\r\n"); "End Class" + Environment.NewLine);
} }
[Test] [Test]
@ -227,9 +227,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
[Test] [Test]
public void PInvoke() public void PInvoke()
{ {
TestMember("[DllImport(\"user32.dll\", CharSet = CharSet.Auto)]\n" + TestMember("[DllImport(\"user32.dll\", CharSet = CharSet.Auto)]" + Environment.NewLine +
"public static extern int MessageBox(IntPtr hwnd, string t, string caption, UInt32 t2);", "public static extern int MessageBox(IntPtr hwnd, string t, string caption, UInt32 t2);",
"<DllImport(\"user32.dll\", CharSet := CharSet.Auto)> _\n" + "<DllImport(\"user32.dll\", CharSet := CharSet.Auto)> _" + Environment.NewLine +
"Public Shared Function MessageBox(ByVal hwnd As IntPtr, ByVal t As String, ByVal caption As String, ByVal t2 As UInt32) As Integer\n" + "Public Shared Function MessageBox(ByVal hwnd As IntPtr, ByVal t As String, ByVal caption As String, ByVal t2 As UInt32) As Integer\n" +
"End Function"); "End Function");
@ -406,7 +406,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
[Test] [Test]
public void ImportAliasPrimitiveType() public void ImportAliasPrimitiveType()
{ {
TestProgram("using T = System.Boolean;", "Imports T = System.Boolean\r\n"); TestProgram("using T = System.Boolean;", "Imports T = System.Boolean"+ Environment.NewLine);
} }
[Test] [Test]
@ -418,11 +418,10 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
[Test] [Test]
public void StaticClass() public void StaticClass()
{ {
TestProgram("public static class Test {}", @"Public NotInheritable Class Test TestProgram("public static class Test {}", @"Public NotInheritable Class Test" + Environment.NewLine +
Private Sub New() " Private Sub New()" + Environment.NewLine +
End Sub " End Sub" + Environment.NewLine +
End Class "End Class" + Environment.NewLine);
");
} }
[Test] [Test]
@ -500,19 +499,18 @@ End Class
public void InlineAssignment() public void InlineAssignment()
{ {
TestProgram(@"public class Convert { void Run(string s) { char c; if ((c = s[0]) == '\n') { c = ' '; } } }", TestProgram(@"public class Convert { void Run(string s) { char c; if ((c = s[0]) == '\n') { c = ' '; } } }",
@"Public Class Convert @"Public Class Convert" + Environment.NewLine +
Private Sub Run(ByVal s As String) " Private Sub Run(ByVal s As String)" + Environment.NewLine +
Dim c As Char " Dim c As Char" + Environment.NewLine +
If (InlineAssignHelper(c, s(0))) = ControlChars.Lf Then " If (InlineAssignHelper(c, s(0))) = ControlChars.Lf Then" + Environment.NewLine +
c = "" ""C " c = \" \"C" + Environment.NewLine +
End If " End If" + Environment.NewLine +
End Sub " End Sub" + Environment.NewLine +
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T " Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T" + Environment.NewLine +
target = value " target = value" + Environment.NewLine +
Return value " Return value" + Environment.NewLine +
End Function " End Function" + Environment.NewLine +
End Class "End Class" + Environment.NewLine);
");
} }
[Test] [Test]

Loading…
Cancel
Save