~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/PropertyWithGetSetStatementsTestfixture.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 CSharpToPythonConverter class can convert a C# property to
 
13
        /// two get and set methods in Python.
 
14
        /// </summary>
 
15
        [TestFixture]
 
16
        public class PropertyWithGetSetStatementsTestFixture
 
17
        {
 
18
                string csharp = "class Foo\r\n" +
 
19
                                                "{\r\n" +
 
20
                                                "\tint count = 0;\r\n" +
 
21
                                                "\tint i = 0;\r\n" +
 
22
                                                "\tpublic int Count\r\n" +
 
23
                                                "\t{\r\n" +
 
24
                                                "\t\tget {\r\n" +
 
25
                                                "\t\t\tif (i == 0) {\r\n" +
 
26
                                                "\t\t\treturn 10;\r\n" +
 
27
                                                "\t\t} else {\r\n" +
 
28
                                                "\t\t\treturn count;\r\n" +
 
29
                                                "\t\t}\r\n" +
 
30
                                                "\t}\r\n" +
 
31
                                                "\t\tset {\r\n" +
 
32
                                                "\t\t\tif (i == 1) {\r\n" +
 
33
                                                "\t\t\tcount = value;\r\n" +
 
34
                                                "\t\t} else {\r\n" +
 
35
                                                "\t\t\tcount = value + 5;\r\n" +
 
36
                                                "\t\t}\r\n" +
 
37
                                                "\t}\r\n" +
 
38
                                                "}";
 
39
                        
 
40
                [Test]
 
41
                public void ConvertedPythonCode()
 
42
                {
 
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" +
 
49
                                                                        "\r\n" +
 
50
                                                                        "\tdef get_Count(self):\r\n" +
 
51
                                                                        "\t\tif self._i == 0:\r\n" +
 
52
                                                                        "\t\t\treturn 10\r\n" +
 
53
                                                                        "\t\telse:\r\n" +
 
54
                                                                        "\t\t\treturn self._count\r\n" +
 
55
                                                                        "\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" +
 
59
                                                                        "\t\telse:\r\n" +
 
60
                                                                        "\t\t\tself._count = value + 5\r\n" +
 
61
                                                                        "\r\n" +
 
62
                                                                        "\tCount = property(fget=get_Count, fset=set_Count)";
 
63
                        
 
64
                        Assert.AreEqual(expectedPython, python);
 
65
                }                       
 
66
        }
 
67
}