public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tself._count = 0\r\n" + "\t\tself._i = 0\r\n" + "\r\n" + "\tdef get_Count(self):\r\n" + "\t\tif self._i == 0:\r\n" + "\t\t\treturn 10\r\n" + "\t\telse:\r\n" + "\t\t\treturn self._count\r\n" + "\r\n" + "\tdef set_Count(self, value):\r\n" + "\t\tif self._i == 1:\r\n" + "\t\t\tself._count = value\r\n" + "\t\telse:\r\n" + "\t\t\tself._count = value + 5\r\n" + "\r\n" + "\tCount = property(fget=get_Count, fset=set_Count)"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + " \"\"\" <summary>\r\n" + " Class Foo\r\n" + " </summary>\r\n" + " \"\"\"\r\n" + " def Run(self):\r\n" + " \"\"\" <summary>\r\n" + " Run\r\n" + " </summary>\r\n" + " \"\"\"\r\n" + " pass\r\n" + "\r\n" + " def Stop(self):\r\n" + " \"\"\" <summary> Stop </summary>\"\"\"\r\n" + " pass\r\n" + "\r\n" + " def __init__(self):\r\n" + " \"\"\" <summary> Initialize.</summary>\"\"\"\r\n" + " # Initialize j.\r\n" + " j = 0 # Set to zero\r\n" + " # test\r\n" + " if j == 0:\r\n" + " j = 2"; Assert.AreEqual(expectedPython, python, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Class1(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tself._name = String.Empty\r\n" + "\t\tself._lastName = String.Empty\r\n" + "\r\n" + "\tdef get_Name(self):\r\n" + "\t\treturn self._name\r\n" + "\r\n" + "\tdef set_Name(self, value):\r\n" + "\t\tself._name = value\r\n" + "\r\n" + "\tName = property(fget=get_Name, fset=set_Name)\r\n" + "\r\n" + "\tdef get_LastName(self):\r\n" + "\t\treturn self._lastName\r\n" + "\r\n" + "\tdef set_LastName(self, value):\r\n" + "\t\tself._lastName = value\r\n" + "\r\n" + "\tLastName = property(fget=get_LastName, fset=set_LastName)\r\n" + "\r\n" + "\tdef Clone(self):\r\n" + "\t\treturn Class1(Name = \"First\", LastName = \"Last\")"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tself._i = 0\r\n" + "\r\n" + "\tdef GetCount(self):\r\n" + "\t\tif self._i == 0:\r\n" + "\t\t\tif self._i == 0:\r\n" + "\t\t\t\tself._i = 10\r\n" + "\t\t\t\treturn 10\r\n" + "\t\t\telse:\r\n" + "\t\t\t\tself._i = 4\r\n" + "\t\t\t\treturn 4\r\n" + "\t\telse:\r\n" + "\t\t\tif self._i == 0:\r\n" + "\t\t\t\tself._i = 10\r\n" + "\t\t\t\treturn 10\r\n" + "\t\t\telse:\r\n" + "\t\t\t\tself._i = 4\r\n" + "\t\t\t\treturn 4"; Assert.AreEqual(expectedPython, python); }
public void GeneratedMainMethodCallWithNoParametersCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; converter.Convert(mainMethodWithNoParametersCode); string code = converter.GenerateMainMethodCall(converter.EntryPointMethods[0]); Assert.AreEqual("Foo.Main()", code); }
public void DivideOperator() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(GetCode(csharp, "/=")); string expectedPython = GetCode(pythonCodeTemplate, "/="); Assert.AreEqual(expectedPython, python); }
public void GeneratedPythonSourceCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n\tpass"; Assert.AreEqual(expectedPython, python); }
public void GeneratedPythonSourceCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.VBNet); string python = converter.Convert(vb); string expectedPython = "class Class1(object):\r\n" + "\tpass"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tSystem.Console.WriteLine(\"Test\")"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { string expectedCode = "class Foo(object):\r\n" + "\tdef Run(self):\r\n" + "\t\treturn self.ToString()"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string code = converter.Convert(csharp); Assert.AreEqual(expectedCode, code); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef GetCount(self):\r\n" + "\t\treturn 10"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tself._a = True"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCodeUsingFourSpacesAsIndent() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = new String(' ', 4); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + " pass"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef TestMe(self, test):\r\n" + "\t\ta = \"Ape\" if test else \"Monkey\"\r\n" + "\t\treturn a"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + " def IsEqual(self, o):\r\n" + " return Object.ReferenceEquals(o, None)"; Assert.AreEqual(expectedPython, python, python); }
public void GeneratedPythonSourceCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef Print(self):\r\n" + "\t\ti = 0\r\n" + "\t\tself.PrintInt(i)"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef CountDown(self):\r\n" + "\t\ti = 10\r\n" + "\t\twhile i > 0:\r\n" + "\t\t\ti -= 1"; Assert.AreEqual(expectedPython, python); }
public void Equals() { string code = GetCode(@"=="); NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string pythonCode = converter.Convert(code); string expectedPythonCode = "class Foo(object):\r\n" + "\tdef Run(self, i):\r\n" + "\t\tif i == 0:\r\n" + "\t\t\treturn 10\r\n" + "\t\treturn 0"; Assert.AreEqual(expectedPythonCode, pythonCode); }
public void ConvertedPythonCode() { string expectedPython = "class Foo(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tdoc = XmlDocument()\r\n" + "\t\tdoc.LoadXml(\"<root/>\")"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); Assert.AreEqual(expectedPython, python); }
public static bool Convert(SupportedLanguage inputLanguage, string ProvidedSource, out string ConvertedSource, out string ErrorMessage) { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(inputLanguage); string convertedCode = converter.Convert(ProvidedSource); ConvertedSource = convertedCode; ErrorMessage = ""; return true; }
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); }
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); }
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); }
public void GeneratedPythonSourceCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + " def Assign(self):\r\n" + " elements = Array.CreateInstance(int, 10)\r\n" + " list = List[Array[int]]()\r\n" + " list.Add(elements.Clone())"; Assert.AreEqual(expectedPython, python); }
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); }
public void ConvertedTypeOfIntegerCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string python = converter.Convert(typeofIntCode); string expectedPython = "import clr\r\n" + "\r\n" + "class Foo(object):\r\n" + " def ToString(self):\r\n" + " clr.GetClrType(int).FullName"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { string expectedCode = "class Foo(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tbutton = Button()\r\n" + "\t\tbutton.Click += self.ButtonClick\r\n" + "\r\n" + "\tdef ButtonClick(self, sender, e):\r\n" + "\t\tpass"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string code = converter.Convert(csharp); Assert.AreEqual(expectedCode, code); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string python = converter.Convert(csharp); string expectedPython = "from System.Collections.Generic import *\r\n" + "\r\n" + "class Foo(object):\r\n" + " def __init__(self):\r\n" + " list = List[str]()\r\n" + " dictionary = Dictionary[str, int]()"; Assert.AreEqual(expectedPython, python); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string code = converter.Convert(csharp); string expectedCode = "class Foo(object):\r\n" + "\tdef GetCount(self):\r\n" + "\t\tcount = 0\r\n" + "\t\ti = 0\r\n" + "\t\twhile i < 5:\r\n" + "\t\t\tcount += 1\r\n" + "\t\t\ti = i + 1\r\n" + "\t\treturn count"; Assert.AreEqual(expectedCode, code); }
public void ConvertedEnvironmentSpecialFolderCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string code = converter.Convert(environmentSpecialFolderCode); string expectedCode = "import clr\r\n" + "\r\n" + "class Foo(object):\r\n" + " def PrintEnvironmentVariables(self):\r\n" + " enumerator = Environment.SpecialFolder.GetValues(clr.GetClrType(Environment.SpecialFolder)).GetEnumerator()\r\n" + " while enumerator.MoveNext():\r\n" + " folder = enumerator.Current\r\n" + " Console.WriteLine(\"{0}={1}\\n\", folder, Environment.GetFolderPath(folder))"; Assert.AreEqual(expectedCode, code); }