~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/MultipleFieldsOnSameLineTests.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
        [TestFixture]
 
12
        public class MultipleFieldsOnSameLineTests
 
13
        {
 
14
                string csharpClassWithFieldsThatHaveInitialValues =
 
15
                        "class Foo\r\n" +
 
16
                        "{\r\n" +
 
17
                        "    int i = 0, j = 1;\r\n" +
 
18
                        "}";
 
19
                
 
20
                [Test]
 
21
                public void ConvertCSharpClassWithFieldsThatHaveInitialValues()
 
22
                {
 
23
                        NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
 
24
                        converter.IndentString = "    ";
 
25
                        string python = converter.Convert(csharpClassWithFieldsThatHaveInitialValues);
 
26
                        string expectedPython =
 
27
                                "class Foo(object):\r\n" +
 
28
                                "    def __init__(self):\r\n" +
 
29
                                "        self._i = 0\r\n" +
 
30
                                "        self._j = 1";
 
31
                        
 
32
                        Assert.AreEqual(expectedPython, python);
 
33
                }
 
34
                
 
35
                string csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue =
 
36
                        "class Foo\r\n" +
 
37
                        "{\r\n" +
 
38
                        "    int i, j = 1;\r\n" +
 
39
                        "}";
 
40
                
 
41
                [Test]
 
42
                public void ConvertCSharpClassWithFieldsWhereFirstFieldDoesNotHaveInitialValue()
 
43
                {
 
44
                        NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
 
45
                        converter.IndentString = "    ";
 
46
                        string python = converter.Convert(csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue);
 
47
                        string expectedPython =
 
48
                                "class Foo(object):\r\n" +
 
49
                                "    def __init__(self):\r\n" +
 
50
                                "        self._j = 1";
 
51
                        
 
52
                        Assert.AreEqual(expectedPython, python);
 
53
                }
 
54
                
 
55
                string csharpClassWithTwoFieldsInitializedInMethod =
 
56
                        "class Foo\r\n" +
 
57
                        "{\r\n" +
 
58
                        "    int i = 0;\r\n" +
 
59
                        "    int j, k;\r\n" +
 
60
                        "\r\n" +
 
61
                        "    public void Test()\r\n" +
 
62
                        "    {\r\n" +
 
63
                        "        j = 1;\r\n" +
 
64
                        "        k = 3;\r\n" +
 
65
                        "    }\r\n" +
 
66
                        "}";
 
67
                
 
68
                [Test]
 
69
                public void ConvertCSharpClassWithTwoFieldsInitializedInMethod()
 
70
                {
 
71
                        NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
 
72
                        converter.IndentString = "    ";
 
73
                        string python = converter.Convert(csharpClassWithTwoFieldsInitializedInMethod);
 
74
                        string expectedPython =
 
75
                                "class Foo(object):\r\n" +
 
76
                                "    def __init__(self):\r\n" +
 
77
                                "        self._i = 0\r\n" +
 
78
                                "\r\n" +
 
79
                                "    def Test(self):\r\n" +
 
80
                                "        self._j = 1\r\n" +
 
81
                                "        self._k = 3";
 
82
                        
 
83
                        Assert.AreEqual(expectedPython, python);
 
84
                }
 
85
                
 
86
                string vnetClassWithTwoArrayFieldsOnSameLine =
 
87
                        "class Foo\r\n" +
 
88
                        "    Private i(10), j(20) as integer\r\n" +
 
89
                        "end class";
 
90
                
 
91
                [Test]
 
92
                public void ConvertVBNetClassWithTwoArrayFieldsOnSameLine()
 
93
                {
 
94
                        NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.VBNet);
 
95
                        converter.IndentString = "    ";
 
96
                        string python = converter.Convert(vnetClassWithTwoArrayFieldsOnSameLine);
 
97
                        string expectedPython =
 
98
                                "class Foo(object):\r\n" +
 
99
                                "    def __init__(self):\r\n" +
 
100
                                "        self._i = Array.CreateInstance(int, 10)\r\n" +
 
101
                                "        self._j = Array.CreateInstance(int, 20)";
 
102
                        
 
103
                        Assert.AreEqual(expectedPython, python);
 
104
                }
 
105
        }
 
106
}