26 changed files with 1122 additions and 391 deletions
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class ForNextConversionTests |
||||
{ |
||||
string vbnetForNextCode = |
||||
"Public Class Foo\r\n" + |
||||
" Public Function GetCount() As Integer\r\n" + |
||||
" Dim count As Integer = 0\r\n" + |
||||
" For i As Integer = 0 To 4\r\n" + |
||||
" count += 1\r\n" + |
||||
" Next\r\n" + |
||||
" Return count\r\n" + |
||||
" End Function\r\n" + |
||||
"End Class\r\n"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetForNextToPython() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string code = converter.Convert(vbnetForNextCode); |
||||
string expectedCode = |
||||
"class Foo(object):\r\n" + |
||||
" def GetCount(self):\r\n" + |
||||
" count = 0\r\n" + |
||||
" i = 0\r\n" + |
||||
" while i <= 4:\r\n" + |
||||
" count += 1\r\n" + |
||||
" i = i + 1\r\n" + |
||||
" return count"; |
||||
|
||||
Assert.AreEqual(expectedCode, code); |
||||
} |
||||
|
||||
string vbnetForNextWithStepCode = |
||||
"Public Class Foo\r\n" + |
||||
" Public Function GetCount() As Integer\r\n" + |
||||
" Dim count As Integer = 0\r\n" + |
||||
" For i As Integer = 0 To 4 Step 2\r\n" + |
||||
" count += 1\r\n" + |
||||
" Next\r\n" + |
||||
" Return count\r\n" + |
||||
" End Function\r\n" + |
||||
"End Class\r\n"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetForNextWithStepToPython() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string code = converter.Convert(vbnetForNextWithStepCode ); |
||||
string expectedCode = |
||||
"class Foo(object):\r\n" + |
||||
" def GetCount(self):\r\n" + |
||||
" count = 0\r\n" + |
||||
" i = 0\r\n" + |
||||
" while i <= 4:\r\n" + |
||||
" count += 1\r\n" + |
||||
" i = i + 2\r\n" + |
||||
" return count"; |
||||
|
||||
Assert.AreEqual(expectedCode, code); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class LocalVariableDefinitionsOnSameLineTests |
||||
{ |
||||
string csharp = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" public Foo()\r\n" + |
||||
" {\r\n" + |
||||
" int i = 0, i = 2;\r\n" + |
||||
" }\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertedPythonCode() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string python = converter.Convert(csharp); |
||||
string expectedPython = |
||||
"class Foo(object):\r\n" + |
||||
" def __init__(self):\r\n" + |
||||
" i = 0\r\n" + |
||||
" i = 2"; |
||||
|
||||
Assert.AreEqual(expectedPython, python); |
||||
} |
||||
|
||||
string vnetClassWithTwoArrayVariablesOnSameLine = |
||||
"class Foo\r\n" + |
||||
" Public Sub New()\r\n" + |
||||
" Dim i(10), j(20) as integer\r\n" + |
||||
" End Sub\r\n" + |
||||
"end class"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetClassWithTwoArrayVariablesOnSameLine() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string python = converter.Convert(vnetClassWithTwoArrayVariablesOnSameLine); |
||||
string expectedPython = |
||||
"class Foo(object):\r\n" + |
||||
" def __init__(self):\r\n" + |
||||
" i = Array.CreateInstance(int, 10)\r\n" + |
||||
" j = Array.CreateInstance(int, 20)"; |
||||
|
||||
Assert.AreEqual(expectedPython, python); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class MultipleFieldsOnSameLineTests |
||||
{ |
||||
string csharpClassWithFieldsThatHaveInitialValues = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" int i = 0, j = 1;\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertCSharpClassWithFieldsThatHaveInitialValues() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string python = converter.Convert(csharpClassWithFieldsThatHaveInitialValues); |
||||
string expectedPython = |
||||
"class Foo(object):\r\n" + |
||||
" def __init__(self):\r\n" + |
||||
" self._i = 0\r\n" + |
||||
" self._j = 1"; |
||||
|
||||
Assert.AreEqual(expectedPython, python); |
||||
} |
||||
|
||||
string csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" int i, j = 1;\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertCSharpClassWithFieldsWhereFirstFieldDoesNotHaveInitialValue() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string python = converter.Convert(csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue); |
||||
string expectedPython = |
||||
"class Foo(object):\r\n" + |
||||
" def __init__(self):\r\n" + |
||||
" self._j = 1"; |
||||
|
||||
Assert.AreEqual(expectedPython, python); |
||||
} |
||||
|
||||
string csharpClassWithTwoFieldsInitializedInMethod = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" int i = 0;\r\n" + |
||||
" int j, k;\r\n" + |
||||
"\r\n" + |
||||
" public void Test()\r\n" + |
||||
" {\r\n" + |
||||
" j = 1;\r\n" + |
||||
" k = 3;\r\n" + |
||||
" }\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertCSharpClassWithTwoFieldsInitializedInMethod() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string python = converter.Convert(csharpClassWithTwoFieldsInitializedInMethod); |
||||
string expectedPython = |
||||
"class Foo(object):\r\n" + |
||||
" def __init__(self):\r\n" + |
||||
" self._i = 0\r\n" + |
||||
"\r\n" + |
||||
" def Test(self):\r\n" + |
||||
" self._j = 1\r\n" + |
||||
" self._k = 3"; |
||||
|
||||
Assert.AreEqual(expectedPython, python); |
||||
} |
||||
|
||||
string vnetClassWithTwoArrayFieldsOnSameLine = |
||||
"class Foo\r\n" + |
||||
" Private i(10), j(20) as integer\r\n" + |
||||
"end class"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetClassWithTwoArrayFieldsOnSameLine() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string python = converter.Convert(vnetClassWithTwoArrayFieldsOnSameLine); |
||||
string expectedPython = |
||||
"class Foo(object):\r\n" + |
||||
" def __init__(self):\r\n" + |
||||
" self._i = Array.CreateInstance(int, 10)\r\n" + |
||||
" self._j = Array.CreateInstance(int, 20)"; |
||||
|
||||
Assert.AreEqual(expectedPython, python); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class VBExitConversionTests |
||||
{ |
||||
string vb = |
||||
"Public Class Class1\r\n" + |
||||
" Public Sub Test\r\n" + |
||||
" While True\r\n" + |
||||
" Exit While\r\n" + |
||||
" End While\r\n" + |
||||
" End Sub\r\n" + |
||||
"End Class\r\n"; |
||||
|
||||
[Test] |
||||
public void ConvertedPythonCode() |
||||
{ |
||||
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string python = converter.Convert(vb); |
||||
string expectedPython = |
||||
"class Class1(object):\r\n" + |
||||
" def Test(self):\r\n" + |
||||
" while True:\r\n" + |
||||
" break"; |
||||
|
||||
Assert.AreEqual(expectedPython, python); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class ForNextConversionTests |
||||
{ |
||||
string vbnetForNextCode = |
||||
"Public Class Foo\r\n" + |
||||
" Public Function GetCount() As Integer\r\n" + |
||||
" Dim count As Integer = 0\r\n" + |
||||
" For i As Integer = 0 To 4\r\n" + |
||||
" count += 1\r\n" + |
||||
" Next\r\n" + |
||||
" Return count\r\n" + |
||||
" End Function\r\n" + |
||||
"End Class\r\n"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetForNextToRuby() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string code = converter.Convert(vbnetForNextCode); |
||||
string expectedCode = |
||||
"class Foo\r\n" + |
||||
" def GetCount()\r\n" + |
||||
" count = 0\r\n" + |
||||
" i = 0\r\n" + |
||||
" while i <= 4\r\n" + |
||||
" count += 1\r\n" + |
||||
" i = i + 1\r\n" + |
||||
" end\r\n" + |
||||
" return count\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedCode, code); |
||||
} |
||||
|
||||
string vbnetForNextWithStepCode = |
||||
"Public Class Foo\r\n" + |
||||
" Public Function GetCount() As Integer\r\n" + |
||||
" Dim count As Integer = 0\r\n" + |
||||
" For i As Integer = 0 To 4 Step 2\r\n" + |
||||
" count += 1\r\n" + |
||||
" Next\r\n" + |
||||
" Return count\r\n" + |
||||
" End Function\r\n" + |
||||
"End Class\r\n"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetForNextWithStepToRuby() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string code = converter.Convert(vbnetForNextWithStepCode); |
||||
string expectedCode = |
||||
"class Foo\r\n" + |
||||
" def GetCount()\r\n" + |
||||
" count = 0\r\n" + |
||||
" i = 0\r\n" + |
||||
" while i <= 4\r\n" + |
||||
" count += 1\r\n" + |
||||
" i = i + 2\r\n" + |
||||
" end\r\n" + |
||||
" return count\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedCode, code); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class LocalVariableDefinitionsOnSameLineTests |
||||
{ |
||||
string csharp = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" public Foo()\r\n" + |
||||
" {\r\n" + |
||||
" int i = 0, i = 2;\r\n" + |
||||
" }\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertedRubyCode() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string Ruby = converter.Convert(csharp); |
||||
string expectedRuby = |
||||
"class Foo\r\n" + |
||||
" def initialize()\r\n" + |
||||
" i = 0\r\n" + |
||||
" i = 2\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedRuby, Ruby); |
||||
} |
||||
|
||||
string vnetClassWithTwoArrayLocalVariablesOnSameLine = |
||||
"class Foo\r\n" + |
||||
" Public Sub New()\r\n" + |
||||
" Dim i(10), j(20) as integer\r\n" + |
||||
" End Sub\r\n" + |
||||
"end class"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetClassWithTwoArrayVariablesOnSameLine() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string ruby = converter.Convert(vnetClassWithTwoArrayLocalVariablesOnSameLine); |
||||
string expectedRuby = |
||||
"class Foo\r\n" + |
||||
" def initialize()\r\n" + |
||||
" i = Array.CreateInstance(System::Int32, 10)\r\n" + |
||||
" j = Array.CreateInstance(System::Int32, 20)\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedRuby, ruby); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,115 @@
@@ -0,0 +1,115 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class MultipleFieldsOnSameLineTests |
||||
{ |
||||
string csharpClassWithFieldsThatHaveInitialValues = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" int i = 0, j = 1;\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertCSharpClassWithFieldsThatHaveInitialValues() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string ruby = converter.Convert(csharpClassWithFieldsThatHaveInitialValues); |
||||
string expectedRuby = |
||||
"class Foo\r\n" + |
||||
" def initialize()\r\n" + |
||||
" @i = 0\r\n" + |
||||
" @j = 1\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedRuby, ruby); |
||||
} |
||||
|
||||
string csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" int i, j = 1;\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertCSharpClassWithFieldsWhereFirstFieldDoesNotHaveInitialValue() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string ruby = converter.Convert(csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue); |
||||
string expectedRuby = |
||||
"class Foo\r\n" + |
||||
" def initialize()\r\n" + |
||||
" @j = 1\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedRuby, ruby); |
||||
} |
||||
|
||||
string csharpClassWithTwoFieldsInitializedInMethod = |
||||
"class Foo\r\n" + |
||||
"{\r\n" + |
||||
" int i = 0;\r\n" + |
||||
" int j, k;\r\n" + |
||||
"\r\n" + |
||||
" public void Test()\r\n" + |
||||
" {\r\n" + |
||||
" j = 1;\r\n" + |
||||
" k = 3;\r\n" + |
||||
" }\r\n" + |
||||
"}"; |
||||
|
||||
[Test] |
||||
public void ConvertCSharpClassWithTwoFieldsInitializedInMethod() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp); |
||||
converter.IndentString = " "; |
||||
string ruby = converter.Convert(csharpClassWithTwoFieldsInitializedInMethod); |
||||
string expectedRuby = |
||||
"class Foo\r\n" + |
||||
" def initialize()\r\n" + |
||||
" @i = 0\r\n" + |
||||
" end\r\n" + |
||||
"\r\n" + |
||||
" def Test()\r\n" + |
||||
" @j = 1\r\n" + |
||||
" @k = 3\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedRuby, ruby); |
||||
} |
||||
|
||||
string vnetClassWithTwoArrayFieldsOnSameLine = |
||||
"class Foo\r\n" + |
||||
" Private i(10), j(20) as integer\r\n" + |
||||
"end class"; |
||||
|
||||
[Test] |
||||
public void ConvertVBNetClassWithTwoArrayFieldsOnSameLine() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string ruby = converter.Convert(vnetClassWithTwoArrayFieldsOnSameLine); |
||||
string expectedRuby = |
||||
"class Foo\r\n" + |
||||
" def initialize()\r\n" + |
||||
" @i = Array.CreateInstance(System::Int32, 10)\r\n" + |
||||
" @j = Array.CreateInstance(System::Int32, 20)\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedRuby, ruby); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class VBExitConversionTests |
||||
{ |
||||
string vb = |
||||
"Public Class Class1\r\n" + |
||||
" Public Sub Test\r\n" + |
||||
" While True\r\n" + |
||||
" Exit While\r\n" + |
||||
" End While\r\n" + |
||||
" End Sub\r\n" + |
||||
"End Class\r\n"; |
||||
|
||||
[Test] |
||||
public void ConvertedRubyCode() |
||||
{ |
||||
NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet); |
||||
converter.IndentString = " "; |
||||
string ruby = converter.Convert(vb); |
||||
string expectedRuby = |
||||
"class Class1\r\n" + |
||||
" def Test()\r\n" + |
||||
" while true\r\n" + |
||||
" break\r\n" + |
||||
" end\r\n" + |
||||
" end\r\n" + |
||||
"end"; |
||||
|
||||
Assert.AreEqual(expectedRuby, ruby); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue