~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/NoNewLineAfterInitializeComponentMethodTestFixture.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 System.CodeDom;
 
6
using System.ComponentModel;
 
7
using System.ComponentModel.Design;
 
8
using System.ComponentModel.Design.Serialization;
 
9
using System.Drawing;
 
10
using System.IO;
 
11
using System.Windows.Forms;
 
12
 
 
13
using ICSharpCode.AvalonEdit.Document;
 
14
using ICSharpCode.RubyBinding;
 
15
using ICSharpCode.Scripting.Tests.Utils;
 
16
using ICSharpCode.SharpDevelop.Dom;
 
17
using ICSharpCode.SharpDevelop.Editor;
 
18
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
 
19
using ICSharpCode.SharpDevelop.Refactoring;
 
20
using NUnit.Framework;
 
21
using RubyBinding.Tests.Utils;
 
22
using AvalonEdit = ICSharpCode.AvalonEdit;
 
23
 
 
24
namespace RubyBinding.Tests.Designer
 
25
{
 
26
        /// <summary>
 
27
        /// Tests the code can be generated if there is no new line after the InitializeComponent method.
 
28
        /// </summary>
 
29
        [TestFixture]
 
30
        public class NoNewLineAfterInitializeComponentMethodTestFixture
 
31
        {
 
32
                TextDocument document;
 
33
                
 
34
                [TestFixtureSetUp]
 
35
                public void SetUpFixture()
 
36
                {
 
37
                        AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
 
38
                        document = textEditor.Document;
 
39
                        textEditor.Text = GetTextEditorCode();
 
40
 
 
41
                        RubyParser parser = new RubyParser();
 
42
                        ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text);
 
43
 
 
44
                        using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) {
 
45
                                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
 
46
                                UserControl userControl = (UserControl)host.RootComponent;                      
 
47
                                userControl.ClientSize = new Size(489, 389);
 
48
                                
 
49
                                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl);
 
50
                                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
 
51
                                namePropertyDescriptor.SetValue(userControl, "userControl1");
 
52
                                
 
53
                                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
 
54
                                using (serializationManager.CreateSession()) {
 
55
                                        AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null);
 
56
                                        RubyDesignerGenerator generator = new RubyDesignerGenerator(new MockTextEditorOptions());
 
57
                                        generator.Merge(host, docAdapter, compilationUnit, serializationManager);
 
58
                                }
 
59
                        }
 
60
                }
 
61
                
 
62
                [Test]
 
63
                public void GeneratedCode()
 
64
                {
 
65
                        string expectedCode =
 
66
                                "require \"System.Windows.Forms\"\r\n" +
 
67
                                "\r\n" +
 
68
                                "class MyUserControl < UserControl\r\n" +
 
69
                                "\tdef initialize()\r\n" +
 
70
                                "\t\tself.InitializeComponent()\r\n" +
 
71
                                "\tend\r\n" +
 
72
                                "\r\n" +
 
73
                                "\tdef InitializeComponent()\r\n" +
 
74
                                "\t\tself.SuspendLayout()\r\n" +
 
75
                                "\t\t# \r\n" +
 
76
                                "\t\t# userControl1\r\n" +
 
77
                                "\t\t# \r\n" + 
 
78
                                "\t\tself.Name = \"userControl1\"\r\n" +
 
79
                                "\t\tself.Size = System::Drawing::Size.new(489, 389)\r\n" +
 
80
                                "\t\tself.ResumeLayout(false)\r\n" +
 
81
                                "\tend\r\n" +
 
82
                                "end";
 
83
                        
 
84
                        Assert.AreEqual(expectedCode, document.Text);
 
85
                }
 
86
                
 
87
                /// <summary>
 
88
                /// No new line after the pass statement for InitializeComponent method.
 
89
                /// </summary>
 
90
                string GetTextEditorCode()
 
91
                {
 
92
                        return
 
93
                                "require \"System.Windows.Forms\"\r\n" +
 
94
                                "\r\n" +
 
95
                                "class MyUserControl < UserControl\r\n" +
 
96
                                "\tdef initialize()\r\n" +
 
97
                                "\t\tself.InitializeComponent()\r\n" +
 
98
                                "\tend\r\n" +
 
99
                                "\r\n" +
 
100
                                "\tdef InitializeComponent()\r\n" +
 
101
                                "\tend\r\n" +
 
102
                                "end";
 
103
                }
 
104
        }
 
105
}