~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForLoopConversionTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using ICSharpCode.NRefactory;
 
6
using ICSharpCode.PythonBinding;
 
7
using NUnit.Framework;
 
8
 
 
9
namespace PythonBinding.Tests.Converter
 
10
{
 
11
        /// <summary>
 
12
        /// Tests the conversion of a for loop to Python. 
 
13
        /// 
 
14
        /// C#:
 
15
        /// 
 
16
        /// for (int i = 0; i &lt; 5; ++i) {
 
17
        /// }
 
18
        /// 
 
19
        /// Python:
 
20
        /// 
 
21
        /// i = 0
 
22
        /// while i &lt; 5
 
23
        ///     i = i + 1
 
24
        /// 
 
25
        /// Ideally we would convert it to:
 
26
        /// 
 
27
        /// for i in range(0, 5):
 
28
        ///     pass
 
29
        /// </summary>
 
30
        [TestFixture]
 
31
        public class ForLoopConversionTestFixture
 
32
        {
 
33
                string csharp = "class Foo\r\n" +
 
34
                                        "{\r\n" +
 
35
                                        "\tpublic int GetCount()\r\n" +
 
36
                                        "\t{\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" +
 
40
                                        "\t\t}\r\n" +
 
41
                                        "\t\treturn count;\r\n" +
 
42
                                        "\t}\r\n" +
 
43
                                        "}";
 
44
 
 
45
                [Test]
 
46
                public void ConvertedPythonCode()
 
47
                {
 
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" +
 
52
                                                                        "\t\tcount = 0\r\n" +
 
53
                                                                        "\t\ti = 0\r\n" +
 
54
                                                                        "\t\twhile i < 5:\r\n" +
 
55
                                                                        "\t\t\tcount += 1\r\n" +
 
56
                                                                        "\t\t\ti = i + 1\r\n" +
 
57
                                                                        "\t\treturn count";
 
58
                        
 
59
                        Assert.AreEqual(expectedCode, code);
 
60
                }
 
61
        }
 
62
}