public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef GetCount(self, i):\r\n" + "\t\tif i == 0:\r\n" + "\t\t\treturn 10\r\n" + "\t\telif i < 1:\r\n" + "\t\t\treturn 4\r\n" + "\t\treturn 2"; Assert.AreEqual(expectedPython, python); }
protected void Run(IWorkbench workbench, ITextEditorProperties textEditorProperties) { // Get the code to convert. IViewContent viewContent = workbench.ActiveWorkbenchWindow.ActiveViewContent; IEditable editable = viewContent as IEditable; // Generate the python code. NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(viewContent.PrimaryFileName); converter.IndentString = NRefactoryToPythonConverter.GetIndentString(textEditorProperties); string pythonCode = converter.Convert(editable.Text); // Show the python code in a new window. NewFile("Generated.py", "Python", pythonCode); }
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 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 python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef Run(self):\r\n" + "\t\ti = 0\r\n" + "\t\twhile i < 10:\r\n" + "\t\t\tif i == 5:\r\n" + "\t\t\t\tbreak\r\n" + "\t\t\telse:\r\n" + "\t\t\t\tcontinue\r\n" + "\t\t\ti += 1"; Assert.AreEqual(expectedPython, python); }
public void ConvertedIntArrayCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string code = converter.Convert(intArrayCode); string expectedCode = "class Foo(object):\r\n" + " def GetCount(self, items):\r\n" + " count = 0\r\n" + " enumerator = items.GetEnumerator()\r\n" + " while enumerator.MoveNext():\r\n" + " item = enumerator.Current\r\n" + " count += 1\r\n" + " return count"; Assert.AreEqual(expectedCode, code); }
public void ConvertedCode() { string expectedPython = "class Loader(object):\r\n" + "\tdef load(self, xml):\r\n" + "\t\ttry:\r\n" + "\t\t\tdoc = XmlDocument()\r\n" + "\t\t\tdoc.LoadXml(xml)\r\n" + "\t\texcept XmlException, ex:\r\n" + "\t\t\tConsole.WriteLine(ex.ToString())\r\n" + "\t\tfinally:\r\n" + "\t\t\tConsole.WriteLine(xml)"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); Assert.AreEqual(expectedPython, python); }
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); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "class Foo(object):\r\n" + "\tdef Run(self):\r\n" + "\t\tpass\r\n" + "\r\n" + "\tclass Bar(object):\r\n" + "\t\tdef Test(self):\r\n" + "\t\t\tpass\r\n" + "\r\n" + "\tdef AnotherRun(self):\r\n" + "\t\tpass"; Assert.AreEqual(expectedPython, python); }
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); }
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); }
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" + "\t\tbutton.MouseDown += self.OnMouseDown\r\n" + "\r\n" + "\tdef ButtonClick(self, sender, e):\r\n" + "\t\tpass\r\n" + "\r\n" + "\tdef OnMouseDown(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); 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\tj = 10\r\n" + "\t\t\treturn j\r\n" + "\t\telse:\r\n" + "\t\t\tj = 4\r\n" + "\t\t\treturn j"; Assert.AreEqual(expectedPython, python); }
public void MultipleUsingStatements() { string csharp = "using System\r\n" + "using System.Drawing\r\n" + "class Foo\r\n" + "{\r\n" + "}"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string python = converter.Convert(csharp); string expectedPython = "from System import *\r\n" + "from System.Drawing import *\r\n" + "\r\n" + "class Foo(object):\r\n" + "\tpass"; 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" + " self._count = 0\r\n" + " self._i = 0\r\n" + "\r\n" + " def set_Count(self, value):\r\n" + " self._count = value\r\n" + "\r\n" + " Count = property(fset=set_Count)"; Assert.AreEqual(expectedPython, python, python); }
public void ConvertedDictionaryCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string code = converter.Convert(dictionaryCode); string expectedCode = "class Foo(object):\r\n" + " def DisplayItems(self):\r\n" + " record = Dictionary[str, str]()\r\n" + " record.Add(\"a\", \"b\")\r\n" + " record.Add(\"c\", \"d\")\r\n" + " enumerator = record.Keys.GetEnumerator()\r\n" + " while enumerator.MoveNext():\r\n" + " key = enumerator.Current\r\n" + " Console.WriteLine(\"Key: \" + key)"; Assert.AreEqual(expectedCode, code); }
public void SwitchStatement() { string csharp = "class Foo\r\n" + "{\r\n" + " public int Run(int i)\r\n" + " {\r\n" + " switch (i) {\r\n" + " case 7:\r\n" + " i = 4;\r\n" + " break;\r\n" + " case 10:\r\n" + " return 0;\r\n" + " case 9:\r\n" + " return 2;\r\n" + " case 8:\r\n" + " break;\r\n" + " default:\r\n" + " return -1;\r\n" + " }\r\n" + " return i;\r\n" + " }\r\n" + "}"; string expectedPython = "class Foo(object):\r\n" + " def Run(self, i):\r\n" + " if i == 7:\r\n" + " i = 4\r\n" + " elif i == 10:\r\n" + " return 0\r\n" + " elif i == 9:\r\n" + " return 2\r\n" + " elif i == 8:\r\n" + " pass\r\n" + " else:\r\n" + " return -1\r\n" + " return i"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string code = converter.Convert(csharp); Assert.AreEqual(expectedPython, code, code); }
public void MinusOne() { string csharp = "class Foo\r\n" + "{\r\n" + " public void Run(int i)\r\n" + " {\r\n" + " i = -1;\r\n" + " }\r\n" + "}"; string expectedPython = "class Foo(object):\r\n" + "\tdef Run(self, i):\r\n" + "\t\ti = -1"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string code = converter.Convert(csharp); Assert.AreEqual(expectedPython, code); }
public void BitwiseNotOperator() { string csharp = "class Foo\r\n" + "{\r\n" + " public void Run(bool i)\r\n" + " {\r\n" + " j = ~i;\r\n" + " }\r\n" + "}"; string expectedPython = "class Foo(object):\r\n" + "\tdef Run(self, i):\r\n" + "\t\tj = ~i"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string code = converter.Convert(csharp); Assert.AreEqual(expectedPython, code); }
public void PostDecrement() { string csharp = "class Foo\r\n" + "{\r\n" + "\tpublic void Run(int i)\r\n" + "\t{\r\n" + "\t\ti--\r\n" + "\t}\r\n" + "}"; string expectedPython = "class Foo(object):\r\n" + "\tdef Run(self, i):\r\n" + "\t\ti -= 1"; NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string code = converter.Convert(csharp); Assert.AreEqual(expectedPython, code); }
public void ConvertedPythonCode() { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; string python = converter.Convert(csharp); string expectedPython = "# \r\n" + "# Class Foo\r\n" + "# \r\n" + "class Foo(object):\r\n" + " # Initialize.\r\n" + " def __init__(self):\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 Foo(object):\r\n" + "\tdef __init__(self):\r\n" + "\t\tself._count = 0\r\n" + "\r\n" + "\tdef get_Count(self):\r\n" + "\t\treturn self._count\r\n" + "\r\n" + "\tdef set_Count(self, value):\r\n" + "\t\tself._count = value\r\n" + "\r\n" + "\tCount = property(fget=get_Count, fset=set_Count)\r\n" + "\r\n" + "\tdef Run(self):\r\n" + "\t\tpass"; 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" + " self._count = 0\r\n" + "\r\n" + " def get_Count(self):\r\n" + " return self._count\r\n" + "\r\n" + " Count = property(fget=get_Count)\r\n" + "\r\n" + " def Increment(self):\r\n" + " self.Count += 1\r\n" + "\r\n" + " def SetCount(self, Count):\r\n" + " self.Count = Count"; Assert.AreEqual(expectedPython, python, python); }
public void Init() { converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); converter.IndentString = " "; python = converter.Convert(csharp); }