22 changed files with 470 additions and 804 deletions
@ -1,125 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.CodeDom; |
|
||||||
using System.CodeDom.Compiler; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.ComponentModel.Design.Serialization; |
|
||||||
using System.Drawing; |
|
||||||
using System.IO; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.FormsDesigner; |
|
||||||
using ICSharpCode.PythonBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using NUnit.Framework; |
|
||||||
using PythonBinding.Tests.Utils; |
|
||||||
using UnitTesting.Tests.Utils; |
|
||||||
|
|
||||||
namespace PythonBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that the PythonDesignerGenerator's MergeFormChanges
|
|
||||||
/// finds the InitializeComponents method and the class.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class GeneratorMergeFindsInitializeComponentsTestFixture |
|
||||||
{ |
|
||||||
DerivedPythonDesignerGenerator generator; |
|
||||||
FormsDesignerViewContent viewContent; |
|
||||||
FormsDesignerViewContent viewContentAttached; |
|
||||||
MockTextEditorViewContent mockViewContent; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
generator = new DerivedPythonDesignerGenerator(); |
|
||||||
mockViewContent = new MockTextEditorViewContent(); |
|
||||||
viewContent = new FormsDesignerViewContent(mockViewContent, new MockOpenedFile("Test.py")); |
|
||||||
viewContent.DesignerCodeFileContent = GetTextEditorCode(); |
|
||||||
generator.Attach(viewContent); |
|
||||||
viewContentAttached = generator.GetViewContent(); |
|
||||||
|
|
||||||
PythonParser parser = new PythonParser(); |
|
||||||
ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), "Test.py", GetTextEditorCode()); |
|
||||||
ParseInformation parseInfo = new ParseInformation(parserCompilationUnit); |
|
||||||
generator.ParseInfoToReturnFromParseFileMethod = parseInfo; |
|
||||||
|
|
||||||
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
|
||||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
|
||||||
Form form = (Form)host.RootComponent; |
|
||||||
form.ClientSize = new Size(499, 309); |
|
||||||
|
|
||||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
|
||||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
|
||||||
namePropertyDescriptor.SetValue(form, "MainForm"); |
|
||||||
|
|
||||||
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
|
||||||
using (serializationManager.CreateSession()) { |
|
||||||
generator.MergeRootComponentChanges(host, serializationManager); |
|
||||||
generator.Detach(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void GetDomRegion() |
|
||||||
{ |
|
||||||
MockMethod method = new MockMethod(MockClass.CreateMockClassWithoutAnyAttributes()); |
|
||||||
DomRegion bodyRegion = new DomRegion(0, 4, 1, 4); |
|
||||||
method.BodyRegion = bodyRegion; |
|
||||||
DomRegion expectedRegion = new DomRegion(bodyRegion.BeginLine + 1, 1, bodyRegion.EndLine + 1, 1); |
|
||||||
|
|
||||||
PythonDesignerGenerator generator = new PythonDesignerGenerator(new MockTextEditorOptions()); |
|
||||||
Assert.AreEqual(expectedRegion, generator.GetBodyRegionInDocument(method)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void ViewContentSetToNullAfterDetach() |
|
||||||
{ |
|
||||||
Assert.IsNull(generator.GetViewContent()); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void ViewContentAttached() |
|
||||||
{ |
|
||||||
Assert.AreSame(viewContent, viewContentAttached); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void DocumentUpdated() |
|
||||||
{ |
|
||||||
string expectedText = "from System.Windows.Forms import Form\r\n" + |
|
||||||
"\r\n" + |
|
||||||
"class MainForm(Form):\r\n" + |
|
||||||
"\tdef __init__(self):\r\n" + |
|
||||||
"\t\tself.InitializeComponents()\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef InitializeComponents(self):\r\n" + |
|
||||||
"\t\tself.SuspendLayout()\r\n" + |
|
||||||
"\t\t# \r\n" + |
|
||||||
"\t\t# MainForm\r\n" + |
|
||||||
"\t\t# \r\n" + |
|
||||||
"\t\tself.ClientSize = System.Drawing.Size(499, 309)\r\n" + |
|
||||||
"\t\tself.Name = \"MainForm\"\r\n" + |
|
||||||
"\t\tself.ResumeLayout(False)\r\n"; |
|
||||||
|
|
||||||
Assert.AreEqual(expectedText, viewContent.DesignerCodeFileContent); |
|
||||||
} |
|
||||||
|
|
||||||
string GetTextEditorCode() |
|
||||||
{ |
|
||||||
return "from System.Windows.Forms import Form\r\n" + |
|
||||||
"\r\n" + |
|
||||||
"class MainForm(Form):\r\n" + |
|
||||||
"\tdef __init__(self):\r\n" + |
|
||||||
"\t\tself.InitializeComponents()\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef InitializeComponents(self):\r\n" + |
|
||||||
"\t\tpass\r\n"; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,79 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.CodeDom; |
|
||||||
using System.CodeDom.Compiler; |
|
||||||
using System.Collections; |
|
||||||
using System.IO; |
|
||||||
|
|
||||||
using ICSharpCode.PythonBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using NUnit.Framework; |
|
||||||
using PythonBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace PythonBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that one method is found to be that could
|
|
||||||
/// be used as a event handler.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class OneCompatibleMethodTestFixture |
|
||||||
{ |
|
||||||
ICollection compatibleMethods; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
DerivedPythonDesignerGenerator generator = new DerivedPythonDesignerGenerator(); |
|
||||||
MockTextEditorViewContent mockViewContent = new MockTextEditorViewContent(); |
|
||||||
DerivedFormDesignerViewContent viewContent = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile("Test.py")); |
|
||||||
viewContent.DesignerCodeFileContent = GetTextEditorCode(); |
|
||||||
|
|
||||||
// Create parse info.
|
|
||||||
PythonParser parser = new PythonParser(); |
|
||||||
ICompilationUnit unit = parser.Parse(new MockProjectContent(), @"C:\Projects\MyProject\test.py", GetTextEditorCode()); |
|
||||||
ParseInformation parseInfo = new ParseInformation(unit); |
|
||||||
generator.ParseInfoToReturnFromParseFileMethod = parseInfo; |
|
||||||
|
|
||||||
// Attach view content to generator.
|
|
||||||
generator.Attach(viewContent); |
|
||||||
|
|
||||||
// Get compatible methods for event.
|
|
||||||
MockEventDescriptor eventDescriptor = new MockEventDescriptor("Click"); |
|
||||||
compatibleMethods = generator.GetCompatibleMethods(eventDescriptor); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void OneCompatibleMethod() |
|
||||||
{ |
|
||||||
Assert.AreEqual(1, compatibleMethods.Count); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CompatibleMethodName() |
|
||||||
{ |
|
||||||
IEnumerator enumerator = compatibleMethods.GetEnumerator(); |
|
||||||
enumerator.MoveNext(); |
|
||||||
Assert.AreEqual("button1_click", (string)enumerator.Current); |
|
||||||
} |
|
||||||
|
|
||||||
string GetTextEditorCode() |
|
||||||
{ |
|
||||||
return "from System.Windows.Forms import Form\r\n" + |
|
||||||
"\r\n" + |
|
||||||
"class MainForm(Form):\r\n" + |
|
||||||
"\tdef __init__(self):\r\n" + |
|
||||||
"\t\tself.InitializeComponents()\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef InitializeComponents(self):\r\n" + |
|
||||||
"\t\tself._button1 = System.Windows.Forms.Button()\r\n" + |
|
||||||
"\t\tself.Controls.Add(self._button1)\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef button1_click(self, sender, e):\r\n" + |
|
||||||
"\t\tpass"; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,90 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.ComponentModel.Design.Serialization; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.FormsDesigner; |
|
||||||
using ICSharpCode.PythonBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using ICSharpCode.SharpDevelop.Editor; |
|
||||||
using NUnit.Framework; |
|
||||||
using PythonBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace PythonBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that the indent information in the ITextEditorProperties is passed to the generator.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class TextEditorIndentPassedToGeneratorTestFixture |
|
||||||
{ |
|
||||||
IDocument document; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
using (FormsDesignerViewContent viewContent = new FormsDesignerViewContent(new MockViewContent(), new MockOpenedFile("Test.py"))) { |
|
||||||
viewContent.DesignerCodeFileContent = "class MainForm(Form):\r\n" + |
|
||||||
" def __init__(self):\r\n" + |
|
||||||
" self.InitializeComponent()\r\n" + |
|
||||||
"\r\n" + |
|
||||||
" def InitializeComponent(self):\r\n" + |
|
||||||
" pass\r\n"; |
|
||||||
|
|
||||||
document = viewContent.DesignerCodeFileDocument; |
|
||||||
|
|
||||||
PythonParser parser = new PythonParser(); |
|
||||||
ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text); |
|
||||||
ParseInformation parseInfo = new ParseInformation(compilationUnit); |
|
||||||
|
|
||||||
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
|
||||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
|
||||||
Form form = (Form)host.RootComponent; |
|
||||||
form.ClientSize = new Size(284, 264); |
|
||||||
|
|
||||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
|
||||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
|
||||||
namePropertyDescriptor.SetValue(form, "MainForm"); |
|
||||||
|
|
||||||
MockTextEditorOptions textEditorOptions = new MockTextEditorOptions(); |
|
||||||
textEditorOptions.ConvertTabsToSpaces = true; |
|
||||||
textEditorOptions.IndentationSize = 1; |
|
||||||
|
|
||||||
DerivedPythonDesignerGenerator generator = new DerivedPythonDesignerGenerator(textEditorOptions); |
|
||||||
generator.ParseInfoToReturnFromParseFileMethod = parseInfo; |
|
||||||
generator.Attach(viewContent); |
|
||||||
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
|
||||||
using (serializationManager.CreateSession()) { |
|
||||||
generator.MergeRootComponentChanges(host, serializationManager); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void GeneratedCode() |
|
||||||
{ |
|
||||||
string expectedCode = |
|
||||||
"class MainForm(Form):\r\n" + |
|
||||||
" def __init__(self):\r\n" + |
|
||||||
" self.InitializeComponent()\r\n" + |
|
||||||
"\r\n" + |
|
||||||
" def InitializeComponent(self):\r\n" + |
|
||||||
" self.SuspendLayout()\r\n" + |
|
||||||
" # \r\n" + |
|
||||||
" # MainForm\r\n" + |
|
||||||
" # \r\n" + |
|
||||||
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
|
||||||
" self.Name = \"MainForm\"\r\n" + |
|
||||||
" self.ResumeLayout(False)\r\n"; |
|
||||||
|
|
||||||
Assert.AreEqual(expectedCode, document.Text); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,133 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.CodeDom; |
|
||||||
using System.CodeDom.Compiler; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.ComponentModel.Design.Serialization; |
|
||||||
using System.Drawing; |
|
||||||
using System.IO; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.FormsDesigner; |
|
||||||
using ICSharpCode.RubyBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using NUnit.Framework; |
|
||||||
using RubyBinding.Tests.Utils; |
|
||||||
using UnitTesting.Tests.Utils; |
|
||||||
|
|
||||||
namespace RubyBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that the RubyDesignerGenerator's MergeFormChanges
|
|
||||||
/// finds the InitializeComponents method and the class.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class GeneratorMergeFindsInitializeComponentsTestFixture |
|
||||||
{ |
|
||||||
DerivedRubyDesignerGenerator generator; |
|
||||||
FormsDesignerViewContent viewContent; |
|
||||||
FormsDesignerViewContent viewContentAttached; |
|
||||||
MockTextEditorViewContent mockViewContent; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
generator = new DerivedRubyDesignerGenerator(); |
|
||||||
mockViewContent = new MockTextEditorViewContent(); |
|
||||||
viewContent = new FormsDesignerViewContent(mockViewContent, new MockOpenedFile("Test.rb")); |
|
||||||
viewContent.DesignerCodeFileContent = GetTextEditorCode(); |
|
||||||
generator.Attach(viewContent); |
|
||||||
viewContentAttached = generator.GetViewContent(); |
|
||||||
|
|
||||||
RubyParser parser = new RubyParser(); |
|
||||||
ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), "Test.rb", GetTextEditorCode()); |
|
||||||
ParseInformation parseInfo = new ParseInformation(parserCompilationUnit); |
|
||||||
generator.ParseInfoToReturnFromParseFileMethod = parseInfo; |
|
||||||
|
|
||||||
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
|
||||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
|
||||||
Form form = (Form)host.RootComponent; |
|
||||||
form.ClientSize = new Size(499, 309); |
|
||||||
|
|
||||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
|
||||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
|
||||||
namePropertyDescriptor.SetValue(form, "MainForm"); |
|
||||||
|
|
||||||
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
|
||||||
using (serializationManager.CreateSession()) { |
|
||||||
generator.MergeRootComponentChanges(host, serializationManager); |
|
||||||
generator.Detach(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void GetDomRegion() |
|
||||||
{ |
|
||||||
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
|
||||||
DomRegion bodyRegion = new DomRegion(0, 4, 1, 4); |
|
||||||
method.BodyRegion = bodyRegion; |
|
||||||
DomRegion expectedRegion = new DomRegion(bodyRegion.BeginLine + 1, 1, bodyRegion.EndLine, 1); |
|
||||||
|
|
||||||
Assert.AreEqual(expectedRegion, generator.GetBodyRegionInDocument(method)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void ViewContentSetToNullAfterDetach() |
|
||||||
{ |
|
||||||
Assert.IsNull(generator.GetViewContent()); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void ViewContentAttached() |
|
||||||
{ |
|
||||||
Assert.AreSame(viewContent, viewContentAttached); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void DocumentUpdated() |
|
||||||
{ |
|
||||||
string expectedText = "require \"mscorlib\"\r\n" + |
|
||||||
"require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n" + |
|
||||||
"require \"System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\r\n" + |
|
||||||
"\r\n" + |
|
||||||
"class MainForm < System::Windows::Forms::Form\r\n" + |
|
||||||
"\tdef initialize()\r\n" + |
|
||||||
"\t\tself.InitializeComponents()\r\n" + |
|
||||||
"\tend\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef InitializeComponents()\r\n" + |
|
||||||
"\t\tself.SuspendLayout()\r\n" + |
|
||||||
"\t\t# \r\n" + |
|
||||||
"\t\t# MainForm\r\n" + |
|
||||||
"\t\t# \r\n" + |
|
||||||
"\t\tself.ClientSize = System::Drawing::Size.new(499, 309)\r\n" + |
|
||||||
"\t\tself.Name = \"MainForm\"\r\n" + |
|
||||||
"\t\tself.ResumeLayout(false)\r\n" + |
|
||||||
"\tend\r\n" + |
|
||||||
"end"; |
|
||||||
|
|
||||||
Assert.AreEqual(expectedText, viewContent.DesignerCodeFileContent); |
|
||||||
} |
|
||||||
|
|
||||||
string GetTextEditorCode() |
|
||||||
{ |
|
||||||
return "require \"mscorlib\"\r\n" + |
|
||||||
"require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n" + |
|
||||||
"require \"System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\r\n" + |
|
||||||
"\r\n" + |
|
||||||
"class MainForm < System::Windows::Forms::Form\r\n" + |
|
||||||
"\tdef initialize()\r\n" + |
|
||||||
"\t\tself.InitializeComponents()\r\n" + |
|
||||||
"\tend\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef InitializeComponents()\r\n" + |
|
||||||
"\tend\r\n" + |
|
||||||
"end"; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,80 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.CodeDom; |
|
||||||
using System.CodeDom.Compiler; |
|
||||||
using System.Collections; |
|
||||||
using System.IO; |
|
||||||
|
|
||||||
using ICSharpCode.RubyBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using NUnit.Framework; |
|
||||||
using RubyBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace RubyBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that one method is found to be that could
|
|
||||||
/// be used as a event handler.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class OneCompatibleMethodTestFixture |
|
||||||
{ |
|
||||||
ICollection compatibleMethods; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
DerivedRubyDesignerGenerator generator = new DerivedRubyDesignerGenerator(); |
|
||||||
MockTextEditorViewContent mockViewContent = new MockTextEditorViewContent(); |
|
||||||
DerivedFormDesignerViewContent viewContent = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile("Test.rb")); |
|
||||||
viewContent.DesignerCodeFileContent = GetTextEditorCode(); |
|
||||||
|
|
||||||
// Create parse info.
|
|
||||||
RubyParser parser = new RubyParser(); |
|
||||||
ICompilationUnit unit = parser.Parse(new MockProjectContent(), @"C:\Projects\MyProject\test.rb", GetTextEditorCode()); |
|
||||||
ParseInformation parseInfo = new ParseInformation(unit); |
|
||||||
generator.ParseInfoToReturnFromParseFileMethod = parseInfo; |
|
||||||
|
|
||||||
// Attach view content to generator.
|
|
||||||
generator.Attach(viewContent); |
|
||||||
|
|
||||||
// Get compatible methods for event.
|
|
||||||
MockEventDescriptor eventDescriptor = new MockEventDescriptor("Click"); |
|
||||||
compatibleMethods = generator.GetCompatibleMethods(eventDescriptor); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void OneCompatibleMethod() |
|
||||||
{ |
|
||||||
Assert.AreEqual(1, compatibleMethods.Count); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CompatibleMethodName() |
|
||||||
{ |
|
||||||
IEnumerator enumerator = compatibleMethods.GetEnumerator(); |
|
||||||
enumerator.MoveNext(); |
|
||||||
Assert.AreEqual("button1_click", (string)enumerator.Current); |
|
||||||
} |
|
||||||
|
|
||||||
string GetTextEditorCode() |
|
||||||
{ |
|
||||||
return "class MainForm < System::Windows::Forms::Form\r\n" + |
|
||||||
"\tdef initialize()\r\n" + |
|
||||||
"\t\tself.InitializeComponents()\r\n" + |
|
||||||
"\tend\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef InitializeComponents()\r\n" + |
|
||||||
"\t\t@button1 = System::Windows::Forms::Button.new()\r\n" + |
|
||||||
"\t\tself.Controls.Add(@button1)\r\n" + |
|
||||||
"\tend\r\n" + |
|
||||||
"\t\r\n" + |
|
||||||
"\tdef button1_click(sender, e)\r\n" + |
|
||||||
"\tend\r\n" + |
|
||||||
"end"; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,98 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.CodeDom; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.ComponentModel.Design.Serialization; |
|
||||||
using System.Drawing; |
|
||||||
using System.IO; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.FormsDesigner; |
|
||||||
using ICSharpCode.RubyBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using ICSharpCode.SharpDevelop.Editor; |
|
||||||
using NUnit.Framework; |
|
||||||
using RubyBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace RubyBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that the indent information in the ITextEditorProperties is passed to the generator.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class TextEditorIndentPassedToGeneratorTestFixture |
|
||||||
{ |
|
||||||
IDocument document; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
using (FormsDesignerViewContent viewContent = new FormsDesignerViewContent(new MockViewContent(), new MockOpenedFile("Test.rb"))) { |
|
||||||
viewContent.DesignerCodeFileContent = |
|
||||||
"class MainForm < Form\r\n" + |
|
||||||
" def initialize()\r\n" + |
|
||||||
" self.InitializeComponent()\r\n" + |
|
||||||
" end\r\n" + |
|
||||||
"\r\n" + |
|
||||||
" def InitializeComponent()\r\n" + |
|
||||||
" end\r\n" + |
|
||||||
"end"; |
|
||||||
|
|
||||||
document = viewContent.DesignerCodeFileDocument; |
|
||||||
|
|
||||||
RubyParser parser = new RubyParser(); |
|
||||||
ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.Text); |
|
||||||
ParseInformation parseInfo = new ParseInformation(compilationUnit); |
|
||||||
|
|
||||||
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
|
||||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
|
||||||
Form form = (Form)host.RootComponent; |
|
||||||
form.ClientSize = new Size(284, 264); |
|
||||||
|
|
||||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
|
||||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
|
||||||
namePropertyDescriptor.SetValue(form, "MainForm"); |
|
||||||
|
|
||||||
MockTextEditorOptions textEditorOptions = new MockTextEditorOptions(); |
|
||||||
textEditorOptions.ConvertTabsToSpaces = true; |
|
||||||
textEditorOptions.IndentationSize = 1; |
|
||||||
|
|
||||||
DerivedRubyDesignerGenerator generator = new DerivedRubyDesignerGenerator(textEditorOptions); |
|
||||||
generator.ParseInfoToReturnFromParseFileMethod = parseInfo; |
|
||||||
generator.Attach(viewContent); |
|
||||||
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
|
||||||
using (serializationManager.CreateSession()) { |
|
||||||
generator.MergeRootComponentChanges(host, serializationManager); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void GeneratedCode() |
|
||||||
{ |
|
||||||
string expectedCode = |
|
||||||
"class MainForm < Form\r\n" + |
|
||||||
" def initialize()\r\n" + |
|
||||||
" self.InitializeComponent()\r\n" + |
|
||||||
" end\r\n" + |
|
||||||
"\r\n" + |
|
||||||
" def InitializeComponent()\r\n" + |
|
||||||
" self.SuspendLayout()\r\n" + |
|
||||||
" # \r\n" + |
|
||||||
" # MainForm\r\n" + |
|
||||||
" # \r\n" + |
|
||||||
" self.ClientSize = System::Drawing::Size.new(284, 264)\r\n" + |
|
||||||
" self.Name = \"MainForm\"\r\n" + |
|
||||||
" self.ResumeLayout(false)\r\n" + |
|
||||||
" end\r\n" + |
|
||||||
"end"; |
|
||||||
|
|
||||||
Assert.AreEqual(expectedCode, document.Text); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,33 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.ComponentModel.Design.Serialization; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Utils |
||||||
|
{ |
||||||
|
public class FakeCodeDomSerializer : IScriptingCodeDomSerializer |
||||||
|
{ |
||||||
|
public string MethodBodyToReturnFromGenerateMethodBodyCall = String.Empty; |
||||||
|
|
||||||
|
public IDesignerHost HostPassedToGenerateInitializeComponentMethodBody; |
||||||
|
public IDesignerSerializationManager SerializationManagerGenerateInitializeComponentMethodBody; |
||||||
|
public string RootNamespacePassedToGenerateInitializeComponentMethodBody; |
||||||
|
public int InitialIndentPassedToGenerateInitializeComponentMethodBody; |
||||||
|
|
||||||
|
public string GenerateInitializeComponentMethodBody(IDesignerHost host, IDesignerSerializationManager serializationManager, string rootNamespace, int initialIndent) |
||||||
|
{ |
||||||
|
HostPassedToGenerateInitializeComponentMethodBody = host; |
||||||
|
SerializationManagerGenerateInitializeComponentMethodBody = serializationManager; |
||||||
|
RootNamespacePassedToGenerateInitializeComponentMethodBody = rootNamespace; |
||||||
|
InitialIndentPassedToGenerateInitializeComponentMethodBody = initialIndent; |
||||||
|
|
||||||
|
return MethodBodyToReturnFromGenerateMethodBodyCall; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,95 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Utils.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestableScriptingDesignerGeneratorTests |
||||||
|
{ |
||||||
|
ParseInformation parseInfo; |
||||||
|
TestableScriptingDesignerGenerator generator; |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateParseInfoWithOneMethod_MethodNamePassed_ReturnsParseInfoWithOneClass() |
||||||
|
{ |
||||||
|
CreateTestableScriptingDesignerGenerator(); |
||||||
|
CreateParseInfoWithOneMethod("MyMethod"); |
||||||
|
|
||||||
|
int classCount = parseInfo.CompilationUnit.Classes.Count; |
||||||
|
|
||||||
|
Assert.AreEqual(1, classCount); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateTestableScriptingDesignerGenerator() |
||||||
|
{ |
||||||
|
MockTextEditorOptions options = new MockTextEditorOptions(); |
||||||
|
generator = new TestableScriptingDesignerGenerator(options); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateParseInfoWithOneMethod(string name) |
||||||
|
{ |
||||||
|
parseInfo = generator.CreateParseInfoWithOneMethod(name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateParseInfoWithOneMethod_MethodNamePassed_ReturnsClassWithOneMethod() |
||||||
|
{ |
||||||
|
CreateTestableScriptingDesignerGenerator(); |
||||||
|
CreateParseInfoWithOneMethod("MyMethod"); |
||||||
|
|
||||||
|
IClass c = parseInfo.CompilationUnit.Classes[0]; |
||||||
|
int methodCount = c.Methods.Count; |
||||||
|
|
||||||
|
Assert.AreEqual(1, methodCount); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateParseInfoWithOneMethod_MethodNamePassed_ReturnsMethodWithExpectedMethodName() |
||||||
|
{ |
||||||
|
CreateTestableScriptingDesignerGenerator(); |
||||||
|
CreateParseInfoWithOneMethod("MyMethod"); |
||||||
|
|
||||||
|
IClass c = parseInfo.CompilationUnit.Classes[0]; |
||||||
|
IMethod method = c.Methods[0]; |
||||||
|
string name = method.Name; |
||||||
|
string expectedName = "MyMethod"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedName, name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Constructor_NewInstance_ParseInfoToReturnFromParseFileHasOneClass() |
||||||
|
{ |
||||||
|
CreateTestableScriptingDesignerGenerator(); |
||||||
|
parseInfo = generator.CreateParseInfoWithOneClass(); |
||||||
|
int count = parseInfo.CompilationUnit.Classes.Count; |
||||||
|
Assert.AreEqual(1, count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateParseInfoWithOneMethodWithTwoParameters_MethodNamePassed_ReturnsMethodWithTwoParameters() |
||||||
|
{ |
||||||
|
CreateTestableScriptingDesignerGenerator(); |
||||||
|
CreateParseInfoWithOneMethodWithTwoParameters("MyMethod"); |
||||||
|
|
||||||
|
IClass c = parseInfo.CompilationUnit.Classes[0]; |
||||||
|
IMethod method = c.Methods[0]; |
||||||
|
int parameterCount = method.Parameters.Count; |
||||||
|
|
||||||
|
Assert.AreEqual(2, parameterCount); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateParseInfoWithOneMethodWithTwoParameters(string name) |
||||||
|
{ |
||||||
|
parseInfo = generator.CreateParseInfoWithOneMethodWithTwoParameters(name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue