1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using ICSharpCode.NRefactory;
6
using ICSharpCode.PythonBinding;
9
namespace PythonBinding.Tests.Converter
12
/// Tests the CSharpToPythonConverter class can convert a C# property to
13
/// two get and set methods in Python.
16
public class PropertyWithGetSetStatementsTestFixture
18
string csharp = "class Foo\r\n" +
20
"\tint count = 0;\r\n" +
22
"\tpublic int Count\r\n" +
25
"\t\t\tif (i == 0) {\r\n" +
26
"\t\t\treturn 10;\r\n" +
28
"\t\t\treturn count;\r\n" +
32
"\t\t\tif (i == 1) {\r\n" +
33
"\t\t\tcount = value;\r\n" +
35
"\t\t\tcount = value + 5;\r\n" +
41
public void ConvertedPythonCode()
43
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
44
string python = converter.Convert(csharp);
45
string expectedPython = "class Foo(object):\r\n" +
46
"\tdef __init__(self):\r\n" +
47
"\t\tself._count = 0\r\n" +
48
"\t\tself._i = 0\r\n" +
50
"\tdef get_Count(self):\r\n" +
51
"\t\tif self._i == 0:\r\n" +
52
"\t\t\treturn 10\r\n" +
54
"\t\t\treturn self._count\r\n" +
56
"\tdef set_Count(self, value):\r\n" +
57
"\t\tif self._i == 1:\r\n" +
58
"\t\t\tself._count = value\r\n" +
60
"\t\t\tself._count = value + 5\r\n" +
62
"\tCount = property(fget=get_Count, fset=set_Count)";
64
Assert.AreEqual(expectedPython, python);