~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/AddHandlerConversionTestFixture.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 that assigning a method to an event handler is converted
 
13
        /// from C# to Python correctly.
 
14
        /// </summary>
 
15
        [TestFixture]
 
16
        public class AddHandlerConversionTestFixture
 
17
        {               
 
18
                string csharp = "class Foo\r\n" +
 
19
                                                "{\r\n" +
 
20
                                                "\tpublic Foo()\r\n" +
 
21
                                                "\t{" +
 
22
                                                "\t\tbutton = new Button();\r\n" +
 
23
                                                "\t\tbutton.Click += ButtonClick;\r\n" +
 
24
                                                "\t\tbutton.MouseDown += self.OnMouseDown;\r\n" +
 
25
                                                "\t}\r\n" +
 
26
                                                "\r\n" +
 
27
                                                "\tvoid ButtonClick(object sender, EventArgs e)\r\n" +
 
28
                                                "\t{\r\n" +
 
29
                                                "\t}\r\n" +
 
30
                                                "\r\n" +
 
31
                                                "\tvoid OnMouseDown(object sender, EventArgs e)\r\n" +
 
32
                                                "\t{\r\n" +
 
33
                                                "\t}\r\n" +
 
34
                                                "}";
 
35
                                
 
36
                [Test]
 
37
                public void ConvertedPythonCode()
 
38
                {
 
39
                        string expectedCode = "class Foo(object):\r\n" +
 
40
                                                                        "\tdef __init__(self):\r\n" +
 
41
                                                                        "\t\tbutton = Button()\r\n" +
 
42
                                                                        "\t\tbutton.Click += self.ButtonClick\r\n" +
 
43
                                                                        "\t\tbutton.MouseDown += self.OnMouseDown\r\n" +
 
44
                                                                        "\r\n" +
 
45
                                                                        "\tdef ButtonClick(self, sender, e):\r\n" +
 
46
                                                                        "\t\tpass\r\n" +
 
47
                                                                        "\r\n" +
 
48
                                                                        "\tdef OnMouseDown(self, sender, e):\r\n" +
 
49
                                                                        "\t\tpass";
 
50
                        NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
 
51
                        string code = converter.Convert(csharp);
 
52
                        
 
53
                        Assert.AreEqual(expectedCode, code);
 
54
                }
 
55
        }
 
56
}