Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4761 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
4 changed files with 142 additions and 12 deletions
@ -0,0 +1,55 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.NRefactory; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Converter |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class PropertyWithGetterTestFixture |
||||||
|
{ |
||||||
|
string csharp = "class Foo\r\n" + |
||||||
|
"{\r\n" + |
||||||
|
" int count = 0;\r\n" + |
||||||
|
" int i = 0;\r\n" + |
||||||
|
" public int Count {\r\n" + |
||||||
|
" get {\r\n" + |
||||||
|
" if (i == 0) {\r\n" + |
||||||
|
" return 10;\r\n" + |
||||||
|
" } else {\r\n" + |
||||||
|
" return count;\r\n" + |
||||||
|
" }\r\n" + |
||||||
|
" }\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" + |
||||||
|
" self._count = 0\r\n" + |
||||||
|
" self._i = 0\r\n" + |
||||||
|
"\r\n" + |
||||||
|
" def get_Count(self):\r\n" + |
||||||
|
" if self._i == 0:\r\n" + |
||||||
|
" return 10\r\n" + |
||||||
|
" else:\r\n" + |
||||||
|
" return self._count\r\n" + |
||||||
|
"\r\n" + |
||||||
|
" Count = property(fget=get_Count)"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedPython, python, python); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.NRefactory; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Converter |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class PropertyWithSetterTestFixture |
||||||
|
{ |
||||||
|
string csharp = "class Foo\r\n" + |
||||||
|
"{\r\n" + |
||||||
|
" int count = 0;\r\n" + |
||||||
|
" int i = 0;\r\n" + |
||||||
|
" public int Count {\r\n" + |
||||||
|
" set {\r\n" + |
||||||
|
" count = value;\r\n" + |
||||||
|
" }\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" + |
||||||
|
" 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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue