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 conversion of a for loop to Python.
16
/// for (int i = 0; i < 5; ++i) {
25
/// Ideally we would convert it to:
27
/// for i in range(0, 5):
31
public class ForLoopConversionTestFixture
33
string csharp = "class Foo\r\n" +
35
"\tpublic int GetCount()\r\n" +
37
"\t\tint count = 0;\r\n" +
38
"\t\tfor (int i = 0; i < 5; i = i + 1) {\r\n" +
39
"\t\t\tcount++;\r\n" +
41
"\t\treturn count;\r\n" +
46
public void ConvertedPythonCode()
48
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
49
string code = converter.Convert(csharp);
50
string expectedCode = "class Foo(object):\r\n" +
51
"\tdef GetCount(self):\r\n" +
54
"\t\twhile i < 5:\r\n" +
55
"\t\t\tcount += 1\r\n" +
56
"\t\t\ti = i + 1\r\n" +
59
Assert.AreEqual(expectedCode, code);