Browse Source

Can now send the current text editor line to the Python Console window.

pull/1/head
mrward 15 years ago
parent
commit
9f73652f7d
  1. 3
      data/resources/StringResources.nl.resx
  2. 3
      data/resources/StringResources.resx
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding.sln
  4. 24
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin
  5. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  6. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ConvertToPythonMenuCommand.cs
  7. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IConsoleTextEditor.cs
  8. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ILock.cs
  9. 24
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPadDescriptor.cs
  10. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonConsole.cs
  11. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonConsolePad.cs
  12. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonWorkbench.cs
  13. 114
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs
  14. 13
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleHost.cs
  15. 14
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsolePad.cs
  16. 58
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleTextEditor.cs
  17. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOutputWindowPadDescriptor.cs
  18. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTextEditorViewContent.cs
  19. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonWorkbench.cs
  20. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunDebugPythonCommand.cs
  21. 8
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs
  22. 73
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendLineToPythonConsoleCommand.cs
  23. 39
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/StringListLock.cs
  24. 117
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ThreadSafePythonConsoleTextEditor.cs
  25. 806
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInFileTestFixture.cs
  26. 111
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/ConsoleTextEditorThreadSafetyTestFixture.cs
  27. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs
  28. 23
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs
  29. 19
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs
  30. 49
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCommandLineHistoryTestFixture.cs
  31. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCurrentLineTestFixture.cs
  32. 35
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleEnterKeyTestFixture.cs
  33. 19
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHomeKeyTestFixture.cs
  34. 119
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs
  35. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs
  36. 174
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleSendLineTests.cs
  37. 25
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTestsBase.cs
  38. 78
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTextEditorTests.cs
  39. 21
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleUnreadLinesTestFixture.cs
  40. 26
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleWriteTestFixture.cs
  41. 328
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/ThreadSafePythonConsoleTextEditorTests.cs
  42. 7
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TwoPythonConsoleLinesWaitingTestFixture.cs
  43. 23
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertCSharpToPythonMenuCommandTestFixture.cs
  44. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertVBNetToPythonMenuCommandTestFixture.cs
  45. 28
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/DebugPythonCommandTestFixture.cs
  46. 36
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/RunPythonCommandTests.cs
  47. 93
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/SendLineToPythonConsoleCommandTests.cs
  48. 22
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  49. 53
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeCaret.cs
  50. 139
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeDocument.cs
  51. 23
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeDocumentLine.cs
  52. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeLock.cs
  53. 195
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockConsoleTextEditor.cs
  54. 21
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockEditableViewContent.cs
  55. 40
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPadDescriptor.cs
  56. 22
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPythonConsole.cs
  57. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPythonConsolePad.cs
  58. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTextEditor.cs
  59. 158
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs
  60. 129
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbenchWindow.cs
  61. 56
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/TestablePythonConsole.cs
  62. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockEditableViewContentTestFixture.cs

3
data/resources/StringResources.nl.resx

@ -231,6 +231,9 @@
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve"> <data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Klassendiagram weergeven</value> <value>Klassendiagram weergeven</value>
</data> </data>
<data name="AddIns.Git.TortoiseGitRequired" xml:space="preserve">
<value>Om deze actie uit te voeren dient TortoiseGit geïnstalleerd te zijn.</value>
</data>
<data name="AddIns.HelpViewer.ContentsPadTitle" xml:space="preserve"> <data name="AddIns.HelpViewer.ContentsPadTitle" xml:space="preserve">
<value>Inhoud</value> <value>Inhoud</value>
</data> </data>

3
data/resources/StringResources.resx

@ -4065,6 +4065,9 @@ Please configure the NAnt executable's location in the SharpDevelop Options.</va
<data name="ICSharpCode.PythonBinding.PythonProjectFiles" xml:space="preserve"> <data name="ICSharpCode.PythonBinding.PythonProjectFiles" xml:space="preserve">
<value>Python Project Files</value> <value>Python Project Files</value>
</data> </data>
<data name="ICSharpCode.PythonBinding.SendLineToPythonConsole" xml:space="preserve">
<value>Send Line to Python Console</value>
</data>
<data name="ICSharpCode.PythonBinding.UnknownTypeName" xml:space="preserve"> <data name="ICSharpCode.PythonBinding.UnknownTypeName" xml:space="preserve">
<value>Could not find type '{0}'. Are you missing an assembly reference?</value> <value>Could not find type '{0}'. Are you missing an assembly reference?</value>
</data> </data>

2
src/AddIns/BackendBindings/Python/PythonBinding.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
# SharpDevelop 4.0.0.6374 # SharpDevelop 4.0.0.6500
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding", "PythonBinding\Project\PythonBinding.csproj", "{8D732610-8FC6-43BA-94C9-7126FD7FE361}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding", "PythonBinding\Project\PythonBinding.csproj", "{8D732610-8FC6-43BA-94C9-7126FD7FE361}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding.Tests", "PythonBinding\Test\PythonBinding.Tests.csproj", "{23B517C9-1ECC-4419-A13F-0B7136D085CB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding.Tests", "PythonBinding\Test\PythonBinding.Tests.csproj", "{23B517C9-1ECC-4419-A13F-0B7136D085CB}"

24
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin

@ -28,7 +28,7 @@
<LanguageBinding id="Python" <LanguageBinding id="Python"
class="ICSharpCode.PythonBinding.PythonLanguageBinding" class="ICSharpCode.PythonBinding.PythonLanguageBinding"
extensions=".py" /> extensions=".py" />
</Path>--> </Path>
<!-- Add the "Python" entry to the Open File Dialog --> <!-- Add the "Python" entry to the Open File Dialog -->
<Path name="/SharpDevelop/Workbench/FileFilter"> <Path name="/SharpDevelop/Workbench/FileFilter">
@ -79,6 +79,10 @@
class="ICSharpCode.SharpDevelop.Project.Commands.StopDebuggingCommand" class="ICSharpCode.SharpDevelop.Project.Commands.StopDebuggingCommand"
label="${res:XML.MainMenu.DebugMenu.Stop}"/> label="${res:XML.MainMenu.DebugMenu.Stop}"/>
</Condition> </Condition>
<MenuItem id="SendToPythonConsoleSeparator" type="Separator"/>
<MenuItem id="SendLineToPythonConsole"
class="ICSharpCode.PythonBinding.SendLineToPythonConsoleCommand"
label="${res:ICSharpCode.PythonBinding.SendLineToPythonConsole}"/>
</MenuItem> </MenuItem>
</Condition> </Condition>
</Path> </Path>
@ -178,7 +182,6 @@
<Pad id="PythonConsole" <Pad id="PythonConsole"
category="Tools" category="Tools"
title="${res:ICSharpCode.PythonBinding.PythonConsole}" title="${res:ICSharpCode.PythonBinding.PythonConsole}"
insertafter="Bookmarks"
insertbefore="DefinitionView" insertbefore="DefinitionView"
icon="PadIcons.Output" icon="PadIcons.Output"
defaultPosition="Bottom, Hidden" defaultPosition="Bottom, Hidden"
@ -188,15 +191,26 @@
<Path name="/Workspace/Icons"> <Path name="/Workspace/Icons">
<Icon id="PythonFileIcon" <Icon id="PythonFileIcon"
extensions=".py" extensions=".py"
resource="Python.ProjectBrowser.File" /> resource="Python.ProjectBrowser.File"/>
<Icon id="PythonProjectIcon" <Icon id="PythonProjectIcon"
language="Python" language="Python"
resource="Python.ProjectBrowser.Project" /> resource="Python.ProjectBrowser.Project"/>
</Path> </Path>
<Path name="/SharpDevelop/UnitTesting/TestFrameworks"> <Path name="/SharpDevelop/UnitTesting/TestFrameworks">
<TestFramework id="pyunit" <TestFramework id="pyunit"
class="ICSharpCode.PythonBinding.PythonTestFramework" class="ICSharpCode.PythonBinding.PythonTestFramework"
supportedProjects=".pyproj" /> supportedProjects=".pyproj"/>
</Path>
<Path name="/SharpDevelop/ViewContent/TextEditor/ContextMenu">
<Condition name="ActiveContentExtension" activeextension=".py">
<MenuItem id="SendToPythonConsoleSeparator"
insertafter="Indent"
type="Separator"/>
<MenuItem id="SendLineToPythonConsole"
class="ICSharpCode.PythonBinding.SendLineToPythonConsoleCommand"
label="${res:ICSharpCode.PythonBinding.SendLineToPythonConsole}"/>
</Condition>
</Path> </Path>
</AddIn> </AddIn>

10
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -93,8 +93,12 @@
<Compile Include="Src\CompilingOptionsPanel.cs" /> <Compile Include="Src\CompilingOptionsPanel.cs" />
<Compile Include="Src\CreateTextWriterInfo.cs" /> <Compile Include="Src\CreateTextWriterInfo.cs" />
<Compile Include="Src\IControlDispatcher.cs" /> <Compile Include="Src\IControlDispatcher.cs" />
<Compile Include="Src\IPythonConsole.cs" />
<Compile Include="Src\IPythonConsolePad.cs" />
<Compile Include="Src\IPythonFileService.cs" /> <Compile Include="Src\IPythonFileService.cs" />
<Compile Include="Src\IPythonResolver.cs" /> <Compile Include="Src\IPythonResolver.cs" />
<Compile Include="Src\IPythonWorkbench.cs" />
<Compile Include="Src\ILock.cs" />
<Compile Include="Src\MemberName.cs" /> <Compile Include="Src\MemberName.cs" />
<Compile Include="Src\PythonBuiltInModuleMemberName.cs" /> <Compile Include="Src\PythonBuiltInModuleMemberName.cs" />
<Compile Include="Src\PythonClassResolver.cs" /> <Compile Include="Src\PythonClassResolver.cs" />
@ -128,10 +132,12 @@
<Compile Include="Src\PythonTestRunnerContext.cs" /> <Compile Include="Src\PythonTestRunnerContext.cs" />
<Compile Include="Src\PythonTestRunnerResponseFile.cs" /> <Compile Include="Src\PythonTestRunnerResponseFile.cs" />
<Compile Include="Src\PythonTextEditorViewContent.cs" /> <Compile Include="Src\PythonTextEditorViewContent.cs" />
<Compile Include="Src\PythonWorkbench.cs" />
<Compile Include="Src\SendLineToPythonConsoleCommand.cs" />
<Compile Include="Src\StringListLock.cs" />
<Compile Include="Src\SysModuleCompletionItems.cs" /> <Compile Include="Src\SysModuleCompletionItems.cs" />
<Compile Include="Src\IComponentCreator.cs" /> <Compile Include="Src\IComponentCreator.cs" />
<Compile Include="Src\IMemberProvider.cs" /> <Compile Include="Src\IMemberProvider.cs" />
<Compile Include="Src\IPadDescriptor.cs" />
<Compile Include="Src\IConsoleTextEditor.cs" /> <Compile Include="Src\IConsoleTextEditor.cs" />
<Compile Include="Src\NRefactoryToPythonConverter.cs" /> <Compile Include="Src\NRefactoryToPythonConverter.cs" />
<Compile Include="Src\PythonAstWalker.cs" /> <Compile Include="Src\PythonAstWalker.cs" />
@ -164,7 +170,6 @@
<Compile Include="Src\PythonImportModuleResolveResult.cs" /> <Compile Include="Src\PythonImportModuleResolveResult.cs" />
<Compile Include="Src\PythonOptionsPanel.cs" /> <Compile Include="Src\PythonOptionsPanel.cs" />
<Compile Include="Src\PythonOutputStream.cs" /> <Compile Include="Src\PythonOutputStream.cs" />
<Compile Include="Src\PythonOutputWindowPadDescriptor.cs" />
<Compile Include="Src\PythonParser.cs" /> <Compile Include="Src\PythonParser.cs" />
<Compile Include="Src\PythonProject.cs" /> <Compile Include="Src\PythonProject.cs" />
<Compile Include="Src\PythonPropertyValueAssignment.cs" /> <Compile Include="Src\PythonPropertyValueAssignment.cs" />
@ -175,6 +180,7 @@
<Compile Include="Src\PythonVariableResolver.cs" /> <Compile Include="Src\PythonVariableResolver.cs" />
<Compile Include="Src\StringTextContentProvider.cs" /> <Compile Include="Src\StringTextContentProvider.cs" />
<Compile Include="Src\PythonConsoleTextEditor.cs" /> <Compile Include="Src\PythonConsoleTextEditor.cs" />
<Compile Include="Src\ThreadSafePythonConsoleTextEditor.cs" />
<None Include="..\..\RequiredLibraries\Chiron.exe.Config"> <None Include="..\..\RequiredLibraries\Chiron.exe.Config">
<Link>Chiron.exe.Config</Link> <Link>Chiron.exe.Config</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ConvertToPythonMenuCommand.cs

@ -21,10 +21,10 @@ namespace ICSharpCode.PythonBinding
public override void Run() public override void Run()
{ {
Run(WorkbenchSingleton.Workbench); Run(new PythonWorkbench());
} }
protected void Run(IWorkbench workbench) protected void Run(IPythonWorkbench workbench)
{ {
view = new PythonTextEditorViewContent(workbench); view = new PythonTextEditorViewContent(workbench);
string code = GeneratePythonCode(); string code = GeneratePythonCode();

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IConsoleTextEditor.cs

@ -16,7 +16,7 @@ namespace ICSharpCode.PythonBinding
/// all the methods will be called on another thread not the main UI thread and will therefore need to /// all the methods will be called on another thread not the main UI thread and will therefore need to
/// be invoked. /// be invoked.
/// </summary> /// </summary>
public interface IConsoleTextEditor public interface IConsoleTextEditor : IDisposable
{ {
/// <summary> /// <summary>
/// Fired when a key is pressed but before any text has been added to the text editor. /// Fired when a key is pressed but before any text has been added to the text editor.
@ -55,7 +55,7 @@ namespace ICSharpCode.PythonBinding
/// <summary> /// <summary>
/// Gets the current line the cursor is on. This is zero based. /// Gets the current line the cursor is on. This is zero based.
/// </summary> /// </summary>
int Line {get;} int Line {get; set;}
/// <summary> /// <summary>
/// Gets the total number of lines in the text editor. /// Gets the total number of lines in the text editor.

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ILock.cs

@ -0,0 +1,16 @@
// <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.Collections.Generic;
namespace ICSharpCode.PythonBinding
{
public interface ILock : IDisposable
{
}
}

24
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPadDescriptor.cs

@ -1,24 +0,0 @@
// <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;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// The interface that a pad descriptor should implement.
/// Note that the actual PadDescriptor class does not
/// have an interface.
/// </summary>
public interface IPadDescriptor
{
/// <summary>
/// Brings the pad to the front of the IDE.
/// </summary>
void BringPadToFront();
}
}

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonConsole.cs

@ -0,0 +1,16 @@
// <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;
namespace ICSharpCode.PythonBinding
{
public interface IPythonConsole
{
void SendLine(string text);
}
}

18
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonConsolePad.cs

@ -0,0 +1,18 @@
// <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;
namespace ICSharpCode.PythonBinding
{
public interface IPythonConsolePad
{
void BringToFront();
IConsoleTextEditor ConsoleTextEditor { get; }
IPythonConsole PythonConsole { get; }
}
}

18
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonWorkbench.cs

@ -0,0 +1,18 @@
// <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.Gui;
namespace ICSharpCode.PythonBinding
{
public interface IPythonWorkbench
{
IPythonConsolePad GetPythonConsolePad();
IViewContent ActiveViewContent { get; }
}
}

114
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs

@ -13,11 +13,12 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Windows.Input; using System.Windows.Input;
using ICSharpCode.AvalonEdit.CodeCompletion; using ICSharpCode.AvalonEdit.CodeCompletion;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting.Shell; using Microsoft.Scripting.Hosting.Shell;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
public class PythonConsole : IConsole, IDisposable, IMemberProvider public class PythonConsole : IConsole, IDisposable, IMemberProvider, IPythonConsole
{ {
IConsoleTextEditor textEditor; IConsoleTextEditor textEditor;
int lineReceivedEventIndex = 0; // The index into the waitHandles array where the lineReceivedEvent is stored. int lineReceivedEventIndex = 0; // The index into the waitHandles array where the lineReceivedEvent is stored.
@ -25,20 +26,22 @@ namespace ICSharpCode.PythonBinding
ManualResetEvent disposedEvent = new ManualResetEvent(false); ManualResetEvent disposedEvent = new ManualResetEvent(false);
WaitHandle[] waitHandles; WaitHandle[] waitHandles;
int promptLength; int promptLength;
List<string> previousLines = new List<string>(); bool firstPromptDisplayed;
CommandLine commandLine; string savedSendLineText;
CommandLineHistory commandLineHistory = new CommandLineHistory(); CommandLineHistory commandLineHistory = new CommandLineHistory();
public PythonConsole(IConsoleTextEditor textEditor, CommandLine commandLine) protected List<string> unreadLines = new List<string>();
public PythonConsole(IConsoleTextEditor textEditor)
{ {
waitHandles = new WaitHandle[] {lineReceivedEvent, disposedEvent}; waitHandles = new WaitHandle[] {lineReceivedEvent, disposedEvent};
this.commandLine = commandLine;
this.textEditor = textEditor; this.textEditor = textEditor;
textEditor.PreviewKeyDown += ProcessPreviewKeyDown; textEditor.PreviewKeyDown += ProcessPreviewKeyDown;
} }
public CommandLine CommandLine { get; set; }
public void Dispose() public void Dispose()
{ {
disposedEvent.Set(); disposedEvent.Set();
@ -59,12 +62,12 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
public IList<string> GetMemberNames(string name) public IList<string> GetMemberNames(string name)
{ {
return commandLine.GetMemberNames(name); return CommandLine.GetMemberNames(name);
} }
public IList<string> GetGlobals(string name) public IList<string> GetGlobals(string name)
{ {
return commandLine.GetGlobals(name); return CommandLine.GetGlobals(name);
} }
/// <summary> /// <summary>
@ -73,9 +76,8 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
public string ReadLine(int autoIndentSize) public string ReadLine(int autoIndentSize)
{ {
string indent = String.Empty; string indent = GetIndent(autoIndentSize);
if (autoIndentSize > 0) { if (autoIndentSize > 0) {
indent = String.Empty.PadLeft(autoIndentSize);
Write(indent, Style.Prompt); Write(indent, Style.Prompt);
} }
@ -86,6 +88,11 @@ namespace ICSharpCode.PythonBinding
return null; return null;
} }
string GetIndent(int autoIndentSize)
{
return String.Empty.PadLeft(autoIndentSize);
}
/// <summary> /// <summary>
/// Writes text to the console. /// Writes text to the console.
/// </summary> /// </summary>
@ -93,11 +100,21 @@ namespace ICSharpCode.PythonBinding
{ {
textEditor.Write(text); textEditor.Write(text);
if (style == Style.Prompt) { if (style == Style.Prompt) {
WriteSavedLineTextAfterFirstPrompt(text);
promptLength = text.Length; promptLength = text.Length;
textEditor.MakeCurrentContentReadOnly(); textEditor.MakeCurrentContentReadOnly();
} }
} }
void WriteSavedLineTextAfterFirstPrompt(string promptText)
{
firstPromptDisplayed = true;
if (savedSendLineText != null) {
textEditor.Write(savedSendLineText + "\r\n");
savedSendLineText = null;
}
}
/// <summary> /// <summary>
/// Writes text followed by a newline to the console. /// Writes text followed by a newline to the console.
/// </summary> /// </summary>
@ -119,8 +136,8 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
public bool IsLineAvailable { public bool IsLineAvailable {
get { get {
lock (previousLines) { lock (unreadLines) {
return (previousLines.Count > 0); return (unreadLines.Count > 0);
} }
} }
} }
@ -135,15 +152,6 @@ namespace ICSharpCode.PythonBinding
return fullLine.Substring(promptLength); return fullLine.Substring(promptLength);
} }
/// <summary>
/// Gets the lines that have not been returned by the ReadLine method. This does not
/// include the current line.
/// </summary>
public string[] GetUnreadLines()
{
return previousLines.ToArray();
}
string GetLastTextEditorLine() string GetLastTextEditorLine()
{ {
return textEditor.GetLine(textEditor.TotalLines - 1); return textEditor.GetLine(textEditor.TotalLines - 1);
@ -153,10 +161,10 @@ namespace ICSharpCode.PythonBinding
{ {
int result = WaitHandle.WaitAny(waitHandles); int result = WaitHandle.WaitAny(waitHandles);
if (result == lineReceivedEventIndex) { if (result == lineReceivedEventIndex) {
lock (previousLines) { lock (unreadLines) {
string line = previousLines[0]; string line = unreadLines[0];
previousLines.RemoveAt(0); unreadLines.RemoveAt(0);
if (previousLines.Count == 0) { if (unreadLines.Count == 0) {
lineReceivedEvent.Reset(); lineReceivedEvent.Reset();
} }
return line; return line;
@ -216,24 +224,29 @@ namespace ICSharpCode.PythonBinding
return false; return false;
} }
/// <summary>
/// Move cursor to the end of the line before retrieving the line.
/// </summary>
void OnEnterKeyPressed() void OnEnterKeyPressed()
{ {
lock (previousLines) { lock (unreadLines) {
// Move cursor to the end of the line. MoveCursorToEndOfLastTextEditorLine();
textEditor.Column = GetLastTextEditorLine().Length; SaveLastTextEditorLine();
// Append line.
string currentLine = GetCurrentLine();
previousLines.Add(currentLine);
commandLineHistory.Add(currentLine);
lineReceivedEvent.Set(); lineReceivedEvent.Set();
} }
} }
void MoveCursorToEndOfLastTextEditorLine()
{
textEditor.Line = textEditor.TotalLines - 1;
textEditor.Column = GetLastTextEditorLine().Length;
}
void SaveLastTextEditorLine()
{
string currentLine = GetCurrentLine();
unreadLines.Add(currentLine);
commandLineHistory.Add(currentLine);
}
/// <summary> /// <summary>
/// Returns true if the cursor is in a readonly text editor region. /// Returns true if the cursor is in a readonly text editor region.
/// </summary> /// </summary>
@ -311,5 +324,34 @@ namespace ICSharpCode.PythonBinding
// Put cursor at end. // Put cursor at end.
textEditor.Column = promptLength + text.Length; textEditor.Column = promptLength + text.Length;
} }
public void SendLine(string text)
{
using (ILock linesLock = CreateLock(unreadLines)) {
unreadLines.Add(text);
}
FireLineReceivedEvent();
MoveCursorToEndOfLastTextEditorLine();
WriteLineIfFirstPromptHasBeenDisplayed(text);
}
protected virtual ILock CreateLock(List<string> lines)
{
return new StringListLock(lines);
}
protected virtual void FireLineReceivedEvent()
{
lineReceivedEvent.Set();
}
void WriteLineIfFirstPromptHasBeenDisplayed(string text)
{
if (firstPromptDisplayed) {
WriteLine(text, Style.Out);
} else {
savedSendLineText = text;
}
}
} }
} }

13
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleHost.cs

@ -16,9 +16,6 @@ using Microsoft.Scripting.Hosting.Shell;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
/// <summary>
/// Hosts the python console.
/// </summary>
public class PythonConsoleHost : ConsoleHost, IDisposable public class PythonConsoleHost : ConsoleHost, IDisposable
{ {
Thread thread; Thread thread;
@ -28,6 +25,11 @@ namespace ICSharpCode.PythonBinding
public PythonConsoleHost(IConsoleTextEditor textEditor) public PythonConsoleHost(IConsoleTextEditor textEditor)
{ {
this.textEditor = textEditor; this.textEditor = textEditor;
pythonConsole = new PythonConsole(textEditor);
}
public PythonConsole PythonConsole {
get { return pythonConsole; }
} }
protected override Type Provider { protected override Type Provider {
@ -73,7 +75,7 @@ namespace ICSharpCode.PythonBinding
protected override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options) protected override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options)
{ {
SetOutput(new PythonOutputStream(textEditor)); SetOutput(new PythonOutputStream(textEditor));
pythonConsole = new PythonConsole(textEditor, commandLine); pythonConsole.CommandLine = commandLine;
return pythonConsole; return pythonConsole;
} }
@ -82,9 +84,6 @@ namespace ICSharpCode.PythonBinding
Runtime.IO.SetOutput(stream, Encoding.UTF8); Runtime.IO.SetOutput(stream, Encoding.UTF8);
} }
/// <summary>
/// Runs the console.
/// </summary>
void RunConsole() void RunConsole()
{ {
Run(new string[0]); Run(new string[0]);

14
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsolePad.cs

@ -11,20 +11,28 @@ using AvalonEdit = ICSharpCode.AvalonEdit;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
public class PythonConsolePad : AbstractPadContent public class PythonConsolePad : AbstractPadContent, IPythonConsolePad
{ {
PythonConsoleTextEditor consoleTextEditor; ThreadSafePythonConsoleTextEditor consoleTextEditor;
AvalonEdit.TextEditor textEditor; AvalonEdit.TextEditor textEditor;
PythonConsoleHost host; PythonConsoleHost host;
public PythonConsolePad() public PythonConsolePad()
{ {
textEditor = new AvalonEdit.TextEditor(); textEditor = new AvalonEdit.TextEditor();
consoleTextEditor = new PythonConsoleTextEditor(textEditor); consoleTextEditor = new ThreadSafePythonConsoleTextEditor(textEditor);
host = new PythonConsoleHost(consoleTextEditor); host = new PythonConsoleHost(consoleTextEditor);
host.Run(); host.Run();
} }
public IConsoleTextEditor ConsoleTextEditor {
get { return consoleTextEditor; }
}
public IPythonConsole PythonConsole {
get { return host.PythonConsole; }
}
public override object Control { public override object Control {
get { return textEditor; } get { return textEditor; }
} }

58
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleTextEditor.cs

@ -19,23 +19,14 @@ namespace ICSharpCode.PythonBinding
{ {
public class PythonConsoleTextEditor : IConsoleTextEditor public class PythonConsoleTextEditor : IConsoleTextEditor
{ {
delegate string GetLineInvoker(int index);
TextEditor textEditor; TextEditor textEditor;
Color customLineColour = Color.LightGray; Color customLineColour = Color.LightGray;
BeginReadOnlySectionProvider readOnlyRegion; BeginReadOnlySectionProvider readOnlyRegion;
IControlDispatcher dispatcher;
CompletionWindow completionWindow; CompletionWindow completionWindow;
public PythonConsoleTextEditor(TextEditor textEditor) public PythonConsoleTextEditor(TextEditor textEditor)
: this(textEditor, new ControlDispatcher(textEditor))
{
}
public PythonConsoleTextEditor(TextEditor textEditor, IControlDispatcher dispatcher)
{ {
this.textEditor = textEditor; this.textEditor = textEditor;
this.dispatcher = dispatcher;
readOnlyRegion = new BeginReadOnlySectionProvider(); readOnlyRegion = new BeginReadOnlySectionProvider();
textEditor.TextArea.ReadOnlySectionProvider = readOnlyRegion; textEditor.TextArea.ReadOnlySectionProvider = readOnlyRegion;
textEditor.PreviewKeyDown += OnTextEditorPreviewKeyDown; textEditor.PreviewKeyDown += OnTextEditorPreviewKeyDown;
@ -50,20 +41,20 @@ namespace ICSharpCode.PythonBinding
public event ConsoleTextEditorKeyEventHandler PreviewKeyDown; public event ConsoleTextEditorKeyEventHandler PreviewKeyDown;
public void Dispose()
{
textEditor.PreviewKeyDown -= OnTextEditorPreviewKeyDown;
}
public Color CustomLineColour { public Color CustomLineColour {
get { return customLineColour; } get { return customLineColour; }
} }
public void Write(string text) public void Write(string text)
{ {
if (dispatcher.CheckAccess()) { TextLocation location = GetCurrentCursorLocation();
TextLocation location = GetCurrentCursorLocation(); int offset = textEditor.Document.GetOffset(location);
int offset = textEditor.Document.GetOffset(location); textEditor.Document.Insert(offset, text);
textEditor.Document.Insert(offset, text);
} else {
Action<string> action = Write;
dispatcher.Invoke(action, new object[] {text});
}
} }
TextLocation GetCurrentCursorLocation() TextLocation GetCurrentCursorLocation()
@ -84,11 +75,9 @@ namespace ICSharpCode.PythonBinding
get { return textEditor.SelectionLength; } get { return textEditor.SelectionLength; }
} }
/// <summary>
/// Gets the current cursor line.
/// </summary>
public int Line { public int Line {
get { return textEditor.TextArea.Caret.Line - 1; } get { return textEditor.TextArea.Caret.Line - 1; }
set { textEditor.TextArea.Caret.Line = value + 1; }
} }
/// <summary> /// <summary>
@ -103,13 +92,8 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
public string GetLine(int index) public string GetLine(int index)
{ {
if (dispatcher.CheckAccess()) { DocumentLine line = textEditor.Document.GetLineByNumber(index + 1);
DocumentLine line = textEditor.Document.GetLineByNumber(index + 1); return textEditor.Document.GetText(line);
return textEditor.Document.GetText(line);
} else {
GetLineInvoker invoker = new GetLineInvoker(GetLine);
return (string)dispatcher.Invoke(invoker, new object[] {index});
}
} }
/// <summary> /// <summary>
@ -117,14 +101,9 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
public void Replace(int index, int length, string text) public void Replace(int index, int length, string text)
{ {
if (dispatcher.CheckAccess()) { DocumentLine line = textEditor.Document.GetLineByNumber(textEditor.TextArea.Caret.Line);
DocumentLine line = textEditor.Document.GetLineByNumber(textEditor.TextArea.Caret.Line); int offset = line.Offset + index;
int offset = line.Offset + index; textEditor.Document.Replace(offset, length, text);
textEditor.Document.Replace(offset, length, text);
} else {
Action<int, int, string> action = Replace;
dispatcher.Invoke(action, new object[] {index, length, text});
}
} }
/// <summary> /// <summary>
@ -132,12 +111,7 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
public void MakeCurrentContentReadOnly() public void MakeCurrentContentReadOnly()
{ {
if (dispatcher.CheckAccess()) { readOnlyRegion.EndOffset = textEditor.Document.TextLength;
readOnlyRegion.EndOffset = textEditor.Document.TextLength;
} else {
Action action = MakeCurrentContentReadOnly;
dispatcher.Invoke(action);
}
} }
public void ShowCompletionWindow(PythonConsoleCompletionDataProvider completionDataProvider) public void ShowCompletionWindow(PythonConsoleCompletionDataProvider completionDataProvider)
@ -157,8 +131,6 @@ namespace ICSharpCode.PythonBinding
} }
completionWindow.ExpectInsertionBeforeStart = true; completionWindow.ExpectInsertionBeforeStart = true;
completionWindow.Show(); completionWindow.Show();
Action<CompletionWindow> action = ShowCompletionWindow;
completionWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, action, completionWindow);
} }
void ShowCompletionWindow(CompletionWindow window) void ShowCompletionWindow(CompletionWindow window)

33
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOutputWindowPadDescriptor.cs

@ -1,33 +0,0 @@
// <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;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Implements the IPadDescriptor interface and
/// wraps access to the actual PadDescriptor for the
/// Output Window pad.
/// </summary>
public class PythonOutputWindowPadDescriptor : IPadDescriptor
{
PadDescriptor pad;
public PythonOutputWindowPadDescriptor()
{
pad = WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView));
}
public void BringPadToFront()
{
pad.BringPadToFront();
}
}
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTextEditorViewContent.cs

@ -20,9 +20,9 @@ namespace ICSharpCode.PythonBinding
ITextEditor textEditor; ITextEditor textEditor;
ITextEditorOptions textEditorOptions; ITextEditorOptions textEditorOptions;
public PythonTextEditorViewContent(IWorkbench workbench) public PythonTextEditorViewContent(IPythonWorkbench workbench)
{ {
Init(workbench.ActiveWorkbenchWindow.ActiveViewContent); Init(workbench.ActiveViewContent);
} }
public PythonTextEditorViewContent(IViewContent view) public PythonTextEditorViewContent(IViewContent view)

33
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonWorkbench.cs

@ -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 ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PythonBinding
{
public class PythonWorkbench : IPythonWorkbench
{
IWorkbench workbench;
public PythonWorkbench()
{
workbench = WorkbenchSingleton.Workbench;
}
public IViewContent ActiveViewContent {
get { return workbench.ActiveViewContent; }
}
public IPythonConsolePad GetPythonConsolePad()
{
PadDescriptor padDescriptor = workbench.GetPad(typeof(PythonConsolePad));
return padDescriptor.PadContent as IPythonConsolePad;
}
}
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunDebugPythonCommand.cs

@ -15,14 +15,14 @@ namespace ICSharpCode.PythonBinding
{ {
public class RunDebugPythonCommand : RunPythonCommand public class RunDebugPythonCommand : RunPythonCommand
{ {
public RunDebugPythonCommand(IWorkbench workbench, PythonAddInOptions options, IDebugger debugger) public RunDebugPythonCommand(IPythonWorkbench workbench, PythonAddInOptions options, IDebugger debugger)
: base(workbench, options, debugger) : base(workbench, options, debugger)
{ {
Debug = true; Debug = true;
} }
public RunDebugPythonCommand() public RunDebugPythonCommand()
: this(WorkbenchSingleton.Workbench, new PythonAddInOptions(), DebuggerService.CurrentDebugger) : this(new PythonWorkbench(), new PythonAddInOptions(), DebuggerService.CurrentDebugger)
{ {
} }
} }

8
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs

@ -23,15 +23,15 @@ namespace ICSharpCode.PythonBinding
{ {
IDebugger debugger; IDebugger debugger;
PythonAddInOptions options; PythonAddInOptions options;
IWorkbench workbench; IPythonWorkbench workbench;
PythonConsoleApplication ipy; PythonConsoleApplication ipy;
public RunPythonCommand() public RunPythonCommand()
: this(WorkbenchSingleton.Workbench, new PythonAddInOptions(), DebuggerService.CurrentDebugger) : this(new PythonWorkbench(), new PythonAddInOptions(), DebuggerService.CurrentDebugger)
{ {
} }
public RunPythonCommand(IWorkbench workbench, PythonAddInOptions options, IDebugger debugger) public RunPythonCommand(IPythonWorkbench workbench, PythonAddInOptions options, IDebugger debugger)
{ {
this.workbench = workbench; this.workbench = workbench;
this.debugger = debugger; this.debugger = debugger;
@ -56,7 +56,7 @@ namespace ICSharpCode.PythonBinding
ProcessStartInfo GetProcessStartInfo() ProcessStartInfo GetProcessStartInfo()
{ {
string scriptFileName = workbench.ActiveWorkbenchWindow.ActiveViewContent.PrimaryFileName; string scriptFileName = workbench.ActiveViewContent.PrimaryFileName;
ipy.PythonScriptFileName = scriptFileName; ipy.PythonScriptFileName = scriptFileName;
ipy.WorkingDirectory = Path.GetDirectoryName(scriptFileName); ipy.WorkingDirectory = Path.GetDirectoryName(scriptFileName);
return ipy.GetProcessStartInfo(); return ipy.GetProcessStartInfo();

73
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendLineToPythonConsoleCommand.cs

@ -0,0 +1,73 @@
// <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.Core;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PythonBinding
{
public class SendLineToPythonConsoleCommand : AbstractCommand
{
IPythonWorkbench workbench;
IPythonConsolePad consolePad;
PythonTextEditorViewContent textEditorView;
ITextEditor activeTextEditor;
IPythonConsole pythonConsole;
string lineFromActiveTextEditor;
public SendLineToPythonConsoleCommand()
: this(new PythonWorkbench())
{
}
public SendLineToPythonConsoleCommand(IPythonWorkbench workbench)
{
this.workbench = workbench;
textEditorView = new PythonTextEditorViewContent(workbench);
activeTextEditor = textEditorView.TextEditor;
}
public override void Run()
{
GetLineFromActiveTextEditor();
GetPythonConsolePad();
ShowPythonConsolePad();
AppendLineToPythonConsole();
}
void GetLineFromActiveTextEditor()
{
int lineNumber = activeTextEditor.Caret.Line;
IDocumentLine documentLine = activeTextEditor.Document.GetLine(lineNumber);
lineFromActiveTextEditor = documentLine.Text;
}
void GetPythonConsolePad()
{
consolePad = workbench.GetPythonConsolePad();
}
void ShowPythonConsolePad()
{
consolePad.BringToFront();
}
void AppendLineToPythonConsole()
{
GetPythonConsole();
pythonConsole.SendLine(lineFromActiveTextEditor);
}
void GetPythonConsole()
{
pythonConsole = consolePad.PythonConsole;
}
}
}

39
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/StringListLock.cs

@ -0,0 +1,39 @@
// <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.Collections.Generic;
using System.Threading;
namespace ICSharpCode.PythonBinding
{
public class StringListLock : ILock
{
List<string> lines;
public StringListLock(List<string> lines)
{
this.lines = lines;
Lock();
}
void Lock()
{
Monitor.Enter(lines);
}
public void Dispose()
{
Unlock();
}
void Unlock()
{
Monitor.Exit(lines);
}
}
}

117
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ThreadSafePythonConsoleTextEditor.cs

@ -0,0 +1,117 @@
// <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.AvalonEdit;
namespace ICSharpCode.PythonBinding
{
public class ThreadSafePythonConsoleTextEditor : IConsoleTextEditor
{
delegate string GetLineInvoker(int index);
IConsoleTextEditor consoleTextEditor;
IControlDispatcher dispatcher;
public ThreadSafePythonConsoleTextEditor(TextEditor textEditor)
: this(new PythonConsoleTextEditor(textEditor), new ControlDispatcher(textEditor))
{
}
public ThreadSafePythonConsoleTextEditor(IConsoleTextEditor consoleTextEditor, IControlDispatcher dispatcher)
{
this.consoleTextEditor = consoleTextEditor;
this.dispatcher = dispatcher;
}
public event ConsoleTextEditorKeyEventHandler PreviewKeyDown {
add { consoleTextEditor.PreviewKeyDown += value; }
remove { consoleTextEditor.PreviewKeyDown -= value; }
}
public void Dispose()
{
consoleTextEditor.Dispose();
}
public int Column {
get { return consoleTextEditor.Column; }
set { consoleTextEditor.Column = value; }
}
public int SelectionLength {
get { return consoleTextEditor.SelectionLength; }
}
public int SelectionStart {
get { return consoleTextEditor.SelectionStart; }
}
public int Line {
get { return consoleTextEditor.Line; }
set { consoleTextEditor.Line = value; }
}
public int TotalLines {
get { return consoleTextEditor.TotalLines; }
}
public bool IsCompletionWindowDisplayed {
get { return consoleTextEditor.IsCompletionWindowDisplayed; }
}
public void Write(string text)
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.Write(text);
} else {
Action<string> action = Write;
dispatcher.Invoke(action, text);
}
}
public void Replace(int index, int length, string text)
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.Replace(index, length, text);
} else {
Action<int, int, string> action = Replace;
dispatcher.Invoke(action, index, length, text);
}
}
public string GetLine(int index)
{
if (dispatcher.CheckAccess()) {
return consoleTextEditor.GetLine(index);
} else {
GetLineInvoker invoker = new GetLineInvoker(GetLine);
return (string)dispatcher.Invoke(invoker, index);
}
}
public void ShowCompletionWindow(PythonConsoleCompletionDataProvider completionDataProvider)
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.ShowCompletionWindow(completionDataProvider);
} else {
Action<PythonConsoleCompletionDataProvider> action = ShowCompletionWindow;
dispatcher.Invoke(action, completionDataProvider);
}
}
public void MakeCurrentContentReadOnly()
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.MakeCurrentContentReadOnly();
} else {
Action action = MakeCurrentContentReadOnly;
dispatcher.Invoke(action);
}
}
}
}

806
src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInFileTestFixture.cs

@ -1,806 +0,0 @@
// <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.Collections.Generic;
using System.IO;
using System.Reflection;
using ICSharpCode.Core;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Configuration
{
/// <summary>
/// Basic PythonBinding.addin file tests.
/// </summary>
[TestFixture]
public class AddInFileTestFixture
{
AddIn addin;
Codon fileFilterCodon;
Codon pythonMenuCodon;
Codon pythonRunMenuItemCodon;
Codon pythonWithoutDebuggerRunMenuItemCodon;
Codon pythonStopMenuItemCodon;
Codon fileTemplatesCodon;
Codon optionsPanelCodon;
Codon parserCodon;
Runtime pythonBindingRuntime;
Codon additionalMSBuildPropertiesCodon;
Codon projectBindingCodon;
Codon projectFileFilterCodon;
Codon codeCompletionBindingCodon;
Codon applicationSettingsOptionsCodon;
Codon buildEventsCodon;
Codon compilingOptionsCodon;
Codon debugOptionsCodon;
AddInReference formsDesignerAddInRef;
Runtime formsDesignerRuntime;
Codon displayBindingCodon;
Codon convertCodeCodon;
Codon pythonFileIconCodon;
Codon pythonProjectIconCodon;
Codon convertCSharpProjectCodon;
Codon convertVBNetProjectCodon;
Codon formattingStrategyCodon;
Runtime sharpdevelopRuntime;
Runtime ironpythonModulesRuntime;
Runtime unitTestingRuntime;
Codon testFrameworkCodon;
Codon languageBindingCodon;
[TestFixtureSetUp]
public void SetupFixture()
{
using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
addin = AddIn.Load(reader, String.Empty);
fileFilterCodon = GetCodon("/SharpDevelop/Workbench/FileFilter", "Python");
pythonMenuCodon = GetCodon("/SharpDevelop/Workbench/MainMenu", "Python");
displayBindingCodon = GetCodon("/SharpDevelop/Workbench/DisplayBindings", "PythonDisplayBinding");
const string runMenuExtensionPath = "/SharpDevelop/Workbench/MainMenu/Python";
pythonRunMenuItemCodon = GetCodon(runMenuExtensionPath, "Run");
pythonWithoutDebuggerRunMenuItemCodon = GetCodon(runMenuExtensionPath, "RunWithoutDebugger");
pythonStopMenuItemCodon = GetCodon(runMenuExtensionPath, "Stop");
fileTemplatesCodon = GetCodon("/SharpDevelop/BackendBindings/Templates", "Python");
optionsPanelCodon = GetCodon("/SharpDevelop/Dialogs/OptionsDialog/ToolsOptions", "PythonOptionsPanel");
parserCodon = GetCodon("/Workspace/Parser", "Python");
additionalMSBuildPropertiesCodon = GetCodon("/SharpDevelop/MSBuildEngine/AdditionalProperties", "PythonBinPath");
projectBindingCodon = GetCodon("/SharpDevelop/Workbench/ProjectBindings", "Python");
projectFileFilterCodon = GetCodon("/SharpDevelop/Workbench/Combine/FileFilter", "PythonProject");
codeCompletionBindingCodon = GetCodon("/AddIns/DefaultTextEditor/CodeCompletion", "Python");
applicationSettingsOptionsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "Application");
buildEventsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "BuildEvents");
compilingOptionsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "CompilingOptions");
debugOptionsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "DebugOptions");
convertCodeCodon = GetCodon("/SharpDevelop/Workbench/MainMenu/Tools/ConvertCode", "ConvertToPython");
pythonFileIconCodon = GetCodon("/Workspace/Icons", "PythonFileIcon");
pythonProjectIconCodon = GetCodon("/Workspace/Icons", "PythonProjectIcon");
convertCSharpProjectCodon = GetCodon("/SharpDevelop/Pads/ProjectBrowser/ContextMenu/ProjectActions/Convert", "CSharpProjectToPythonProjectConverter");
convertVBNetProjectCodon = GetCodon("/SharpDevelop/Pads/ProjectBrowser/ContextMenu/ProjectActions/Convert", "VBNetProjectToPythonProjectConverter");
formattingStrategyCodon = GetCodon("/AddIns/DefaultTextEditor/Formatter/Python", "PythonFormatter");
testFrameworkCodon = GetCodon("/SharpDevelop/UnitTesting/TestFrameworks", "pyunit");
languageBindingCodon = GetCodon("/SharpDevelop/Workbench/LanguageBindings", "Python");
// Get the PythonBinding runtime.
foreach (Runtime runtime in addin.Runtimes) {
if (runtime.Assembly == "PythonBinding.dll") {
pythonBindingRuntime = runtime;
} else if (runtime.Assembly == "$ICSharpCode.FormsDesigner/FormsDesigner.dll") {
formsDesignerRuntime = runtime;
} else if (runtime.Assembly == "IronPython.Modules.dll") {
ironpythonModulesRuntime = runtime;
} else if (runtime.Assembly == ":ICSharpCode.SharpDevelop") {
sharpdevelopRuntime = runtime;
} else if (runtime.Assembly == "$ICSharpCode.UnitTesting/UnitTesting.dll") {
unitTestingRuntime = runtime;
}
}
// Get the forms designer dependency.
foreach (AddInReference addInRef in addin.Manifest.Dependencies) {
if (addInRef.Name == "ICSharpCode.FormsDesigner") {
formsDesignerAddInRef = addInRef;
break;
}
}
}
}
[Test]
public void AddInName()
{
Assert.AreEqual(addin.Name, "Python Binding");
}
[Test]
public void ManifestId()
{
Assert.AreEqual("ICSharpCode.PythonBinding", addin.Manifest.PrimaryIdentity);
}
[Test]
public void FormsDesignerAddInIsDependency()
{
Assert.IsNotNull(formsDesignerAddInRef);
}
[Test]
public void FormsDesignerRuntimeExists()
{
Assert.IsNotNull(formsDesignerRuntime);
}
[Test]
public void PythonBindingRuntimeExists()
{
Assert.IsNotNull(pythonBindingRuntime);
}
[Test]
public void ICSharpCodeSharpDevelopRuntimeExists()
{
Assert.IsNotNull(sharpdevelopRuntime);
}
[Test]
public void IronPythonModulesRuntimeExists()
{
Assert.IsNotNull(ironpythonModulesRuntime);
}
[Test]
public void UnitTestingRuntimeExists()
{
Assert.IsNotNull(unitTestingRuntime);
}
[Test]
public void FileFilterExists()
{
Assert.IsNotNull(fileFilterCodon);
}
[Test]
public void FileFilterExtension()
{
Assert.AreEqual("*.py", fileFilterCodon["extensions"]);
}
[Test]
public void FileFilterInsertBefore()
{
Assert.AreEqual("Resources", fileFilterCodon.InsertBefore);
}
[Test]
public void FileFilterInsertAfter()
{
Assert.AreEqual("Icons", fileFilterCodon.InsertAfter);
}
[Test]
public void PythonMenuName()
{
Assert.AreEqual("&Python", pythonMenuCodon["label"]);
}
[Test]
public void PythonMenuCodon()
{
Assert.AreEqual("MenuItem", pythonMenuCodon.Name);
}
[Test]
public void PythonMenuCodonType()
{
Assert.AreEqual("Menu", pythonMenuCodon["type"]);
}
[Test]
public void PythonMenuInsertBefore()
{
Assert.AreEqual("Tools", pythonMenuCodon.InsertBefore);
}
[Test]
public void PythonMenuInsertAfter()
{
Assert.AreEqual("Search", pythonMenuCodon.InsertAfter);
}
[Test]
public void PythonMenuConditionExists()
{
Assert.AreEqual(1, pythonMenuCodon.Conditions.Length);
}
[Test]
public void PythonMenuConditionName()
{
ICondition condition = pythonMenuCodon.Conditions[0];
Assert.AreEqual("ActiveContentExtension", condition.Name);
}
[Test]
public void PythonMenuConditionActiveExtension()
{
Condition condition = pythonMenuCodon.Conditions[0] as Condition;
Assert.AreEqual(".py", condition["activeextension"]);
}
[Test]
public void PythonStopMenuItemLabel()
{
Assert.AreEqual("${res:XML.MainMenu.DebugMenu.Stop}", pythonStopMenuItemCodon["label"]);
}
[Test]
public void PythonStopMenuItemIsMenuItem()
{
Assert.AreEqual("MenuItem", pythonStopMenuItemCodon.Name);
}
[Test]
public void PythonStopMenuItemClass()
{
Assert.AreEqual("ICSharpCode.SharpDevelop.Project.Commands.StopDebuggingCommand", pythonStopMenuItemCodon["class"]);
}
[Test]
public void PythonStopMenuItemIcon()
{
Assert.AreEqual("Icons.16x16.StopProcess", pythonStopMenuItemCodon["icon"]);
}
[Test]
public void PythonRunMenuItemLabel()
{
Assert.AreEqual("${res:XML.MainMenu.RunMenu.Run}", pythonRunMenuItemCodon["label"]);
}
[Test]
public void PythonRunMenuItemIsMenuItem()
{
Assert.AreEqual("MenuItem", pythonRunMenuItemCodon.Name);
}
[Test]
public void PythonRunMenuItemClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.RunDebugPythonCommand", pythonRunMenuItemCodon["class"]);
}
[Test]
public void PythonRunMenuItemShortcut()
{
Assert.AreEqual("Control|Shift|R", pythonRunMenuItemCodon["shortcut"]);
}
[Test]
public void PythonRunMenuItemIcon()
{
Assert.AreEqual("Icons.16x16.RunProgramIcon", pythonRunMenuItemCodon["icon"]);
}
[Test]
public void PythonRunMenuHasSingleCondition()
{
Assert.AreEqual(1, pythonRunMenuItemCodon.Conditions.Length);
}
[Test]
public void PythonRunMenuConditionName()
{
Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.IsNotNull("IsProcessRunning", condition.Name);
}
[Test]
public void PythonRunMenuConditionIsDebuggingProperty()
{
Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("False", condition["isdebugging"]);
}
[Test]
public void PythonRunMenuConditionIsProcessRunningProperty()
{
Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("False", condition["isprocessrunning"]);
}
[Test]
public void PythonRunMenuConditionAction()
{
ICondition condition = pythonRunMenuItemCodon.Conditions[0];
Assert.AreEqual(ConditionFailedAction.Disable, condition.Action);
}
[Test]
public void PythonStopMenuHasSingleCondition()
{
Assert.AreEqual(1, pythonStopMenuItemCodon.Conditions.Length);
}
[Test]
public void PythonStopMenuConditionName()
{
Condition condition = pythonStopMenuItemCodon.Conditions[0] as Condition;
Assert.IsNotNull("IsProcessRunning", condition.Name);
}
[Test]
public void PythonStopMenuConditionIsDebuggingProperty()
{
Condition condition = pythonStopMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("True", condition["isdebugging"]);
}
[Test]
public void PythonStopMenuConditionAction()
{
ICondition condition = pythonStopMenuItemCodon.Conditions[0];
Assert.AreEqual(ConditionFailedAction.Disable, condition.Action);
}
[Test]
public void FileTemplatesCodonType()
{
Assert.AreEqual("Directory", fileTemplatesCodon.Name);
}
[Test]
public void FileTemplatesFolder()
{
Assert.AreEqual("./Templates", fileTemplatesCodon["path"]);
}
[Test]
public void OptionsPanelCodonIsDialogPanel()
{
Assert.AreEqual("OptionPanel", optionsPanelCodon.Name);
}
[Test]
public void OptionsPanelLabel()
{
Assert.AreEqual("Python", optionsPanelCodon["label"]);
}
[Test]
public void OptionsPanelClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.PythonOptionsPanel", optionsPanelCodon["class"]);
}
[Test]
public void SupportedParserExtensions()
{
Assert.AreEqual(".py", parserCodon["supportedextensions"]);
}
[Test]
public void ParserClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.PythonParser", parserCodon["class"]);
}
[Test]
public void ParserProjectFileExtensions()
{
Assert.AreEqual(".pyproj", parserCodon["projectfileextension"]);
}
[Test]
public void PythonBinPath()
{
Assert.AreEqual("${AddInPath:ICSharpCode.PythonBinding}", additionalMSBuildPropertiesCodon["text"]);
}
[Test]
public void ProjectBindingSupportedExtensions()
{
Assert.AreEqual(".py", projectBindingCodon["supportedextensions"]);
}
[Test]
public void ProjectBindingGuid()
{
Assert.AreEqual("{FD48973F-F585-4F70-812B-4D0503B36CE9}", projectBindingCodon["guid"]);
}
[Test]
public void ProjectBindingProjectFileExtension()
{
Assert.AreEqual(".pyproj", projectBindingCodon["projectfileextension"]);
}
[Test]
public void ProjectBindingClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.PythonProjectBinding", projectBindingCodon["class"]);
}
[Test]
public void ProjectFileFilterExtensions()
{
Assert.AreEqual("*.pyproj", projectFileFilterCodon["extensions"]);
}
[Test]
public void ProjectFileFilterClass()
{
Assert.AreEqual("ICSharpCode.SharpDevelop.Project.LoadProject", projectFileFilterCodon["class"]);
}
[Test]
public void ProjectFileFilterInsertBefore()
{
Assert.AreEqual("AllFiles", projectFileFilterCodon.InsertBefore);
}
[Test]
public void CodeCompletionBindingCodonName()
{
Assert.AreEqual("CodeCompletionBinding", codeCompletionBindingCodon.Name);
}
[Test]
public void CodeCompletionBindingFileExtensions()
{
Assert.AreEqual(".py", codeCompletionBindingCodon["extensions"]);
}
[Test]
public void CodeCompletionBindingClassName()
{
Assert.AreEqual("ICSharpCode.PythonBinding.PythonCodeCompletionBinding", codeCompletionBindingCodon["class"]);
}
[Test]
public void ApplicationSettingsCodonClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.ApplicationSettingsPanel", applicationSettingsOptionsCodon["class"]);
}
[Test]
public void ApplicationSettingsCodonLabel()
{
Assert.AreEqual("${res:Dialog.ProjectOptions.ApplicationSettings}", applicationSettingsOptionsCodon["label"]);
}
[Test]
public void BuildEventsCodonClass()
{
Assert.AreEqual("ICSharpCode.SharpDevelop.Gui.OptionPanels.BuildEvents", buildEventsCodon["class"]);
}
[Test]
public void BuildEventsCodonLabel()
{
Assert.AreEqual("${res:Dialog.ProjectOptions.BuildEvents}", buildEventsCodon["label"]);
}
[Test]
public void CompilingOptionsCodonClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.CompilingOptionsPanel", compilingOptionsCodon["class"]);
}
[Test]
public void CompilingOptionsCodonLabel()
{
Assert.AreEqual("${res:Dialog.ProjectOptions.BuildOptions}", compilingOptionsCodon["label"]);
}
[Test]
public void DebugOptionsCodonClass()
{
Assert.AreEqual("ICSharpCode.SharpDevelop.Gui.OptionPanels.DebugOptions", debugOptionsCodon["class"]);
}
[Test]
public void DebugOptionsCodonLabel()
{
Assert.AreEqual("${res:Dialog.ProjectOptions.DebugOptions}", debugOptionsCodon["label"]);
}
[Test]
public void PythonDisplayBindingExists()
{
Assert.IsNotNull(displayBindingCodon);
}
[Test]
public void PythonDisplayBindingIsSecondary()
{
Assert.AreEqual("Secondary", displayBindingCodon["type"]);
}
[Test]
public void PythonDisplayBindingFileNamePattern()
{
Assert.AreEqual(@"\.py$", displayBindingCodon["fileNamePattern"]);
}
[Test]
public void PythonDisplayBindingLanguagePattern()
{
Assert.AreEqual(@"^Python$", displayBindingCodon["languagePattern"]);
}
[Test]
public void PythonDisplayBindingClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.PythonFormsDesignerDisplayBinding", displayBindingCodon["class"]);
}
[Test]
public void ConvertCodeCodonExists()
{
Assert.IsNotNull(convertCodeCodon);
}
[Test]
public void ConvertCodeCodonIsMenuItem()
{
Assert.AreEqual("MenuItem", convertCodeCodon.Name);
}
[Test]
public void ConvertCodeCodonInsertedAfterCSharp()
{
Assert.AreEqual("CSharp", convertCodeCodon.InsertAfter);
}
[Test]
public void ConvertCodeCodonInsertedBeforeVBNet()
{
Assert.AreEqual("VBNet", convertCodeCodon.InsertBefore);
}
[Test]
public void ConvertCodeCodonLabel()
{
Assert.AreEqual("Python", convertCodeCodon["label"]);
}
[Test]
public void ConvertCodeCodonClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.ConvertToPythonMenuCommand", convertCodeCodon["class"]);
}
[Test]
public void ConvertCodeMenuConditionAction()
{
ICondition condition = convertCodeCodon.Conditions[0];
Assert.AreEqual(ConditionFailedAction.Disable, condition.Action);
}
[Test]
public void ConvertCodeMenuConditionName()
{
ICondition condition = convertCodeCodon.Conditions[0];
Assert.AreEqual("ActiveContentExtension Or ActiveContentExtension", condition.Name);
}
[Test]
public void ConvertCodeMenuConditionIsOrCondition()
{
OrCondition orCondition = convertCodeCodon.Conditions[0] as OrCondition;
Assert.IsNotNull(orCondition);
}
[Test]
public void ConvertCodeMenuConditionActiveExtension()
{
OrCondition orCondition = convertCodeCodon.Conditions[0] as OrCondition;
// Use reflection to get the ICondition associated with the not
// condition.
Type type = orCondition.GetType();
FieldInfo fieldInfo = type.GetField("conditions", BindingFlags.NonPublic | BindingFlags.Instance);
ICondition[] conditions = fieldInfo.GetValue(orCondition) as ICondition[];
Condition csharpCondition = conditions[0] as Condition;
Condition vbnetCondition = conditions[1] as Condition;
Assert.AreEqual(2, conditions.Length);
Assert.AreEqual(".cs", csharpCondition["activeextension"]);
Assert.AreEqual(".vb", vbnetCondition["activeextension"]);
}
[Test]
public void PythonFileIconCodonExists()
{
Assert.IsNotNull(pythonFileIconCodon);
}
[Test]
public void PythonFileIconCodonExtensions()
{
Assert.AreEqual(".py", pythonFileIconCodon["extensions"]);
}
[Test]
public void PythonFileIconCodonResource()
{
Assert.AreEqual("Python.ProjectBrowser.File", pythonFileIconCodon["resource"]);
}
[Test]
public void PythonProjectIconCodonExists()
{
Assert.IsNotNull(pythonProjectIconCodon);
}
[Test]
public void PythonProjectIconCodonLanguage()
{
Assert.AreEqual("Python", pythonProjectIconCodon["language"]);
}
[Test]
public void PythonProjectIconCodonResource()
{
Assert.AreEqual("Python.ProjectBrowser.Project", pythonProjectIconCodon["resource"]);
}
[Test]
public void ConvertToCSharpProjectCodonExists()
{
Assert.IsNotNull(convertCSharpProjectCodon);
}
[Test]
public void ConvertToVBNetProjectCodonExists()
{
Assert.IsNotNull(convertVBNetProjectCodon);
}
[Test]
public void ConvertToCSharpProjectLabel()
{
Assert.AreEqual("${res:ICSharpCode.PythonBinding.ConvertCSharpProjectToPythonProject}", convertCSharpProjectCodon["label"]);
}
[Test]
public void ConvertToVBNetProjectLabel()
{
Assert.AreEqual("${res:ICSharpCode.PythonBinding.ConvertVBNetProjectToPythonProject}", convertVBNetProjectCodon["label"]);
}
[Test]
public void ConvertToCSharpProjectClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.ConvertProjectToPythonProjectCommand", convertCSharpProjectCodon["class"]);
}
[Test]
public void ConvertToVBNetProjectClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.ConvertProjectToPythonProjectCommand", convertVBNetProjectCodon["class"]);
}
[Test]
public void ConvertToCSharpProjectConditionName()
{
ICondition condition = convertCSharpProjectCodon.Conditions[0];
Assert.AreEqual("ProjectActive", condition.Name);
}
[Test]
public void ConvertToCSharpProjectConditionActiveExtension()
{
Condition condition = convertCSharpProjectCodon.Conditions[0] as Condition;
Assert.AreEqual("C#", condition["activeproject"]);
}
[Test]
public void ConvertToVBNetProjectConditionName()
{
ICondition condition = convertVBNetProjectCodon.Conditions[0];
Assert.AreEqual("ProjectActive", condition.Name);
}
[Test]
public void ConvertToVBNetProjectConditionActiveExtension()
{
Condition condition = convertVBNetProjectCodon.Conditions[0] as Condition;
Assert.AreEqual("VBNet", condition["activeproject"]);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemLabel()
{
Assert.AreEqual("${res:XML.MainMenu.DebugMenu.RunWithoutDebug}", pythonWithoutDebuggerRunMenuItemCodon["label"]);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemIsMenuItem()
{
Assert.AreEqual("MenuItem", pythonWithoutDebuggerRunMenuItemCodon.Name);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.RunPythonCommand", pythonWithoutDebuggerRunMenuItemCodon["class"]);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemShortcut()
{
Assert.AreEqual("Control|Shift|W", pythonWithoutDebuggerRunMenuItemCodon["shortcut"]);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemIcon()
{
Assert.AreEqual("Icons.16x16.Debug.StartWithoutDebugging", pythonWithoutDebuggerRunMenuItemCodon["icon"]);
}
[Test]
public void PythonDebugRunMenuHasSingleCondition()
{
Assert.AreEqual(1, pythonWithoutDebuggerRunMenuItemCodon.Conditions.Length);
}
[Test]
public void PythonDebugRunConditionIsSameAsPythonRunCondition()
{
Assert.AreEqual(pythonWithoutDebuggerRunMenuItemCodon.Conditions[0], pythonRunMenuItemCodon.Conditions[0]);
}
[Test]
public void TestFrameworkCodonExists()
{
Assert.IsNotNull(testFrameworkCodon);
}
[Test]
public void TestFrameworkClassIsPythonTestFrameworks()
{
Assert.AreEqual("ICSharpCode.PythonBinding.PythonTestFramework", testFrameworkCodon["class"]);
}
[Test]
public void TestFrameworkSupportedProjectsIsPythonProject()
{
Assert.AreEqual(".pyproj", testFrameworkCodon["supportedProjects"]);
}
[Test]
public void LanguageBindingCodonExists()
{
Assert.IsNotNull(languageBindingCodon);
}
[Test]
public void LanguageBindingClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.PythonLanguageBinding", languageBindingCodon["class"]);
}
[Test]
public void LanguageBindingFileExtensions()
{
Assert.AreEqual(".py", languageBindingCodon["extensions"]);
}
Codon GetCodon(string name, string extensionPath)
{
return AddInHelper.GetCodon(addin, name, extensionPath);
}
}
}

111
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/ConsoleTextEditorThreadSafetyTestFixture.cs

@ -1,111 +0,0 @@
// <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.Collections.Generic;
using System.Threading;
using System.Windows.Input;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
using PythonBinding.Tests.Utils.Tests;
namespace PythonBinding.Tests.Console
{
[TestFixture]
public class ConsoleTextEditorThreadSafetyTestFixture
{
PythonConsoleTextEditor consoleTextEditor;
TextEditor avalonEditTextEditor;
MockControlDispatcher dispatcher;
[TestFixtureSetUp]
public void SetUpFixture()
{
avalonEditTextEditor = new TextEditor();
dispatcher = new MockControlDispatcher();
consoleTextEditor = new PythonConsoleTextEditor(avalonEditTextEditor, dispatcher);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseWriteMethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
consoleTextEditor.Write("abc");
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseWriteMethodIsInvokedWithTextAsArg()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
consoleTextEditor.Write("abc");
object[] expectedArgs = new object[] { "abc" };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseGetLineMethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
consoleTextEditor.GetLine(0);
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseGetLineMethodIsInvokedWithLineNumberAsArg()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
consoleTextEditor.GetLine(0);
object[] expectedArgs = new object[] { 0 };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseReplaceMethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
avalonEditTextEditor.Text = "abcd";
consoleTextEditor.Replace(0, 2, "12");
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseReplaceethodIsInvokedWithThreeArgs()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
avalonEditTextEditor.Text = "abcd";
consoleTextEditor.Replace(0, 2, "12");
object[] expectedArgs = new object[] { 0, 2, "12" };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseMakeCurrentContentReadOnlyIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
consoleTextEditor.MakeCurrentContentReadOnly();
Assert.IsNotNull(dispatcher.MethodInvoked);
}
}
}

12
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs

@ -16,21 +16,21 @@ namespace PythonBinding.Tests.Console
/// Tests the disposing of the PythonConsole. /// Tests the disposing of the PythonConsole.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class DisposedPythonConsoleTestFixture public class DisposedPythonConsoleTestFixture : PythonConsoleTestsBase
{ {
[Test] [Test]
public void PythonConsoleImplementsIDisposable() public void PythonConsoleImplementsIDisposable()
{ {
PythonConsole console = new PythonConsole(new MockConsoleTextEditor(), null); base.CreatePythonConsole();
Assert.IsNotNull(console as IDisposable); Assert.IsNotNull(TestablePythonConsole as IDisposable);
} }
[Test] [Test]
public void ReadLineReturnsNullWhenConsoleDisposed() public void ReadLineReturnsNullWhenConsoleDisposed()
{ {
PythonConsole console = new PythonConsole(new MockConsoleTextEditor(), null); base.CreatePythonConsole();
console.Dispose(); TestablePythonConsole.Dispose();
Assert.IsNull(console.ReadLine(0)); Assert.IsNull(TestablePythonConsole.ReadLine(0));
} }
} }
} }

23
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs

@ -21,36 +21,33 @@ namespace PythonBinding.Tests.Console
/// that the up, down, home and end key do not close this window. /// that the up, down, home and end key do not close this window.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class KeysPressedWhenCompletionWindowOpenTestFixture public class KeysPressedWhenCompletionWindowOpenTestFixture : PythonConsoleTestsBase
{ {
PythonConsole pythonConsole;
MockConsoleTextEditor textEditor;
string prompt = ">>> "; string prompt = ">>> ";
[SetUp] [SetUp]
public void Init() public void Init()
{ {
textEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
pythonConsole = new PythonConsole(textEditor, null); TestablePythonConsole.Write(prompt, Style.Prompt);
pythonConsole.Write(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
pythonConsole.Write(prompt, Style.Prompt); TestablePythonConsole.Write(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
textEditor.RaisePreviewKeyDownEvent(Key.OemPeriod); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.OemPeriod);
} }
[Test] [Test]
public void UpKeyDoesNothing() public void UpKeyDoesNothing()
{ {
Assert.IsFalse(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up)); Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up));
} }
[Test] [Test]
public void DownKeyDoesNothing() public void DownKeyDoesNothing()
{ {
Assert.IsFalse(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down));
} }
} }
} }

19
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs

@ -20,29 +20,26 @@ namespace PythonBinding.Tests.Console
/// When the dot character is typed in after an object the code completion window should appear. /// When the dot character is typed in after an object the code completion window should appear.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleCodeCompletionTestFixture public class PythonConsoleCodeCompletionTestFixture : PythonConsoleTestsBase
{ {
MockConsoleTextEditor textEditor;
PythonConsole console;
string prompt = ">>> "; string prompt = ">>> ";
bool showCompletionWindowCalledBeforeDotTypedIn; bool showCompletionWindowCalledBeforeDotTypedIn;
[TestFixtureSetUp] [TestFixtureSetUp]
public void SetUpFixture() public void SetUpFixture()
{ {
textEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
console = new PythonConsole(textEditor, null); TestablePythonConsole.WriteLine(prompt, Style.Prompt);
console.WriteLine(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
showCompletionWindowCalledBeforeDotTypedIn = textEditor.IsShowCompletionWindowCalled; showCompletionWindowCalledBeforeDotTypedIn = MockConsoleTextEditor.IsShowCompletionWindowCalled;
textEditor.RaisePreviewKeyDownEvent(Key.OemPeriod); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.OemPeriod);
} }
[Test] [Test]
public void ShowCompletionWindowCalled() public void ShowCompletionWindowCalled()
{ {
Assert.IsTrue(textEditor.IsShowCompletionWindowCalled); Assert.IsTrue(MockConsoleTextEditor.IsShowCompletionWindowCalled);
} }
[Test] [Test]
@ -54,7 +51,7 @@ namespace PythonBinding.Tests.Console
[Test] [Test]
public void PythonConsoleCompletionDataProviderPassedToShowCompletionWindowMethod() public void PythonConsoleCompletionDataProviderPassedToShowCompletionWindowMethod()
{ {
Assert.IsInstanceOf(typeof(PythonConsoleCompletionDataProvider), textEditor.CompletionDataProvider); Assert.IsInstanceOf(typeof(PythonConsoleCompletionDataProvider), MockConsoleTextEditor.CompletionProviderPassedToShowCompletionWindow);
} }
} }
} }

49
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCommandLineHistoryTestFixture.cs

@ -21,74 +21,71 @@ namespace PythonBinding.Tests.Console
/// Tests the PythonConsole's command line history. /// Tests the PythonConsole's command line history.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleCommandLineHistoryTestFixture public class PythonConsoleCommandLineHistoryTestFixture : PythonConsoleTestsBase
{ {
PythonConsole pythonConsole;
MockConsoleTextEditor textEditor;
string prompt = ">>> "; string prompt = ">>> ";
[SetUp] [SetUp]
public void Init() public void Init()
{ {
textEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
pythonConsole = new PythonConsole(textEditor, null); TestablePythonConsole.Write(prompt, Style.Prompt);
pythonConsole.Write(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
pythonConsole.Write(prompt, Style.Prompt); TestablePythonConsole.Write(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
textEditor.RaisePreviewKeyDownEvent(Key.C); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
pythonConsole.Write(prompt, Style.Prompt); TestablePythonConsole.Write(prompt, Style.Prompt);
} }
[Test] [Test]
public void UpArrowKeyPressed() public void UpArrowKeyPressed()
{ {
Assert.IsTrue(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up)); Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up));
} }
[Test] [Test]
public void CurrentLineAfterUpArrowKeyPressed() public void CurrentLineAfterUpArrowKeyPressed()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual("BC", pythonConsole.GetCurrentLine()); Assert.AreEqual("BC", TestablePythonConsole.GetCurrentLine());
} }
[Test] [Test]
public void TextEditorCursorIsAtEndOfLineAfterUpArrowKeyPressed() public void TextEditorCursorIsAtEndOfLineAfterUpArrowKeyPressed()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual(prompt.Length + 2, textEditor.Column); Assert.AreEqual(prompt.Length + 2, MockConsoleTextEditor.Column);
} }
[Test] [Test]
public void TextAfterUpArrowKeyPressedTwiceThenDownArrowKey() public void TextAfterUpArrowKeyPressedTwiceThenDownArrowKey()
{ {
UpArrowKeyPressedTwiceThenDownArrowKey(); UpArrowKeyPressedTwiceThenDownArrowKey();
Assert.AreEqual("BC", pythonConsole.GetCurrentLine()); Assert.AreEqual("BC", TestablePythonConsole.GetCurrentLine());
} }
[Test] [Test]
public void TextEditorCursorAfterUpArrowKeyPressedTwice() public void TextEditorCursorAfterUpArrowKeyPressedTwice()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual(prompt.Length + 1, textEditor.Column); Assert.AreEqual(prompt.Length + 1, MockConsoleTextEditor.Column);
} }
[Test] [Test]
public void DownArrowKeyHandled() public void DownArrowKeyHandled()
{ {
Assert.IsTrue(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down));
} }
void UpArrowKeyPressedTwiceThenDownArrowKey() void UpArrowKeyPressedTwiceThenDownArrowKey()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down);
} }
} }
} }

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCurrentLineTestFixture.cs

@ -23,16 +23,16 @@ namespace PythonBinding.Tests.Console
[TestFixture] [TestFixture]
public class PythonConsoleCurrentLineTestFixture public class PythonConsoleCurrentLineTestFixture
{ {
PythonConsole pythonConsole; TestablePythonConsole pythonConsole;
MockConsoleTextEditor textEditor; MockConsoleTextEditor textEditor;
string prompt = ">>> "; string prompt = ">>> ";
[SetUp] [SetUp]
public void Init() public void Init()
{ {
textEditor = new MockConsoleTextEditor(); pythonConsole = new TestablePythonConsole();
pythonConsole = new PythonConsole(textEditor, null);
pythonConsole.Write(prompt, Style.Prompt); pythonConsole.Write(prompt, Style.Prompt);
textEditor = pythonConsole.MockConsoleTextEditor;
} }
[Test] [Test]

35
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleEnterKeyTestFixture.cs

@ -20,47 +20,44 @@ namespace PythonBinding.Tests.Console
/// will break the line and move the last part to the second line. /// will break the line and move the last part to the second line.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleEnterKeyTestFixture public class PythonConsoleEnterKeyTestFixture : PythonConsoleTestsBase
{ {
MockConsoleTextEditor textEditor;
PythonConsole console;
string prompt = ">>> "; string prompt = ">>> ";
[SetUp] [SetUp]
public void Init() public void Init()
{ {
textEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
console = new PythonConsole(textEditor, null); TestablePythonConsole.Write(prompt, Style.Prompt);
console.Write(prompt, Style.Prompt);
} }
public void EnterKeyDoesNotBreakUpExistingLine() public void EnterKeyDoesNotBreakUpExistingLine()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
textEditor.SelectionStart = 1 + prompt.Length; MockConsoleTextEditor.SelectionStart = 1 + prompt.Length;
textEditor.Column = 1 + prompt.Length; MockConsoleTextEditor.Column = 1 + prompt.Length;
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
Assert.AreEqual(">>> AB\r\n", textEditor.Text); Assert.AreEqual(">>> AB\r\n", MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void PreviousLineIsReadOnlyAfterEnterPressed() public void PreviousLineIsReadOnlyAfterEnterPressed()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
console.Write(prompt, Style.Prompt); TestablePythonConsole.Write(prompt, Style.Prompt);
// Move up a line with cursor. // Move up a line with cursor.
textEditor.Line = 0; MockConsoleTextEditor.Line = 0;
textEditor.RaisePreviewKeyDownEvent(Key.C); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C);
string expectedText = string expectedText =
">>> AB\r\n" + ">>> AB\r\n" +
">>> "; ">>> ";
Assert.AreEqual(expectedText, textEditor.Text); Assert.AreEqual(expectedText, MockConsoleTextEditor.Text);
} }
} }
} }

19
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHomeKeyTestFixture.cs

@ -20,37 +20,34 @@ namespace PythonBinding.Tests.Console
/// The Home Key should return the user to the start of the line after the prompt. /// The Home Key should return the user to the start of the line after the prompt.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleHomeKeyTestFixture public class PythonConsoleHomeKeyTestFixture : PythonConsoleTestsBase
{ {
MockConsoleTextEditor textEditor;
PythonConsole console;
string prompt = ">>> "; string prompt = ">>> ";
[SetUp] [SetUp]
public void Init() public void Init()
{ {
textEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
console = new PythonConsole(textEditor, null); TestablePythonConsole.Write(prompt, Style.Prompt);
console.Write(prompt, Style.Prompt);
} }
[Test] [Test]
public void HomeKeyPressedWhenNoUserTextInConsole() public void HomeKeyPressedWhenNoUserTextInConsole()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Home); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Home);
int expectedColumn = prompt.Length; int expectedColumn = prompt.Length;
Assert.AreEqual(expectedColumn, textEditor.Column); Assert.AreEqual(expectedColumn, MockConsoleTextEditor.Column);
} }
[Test] [Test]
public void HomeKeyPressedWhenTextInConsole() public void HomeKeyPressedWhenTextInConsole()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Home); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Home);
int expectedColumn = prompt.Length; int expectedColumn = prompt.Length;
Assert.AreEqual(expectedColumn, textEditor.Column); Assert.AreEqual(expectedColumn, MockConsoleTextEditor.Column);
} }
} }
} }

119
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs

@ -20,148 +20,145 @@ namespace PythonBinding.Tests.Console
/// PythonConsole itself restricts typing itself by handling key press events. /// PythonConsole itself restricts typing itself by handling key press events.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleReadOnlyRegionsTestFixture public class PythonConsoleReadOnlyRegionsTestFixture : PythonConsoleTestsBase
{ {
PythonConsole console;
MockConsoleTextEditor textEditor;
string prompt = ">>> "; string prompt = ">>> ";
[SetUp] [SetUp]
public void Init() public void Init()
{ {
textEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
console = new PythonConsole(textEditor, null); TestablePythonConsole.Write(prompt, Style.Prompt);
console.Write(prompt, Style.Prompt);
} }
[Test] [Test]
public void MakeCurrentContentReadOnlyIsCalled() public void MakeCurrentContentReadOnlyIsCalled()
{ {
Assert.IsTrue(textEditor.IsMakeCurrentContentReadOnlyCalled); Assert.IsTrue(MockConsoleTextEditor.IsMakeCurrentContentReadOnlyCalled);
} }
[Test] [Test]
public void LeftArrowThenInsertNewCharacterInsertsText() public void LeftArrowThenInsertNewCharacterInsertsText()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left);
textEditor.RaisePreviewKeyDownEvent(Key.C); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C);
Assert.AreEqual("ACB", console.GetCurrentLine()); Assert.AreEqual("ACB", TestablePythonConsole.GetCurrentLine());
} }
[Test] [Test]
public void MoveOneCharacterIntoPromptTypingShouldBePrevented() public void MoveOneCharacterIntoPromptTypingShouldBePrevented()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left);
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
Assert.AreEqual(String.Empty, console.GetCurrentLine()); Assert.AreEqual(String.Empty, TestablePythonConsole.GetCurrentLine());
} }
[Test] [Test]
public void MoveOneCharacterIntoPromptAndBackspaceKeyShouldNotRemoveAnything() public void MoveOneCharacterIntoPromptAndBackspaceKeyShouldNotRemoveAnything()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back);
Assert.AreEqual("A", console.GetCurrentLine()); Assert.AreEqual("A", TestablePythonConsole.GetCurrentLine());
Assert.AreEqual(prompt + "A", textEditor.Text); Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void MoveTwoCharactersIntoPromptAndBackspaceKeyShouldNotRemoveAnything() public void MoveTwoCharactersIntoPromptAndBackspaceKeyShouldNotRemoveAnything()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back);
Assert.AreEqual("A", console.GetCurrentLine()); Assert.AreEqual("A", TestablePythonConsole.GetCurrentLine());
Assert.AreEqual(prompt + "A", textEditor.Text); Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void SelectLastCharacterOfPromptThenPressingTheBackspaceKeyShouldNotRemoveAnything() public void SelectLastCharacterOfPromptThenPressingTheBackspaceKeyShouldNotRemoveAnything()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.SelectionStart = prompt.Length - 1; MockConsoleTextEditor.SelectionStart = prompt.Length - 1;
textEditor.SelectionLength = 2; MockConsoleTextEditor.SelectionLength = 2;
textEditor.Column += 2; MockConsoleTextEditor.Column += 2;
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back);
Assert.AreEqual("A", console.GetCurrentLine()); Assert.AreEqual("A", TestablePythonConsole.GetCurrentLine());
Assert.AreEqual(prompt + "A", textEditor.Text); Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void CanMoveIntoPromptRegionWithLeftCursorKey() public void CanMoveIntoPromptRegionWithLeftCursorKey()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left);
Assert.IsFalse(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left)); Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left));
} }
[Test] [Test]
public void CanMoveOutOfPromptRegionWithRightCursorKey() public void CanMoveOutOfPromptRegionWithRightCursorKey()
{ {
textEditor.Column = 0; MockConsoleTextEditor.Column = 0;
Assert.IsFalse(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Right)); Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Right));
} }
[Test] [Test]
public void CanMoveOutOfPromptRegionWithUpCursorKey() public void CanMoveOutOfPromptRegionWithUpCursorKey()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
console.Write(prompt, Style.Prompt); TestablePythonConsole.Write(prompt, Style.Prompt);
textEditor.Column = 0; MockConsoleTextEditor.Column = 0;
Assert.IsFalse(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up)); Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up));
} }
[Test] [Test]
public void CanMoveInReadOnlyRegionWithDownCursorKey() public void CanMoveInReadOnlyRegionWithDownCursorKey()
{ {
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
console.Write(prompt, Style.Prompt); TestablePythonConsole.Write(prompt, Style.Prompt);
textEditor.Column = 0; MockConsoleTextEditor.Column = 0;
textEditor.Line = 0; MockConsoleTextEditor.Line = 0;
Assert.IsFalse(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down));
} }
[Test] [Test]
public void BackspaceKeyPressedIgnoredIfLineIsEmpty() public void BackspaceKeyPressedIgnoredIfLineIsEmpty()
{ {
Assert.IsTrue(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back)); Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back));
} }
[Test] [Test]
public void BackspaceOnPreviousLine() public void BackspaceOnPreviousLine()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
console.Write(prompt, Style.Prompt); TestablePythonConsole.Write(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.C); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C);
// Move up a line with cursor. // Move up a line with cursor.
textEditor.Line = 0; MockConsoleTextEditor.Line = 0;
Assert.IsTrue(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back)); Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back));
Assert.AreEqual("C", console.GetCurrentLine()); Assert.AreEqual("C", TestablePythonConsole.GetCurrentLine());
} }
[Test] [Test]
public void CanBackspaceFirstCharacterOnLine() public void CanBackspaceFirstCharacterOnLine()
{ {
textEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.Column = 5; MockConsoleTextEditor.Column = 5;
textEditor.SelectionStart = 5; MockConsoleTextEditor.SelectionStart = 5;
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back);
Assert.AreEqual(String.Empty, console.GetCurrentLine()); Assert.AreEqual(String.Empty, TestablePythonConsole.GetCurrentLine());
} }
} }
} }

33
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs

@ -19,21 +19,18 @@ namespace PythonBinding.Tests.Console
/// Tests the PythonConsole ReadLine method. /// Tests the PythonConsole ReadLine method.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleReadTestFixture public class PythonConsoleReadTestFixture : PythonConsoleTestsBase
{ {
PythonConsole pythonConsole;
int initialAutoIndentSize = 4; int initialAutoIndentSize = 4;
string readLine; string readLine;
int autoIndentSize; int autoIndentSize;
MockConsoleTextEditor mockTextEditor;
bool raiseKeyPressEvent; bool raiseKeyPressEvent;
bool raiseDialogKeyPressEvent; bool raiseDialogKeyPressEvent;
[TestFixtureSetUp] [TestFixtureSetUp]
public void Init() public void Init()
{ {
mockTextEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
pythonConsole = new PythonConsole(mockTextEditor, null);
autoIndentSize = initialAutoIndentSize; autoIndentSize = initialAutoIndentSize;
Thread thread = new Thread(ReadLineFromConsoleOnDifferentThread); Thread thread = new Thread(ReadLineFromConsoleOnDifferentThread);
@ -42,16 +39,16 @@ namespace PythonBinding.Tests.Console
int sleepInterval = 10; int sleepInterval = 10;
int maxWait = 2000; int maxWait = 2000;
int currentWait = 0; int currentWait = 0;
while ((mockTextEditor.Text.Length < autoIndentSize) && (currentWait < maxWait)) { while ((MockConsoleTextEditor.Text.Length < autoIndentSize) && (currentWait < maxWait)) {
Thread.Sleep(sleepInterval); Thread.Sleep(sleepInterval);
currentWait += sleepInterval; currentWait += sleepInterval;
} }
raiseKeyPressEvent = mockTextEditor.RaisePreviewKeyDownEvent(Key.A); raiseKeyPressEvent = MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
raiseDialogKeyPressEvent = mockTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); raiseDialogKeyPressEvent = MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
currentWait = 0; currentWait = 0;
while ((mockTextEditor.Text.Length < autoIndentSize + 2) && (currentWait < maxWait)) { while ((MockConsoleTextEditor.Text.Length < autoIndentSize + 2) && (currentWait < maxWait)) {
Thread.Sleep(10); Thread.Sleep(10);
currentWait += sleepInterval; currentWait += sleepInterval;
} }
@ -61,7 +58,7 @@ namespace PythonBinding.Tests.Console
[TestFixtureTearDown] [TestFixtureTearDown]
public void TearDown() public void TearDown()
{ {
pythonConsole.Dispose(); TestablePythonConsole.Dispose();
} }
[Test] [Test]
@ -75,30 +72,30 @@ namespace PythonBinding.Tests.Console
public void ReadLineWithNonZeroAutoIndentSizeWritesSpacesToTextEditor() public void ReadLineWithNonZeroAutoIndentSizeWritesSpacesToTextEditor()
{ {
string expectedString = String.Empty.PadLeft(initialAutoIndentSize) + "A\r\n"; string expectedString = String.Empty.PadLeft(initialAutoIndentSize) + "A\r\n";
Assert.AreEqual(expectedString, mockTextEditor.Text); Assert.AreEqual(expectedString, MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void DocumentInsertCalledWhenAutoIndentIsNonZero() public void DocumentInsertCalledWhenAutoIndentIsNonZero()
{ {
Assert.IsTrue(mockTextEditor.IsWriteCalled); Assert.IsTrue(MockConsoleTextEditor.IsWriteCalled);
} }
[Test] [Test]
public void NoTextWrittenWhenAutoIndentSizeIsZero() public void NoTextWrittenWhenAutoIndentSizeIsZero()
{ {
MockConsoleTextEditor textEditor = new MockConsoleTextEditor(); TestablePythonConsole pythonConsole = new TestablePythonConsole();
PythonConsole console = new PythonConsole(textEditor, null); MockConsoleTextEditor textEditor = pythonConsole.MockConsoleTextEditor;
textEditor.RaisePreviewKeyDownEvent(Key.A); textEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
textEditor.IsWriteCalled = false; textEditor.IsWriteCalled = false;
console.ReadLine(0); pythonConsole.ReadLine(0);
Assert.IsFalse(textEditor.IsWriteCalled); Assert.IsFalse(textEditor.IsWriteCalled);
} }
/// <summary> /// <summary>
/// Should return false for any character that should be handled by the text editor itself.s /// Should return false for any character that should be handled by the text editor itself.
/// </summary> /// </summary>
[Test] [Test]
public void RaiseKeyPressEventReturnedFalse() public void RaiseKeyPressEventReturnedFalse()
@ -107,7 +104,7 @@ namespace PythonBinding.Tests.Console
} }
/// <summary> /// <summary>
/// Should return false for any character that should be handled by the text editor itself.s /// Should return false for any character that should be handled by the text editor itself.
/// </summary> /// </summary>
[Test] [Test]
public void RaiseDialogKeyPressEventReturnedFalse() public void RaiseDialogKeyPressEventReturnedFalse()
@ -118,7 +115,7 @@ namespace PythonBinding.Tests.Console
void ReadLineFromConsoleOnDifferentThread() void ReadLineFromConsoleOnDifferentThread()
{ {
System.Console.WriteLine("Reading on different thread"); System.Console.WriteLine("Reading on different thread");
readLine = pythonConsole.ReadLine(autoIndentSize); readLine = TestablePythonConsole.ReadLine(autoIndentSize);
System.Console.WriteLine("Finished reading on different thread"); System.Console.WriteLine("Finished reading on different thread");
} }
} }

174
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleSendLineTests.cs

@ -0,0 +1,174 @@
// <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.Collections.Generic;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding;
using Microsoft.Scripting.Hosting.Shell;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Console
{
[TestFixture]
public class PythonConsoleSendLineTests : PythonConsoleTestsBase
{
[Test]
public void SendLine_NoUnreadLines_AddsLineToUnreadLines()
{
SendLineToConsole("test");
string[] unreadLines = TestablePythonConsole.GetUnreadLines();
string[] expectedUnreadlines = new string[] {"test"};
Assert.AreEqual(expectedUnreadlines, unreadLines);
}
void SendLineToConsole(string text)
{
base.CreatePythonConsole();
WritePrompt();
TestablePythonConsole.SendLine(text);
}
void WritePrompt()
{
TestablePythonConsole.Write(">>> ", Style.Prompt);
}
[Test]
public void SendLine_NoUnreadLines_CreatesLockForPreviousLines()
{
SendLineToConsole("test");
List<string> lines = TestablePythonConsole.LockCreated.Lines;
List<string> expectedLines = TestablePythonConsole.GetUnreadLinesList();
Assert.AreEqual(expectedLines, lines);
}
[Test]
public void SendLine_NoUnreadLines_LockForPreviousLinesIsDisposed()
{
SendLineToConsole("test");
bool disposed = TestablePythonConsole.LockCreated.IsDisposed;
Assert.IsTrue(disposed);
}
[Test]
public void SendLine_NoUnreadLines_LineNotAddedBeforeLockCreated()
{
SendLineToConsole("test");
int count = TestablePythonConsole.LockCreated.UnreadLineCountWhenLockCreated;
int expectedCount = 0;
Assert.AreEqual(expectedCount, count);
}
[Test]
public void SendLine_NoUnreadLines_LineAddedBeforeLockDisposed()
{
SendLineToConsole("test");
int count = TestablePythonConsole.LockCreated.UnreadLineCountWhenLockDisposed;
int expectedCount = 1;
Assert.AreEqual(expectedCount, count);
}
[Test]
public void SendLine_NoUnreadLines_LineReceivedEventIsFired()
{
SendLineToConsole("test");
bool fired = TestablePythonConsole.IsLineReceivedEventFired;
Assert.IsTrue(fired);
}
[Test]
public void SendLine_NoUnreadLines_LineReceivedEventAfterLineAddedToUnreadLines()
{
SendLineToConsole("test");
int count = TestablePythonConsole.UnreadLineCountWhenLineReceivedEventFired;
int expectedCount = 1;
Assert.AreEqual(expectedCount, count);
}
[Test]
public void SendLine_NoUnreadLines_LineWrittenToConsoleTextEditor()
{
SendLineToConsole("test");
string text = MockConsoleTextEditor.TextPassedToWrite;
string expectedTextWritten = "test\r\n";
Assert.AreEqual(expectedTextWritten, text);
}
[Test]
public void SendLine_TwoLinesInConsoleTextEditorCursorOnFirstLine_CursorMovedToEndOfLastLineBeforeTextWritten()
{
base.CreatePythonConsole();
WritePrompt();
MockConsoleTextEditor.Text =
">>> first\r\n" +
">>> second\r\n" +
">>> ";
MockConsoleTextEditor.Line = 0;
MockConsoleTextEditor.Column = 0;
TestablePythonConsole.SendLine("test");
int expectedLine = 2;
int expectedColumn = 4;
Location expectedLocation = new Location(expectedColumn, expectedLine);
Location location = MockConsoleTextEditor.CursorLocationWhenWriteTextCalled;
Assert.AreEqual(expectedLocation, location);
}
[Test]
public void SendLine_NoUnreadLines_NoTextWrittenToConsoleTextEditorBeforeFirstPromptIsWritten()
{
base.CreatePythonConsole();
TestablePythonConsole.SendLine("test");
string text = MockConsoleTextEditor.TextPassedToWrite;
Assert.IsNull(text);
}
[Test]
public void Write_SendLineCalledButNoPromptWritten_WritesOutSavedSendLineText()
{
base.CreatePythonConsole();
TestablePythonConsole.SendLine("test");
TestablePythonConsole.Write(">>> ", Style.Prompt);
string text = MockConsoleTextEditor.Text;
string expectedText =
">>> test\r\n";
Assert.AreEqual(expectedText, text);
}
[Test]
public void Write_CalledTwiceAfterSendLineCalledButNoPromptWritten_WritesOutSavedSendLineTextOnlyOnce()
{
base.CreatePythonConsole();
TestablePythonConsole.SendLine("test");
TestablePythonConsole.Write(">>> ", Style.Prompt);
TestablePythonConsole.Write(">>> ", Style.Prompt);
string text = MockConsoleTextEditor.Text;
string expectedText =
">>> test\r\n" +
">>> ";
Assert.AreEqual(expectedText, text);
}
}
}

25
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTestsBase.cs

@ -0,0 +1,25 @@
// <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.PythonBinding;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Console
{
public class PythonConsoleTestsBase
{
public MockConsoleTextEditor MockConsoleTextEditor;
public TestablePythonConsole TestablePythonConsole;
public void CreatePythonConsole()
{
TestablePythonConsole = new TestablePythonConsole();
MockConsoleTextEditor = TestablePythonConsole.MockConsoleTextEditor;
}
}
}

78
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/ConsoleTextEditorTestFixture.cs → src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTextEditorTests.cs

@ -18,7 +18,7 @@ using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Console namespace PythonBinding.Tests.Console
{ {
[TestFixture] [TestFixture]
public class ConsoleTextEditorTestFixture public class PythonConsoleTextEditorTests
{ {
PythonConsoleTextEditor consoleTextEditor; PythonConsoleTextEditor consoleTextEditor;
TextEditor avalonEditTextEditor; TextEditor avalonEditTextEditor;
@ -31,51 +31,62 @@ namespace PythonBinding.Tests.Console
} }
[Test] [Test]
public void PythonConsoleTextEditorImplementsIConsoleTextEditorInterface() public void InterfaceImplemented_NewInstance_ImplementsIConsoleTextEditorInterface()
{ {
Assert.IsNotNull(consoleTextEditor as IConsoleTextEditor); Assert.IsNotNull(consoleTextEditor as IConsoleTextEditor);
} }
[Test] [Test]
public void MakeCurrentTextEditorContentReadOnlyExtendsReadOnlyRegionToEntireDocument() public void MakeCurrentContentReadOnly_OneLineOfTextInTextEditor_ExtendsReadOnlyRegionToEntireDocument()
{ {
avalonEditTextEditor.Text = String.Empty; avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc" + Environment.NewLine); consoleTextEditor.Write("abc" + Environment.NewLine);
consoleTextEditor.MakeCurrentContentReadOnly(); consoleTextEditor.MakeCurrentContentReadOnly();
IReadOnlySectionProvider readOnlySection = avalonEditTextEditor.TextArea.ReadOnlySectionProvider; IReadOnlySectionProvider readOnlySection = avalonEditTextEditor.TextArea.ReadOnlySectionProvider;
Assert.IsFalse(readOnlySection.CanInsert(2)); bool canInsertInsideText = readOnlySection.CanInsert(2);
Assert.IsFalse(canInsertInsideText);
} }
[Test] [Test]
public void WriteMethodUpdatesTextEditor() public void Write_TextEditorHasNoText_UpdatesTextEditor()
{ {
avalonEditTextEditor.Text = String.Empty; avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc"); consoleTextEditor.Write("abc");
Assert.AreEqual("abc", avalonEditTextEditor.Text);
string text = avalonEditTextEditor.Text;
string expectedText = "abc";
Assert.AreEqual(expectedText, text);
} }
[Test] [Test]
public void ZeroBasedConsoleTextEditorColumnPositionIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased() public void Column_TextEditorColumnSetToThree_ZeroBasedConsoleTextEditorColumnPositionReturnsTwoWhichIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased()
{ {
avalonEditTextEditor.Text = "test"; avalonEditTextEditor.Text = "test";
avalonEditTextEditor.TextArea.Caret.Column = 3; avalonEditTextEditor.TextArea.Caret.Column = 3;
Assert.AreEqual(2, consoleTextEditor.Column); int column = consoleTextEditor.Column;
int expectedColumn = 2;
Assert.AreEqual(expectedColumn, column);
} }
[Test] [Test]
public void SettingConsoleTextEditorColumnPositionUpdatesAvalonTextEditorColumnPosition() public void Column_SettingConsoleTextEditorColumnPosition_UpdatesAvalonTextEditorColumnPosition()
{ {
avalonEditTextEditor.Text = "test"; avalonEditTextEditor.Text = "test";
avalonEditTextEditor.TextArea.Caret.Column = 0; avalonEditTextEditor.TextArea.Caret.Column = 0;
consoleTextEditor.Column = 1; consoleTextEditor.Column = 1;
Assert.AreEqual(2, avalonEditTextEditor.TextArea.Caret.Column); int column = avalonEditTextEditor.TextArea.Caret.Column;
int expectedColumn = 2;
Assert.AreEqual(expectedColumn, column);
} }
[Test] [Test]
public void GetSelectionStartAndLengthWhenThreeCharactersSelected() public void SelectionStart_ThreeCharactersSelectedInTextEditor_ConsoleTextEditorSelectionIsEqualToTextEditorSelection()
{ {
avalonEditTextEditor.Text = "te000xt"; avalonEditTextEditor.Text = "te000xt";
int startOffset = 2; int startOffset = 2;
@ -98,7 +109,7 @@ namespace PythonBinding.Tests.Console
} }
[Test] [Test]
public void GetSelectionStartAndLengthWhenNothingSelected() public void SelectionLength_NothingSelectedInTextEditor_ConsoleTextEditorSelectionMatchesTextEditorSelection()
{ {
avalonEditTextEditor.Text = "text"; avalonEditTextEditor.Text = "text";
avalonEditTextEditor.TextArea.Caret.Column = 1; avalonEditTextEditor.TextArea.Caret.Column = 1;
@ -109,37 +120,62 @@ namespace PythonBinding.Tests.Console
} }
[Test] [Test]
public void ConsoleTextEditorLineEqualsOneLessThanAvalonTextEditorCaretLine() public void Line_TextEditorCaretLineIsTwo_ConsoleTextEditorLineEqualsOneLessThanAvalonTextEditorCaretLine()
{ {
avalonEditTextEditor.Text = "abc\r\ndef"; avalonEditTextEditor.Text = "abc\r\ndef";
avalonEditTextEditor.TextArea.Caret.Line = 2; avalonEditTextEditor.TextArea.Caret.Line = 2;
Assert.AreEqual(1, consoleTextEditor.Line); int line = consoleTextEditor.Line;
int expectedLine = 1;
Assert.AreEqual(expectedLine, line);
}
[Test]
public void Line_SettingConsoleTextEditorToLineOne_AvalonTextEditorCaretLineIsSetToTwo()
{
avalonEditTextEditor.Text = "abc\r\ndef";
avalonEditTextEditor.TextArea.Caret.Line = 0;
consoleTextEditor.Line = 1;
int line = avalonEditTextEditor.TextArea.Caret.Line;
int expectedLine = 2;
Assert.AreEqual(expectedLine, line);
} }
[Test] [Test]
public void ConsoleTextEditorTotalLinesEqualsAvalonTextEditorTotalLines() public void TotalLines_ThreeLinesInTextEditor_ReturnsThreeLines()
{ {
avalonEditTextEditor.Text = "abc\r\ndef\r\nghi"; avalonEditTextEditor.Text = "abc\r\ndef\r\nghi";
Assert.AreEqual(3, consoleTextEditor.TotalLines); int total = consoleTextEditor.TotalLines;
int expected = 3;
Assert.AreEqual(expected, total);
} }
[Test] [Test]
public void GetLineForZerothLineReturnsFirstLineInAvalonTextEditor() public void GetLine_GetLineForZerothLine_ReturnsFirstLineInAvalonTextEditor()
{ {
avalonEditTextEditor.Text = "abc\r\ndef\r\nghi"; avalonEditTextEditor.Text = "abc\r\ndef\r\nghi";
Assert.AreEqual("abc", consoleTextEditor.GetLine(0)); string line = consoleTextEditor.GetLine(0);
string expectedLine = "abc";
Assert.AreEqual(expectedLine, line);
} }
[Test] [Test]
public void ReplaceTextReplacesTextInAvalonEditTextEditor() public void Replace_ReplaceSingleCharacterOnSecondLine_ReplacesCorrectTextInAvalonEditTextEditor()
{ {
avalonEditTextEditor.Text = "abc\r\ndef"; avalonEditTextEditor.Text =
"abc\r\n" +
"def";
avalonEditTextEditor.TextArea.Caret.Line = 2; avalonEditTextEditor.TextArea.Caret.Line = 2;
int lineOffset = 1; int lineOffset = 1;
int length = 1; int length = 1;
consoleTextEditor.Replace(lineOffset, length, "test"); consoleTextEditor.Replace(lineOffset, length, "test");
Assert.AreEqual("abc\r\ndtestf", avalonEditTextEditor.Text);
string text = avalonEditTextEditor.Text;
string expectedText =
"abc\r\n" +
"dtestf";
Assert.AreEqual(expectedText, text);
} }
} }
} }

21
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleUnreadLinesTestFixture.cs

@ -23,40 +23,37 @@ namespace PythonBinding.Tests.Console
/// Tests the PythonConsole's GetUnreadLines method. /// Tests the PythonConsole's GetUnreadLines method.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleUnreadLinesTestFixture public class PythonConsoleUnreadLinesTestFixture : PythonConsoleTestsBase
{ {
PythonConsole pythonConsole;
MockConsoleTextEditor textEditor;
[SetUp] [SetUp]
public void Init() public void Init()
{ {
textEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
pythonConsole = new PythonConsole(textEditor, null);
} }
[Test] [Test]
public void NoUnreadLinesAtStart() public void NoUnreadLinesAtStart()
{ {
Assert.AreEqual(0, pythonConsole.GetUnreadLines().Length); Assert.AreEqual(0, TestablePythonConsole.GetUnreadLines().Length);
} }
[Test] [Test]
public void HasUnreadLines() public void HasUnreadLines()
{ {
Assert.IsFalse(pythonConsole.IsLineAvailable); Assert.IsFalse(TestablePythonConsole.IsLineAvailable);
} }
[Test] [Test]
public void AddOneLine() public void AddOneLine()
{ {
textEditor.RaisePreviewKeyDownEvent(System.Windows.Input.Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(System.Windows.Input.Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(System.Windows.Input.Key.Enter); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(System.Windows.Input.Key.Enter);
string[] lines = TestablePythonConsole.GetUnreadLines();
string[] expectedLines = new string[] {"A"}; string[] expectedLines = new string[] {"A"};
Assert.AreEqual(expectedLines, pythonConsole.GetUnreadLines()); Assert.AreEqual(expectedLines, lines);
Assert.IsTrue(pythonConsole.IsLineAvailable); Assert.IsTrue(TestablePythonConsole.IsLineAvailable);
} }
} }
} }

26
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleWriteTestFixture.cs

@ -18,45 +18,41 @@ namespace PythonBinding.Tests.Console
/// Tests that the PythonConsole Write method correctly update the text editor. /// Tests that the PythonConsole Write method correctly update the text editor.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class PythonConsoleWriteTestFixture public class PythonConsoleWriteTestFixture : PythonConsoleTestsBase
{ {
PythonConsole pythonConsole;
MockConsoleTextEditor mockTextEditor;
[SetUp] [SetUp]
public void Init() public void Init()
{ {
mockTextEditor = new MockConsoleTextEditor(); base.CreatePythonConsole();
mockTextEditor.Text = String.Empty; MockConsoleTextEditor.Text = String.Empty;
pythonConsole = new PythonConsole(mockTextEditor, null);
} }
[Test] [Test]
public void WriteLine() public void WriteLine()
{ {
pythonConsole.WriteLine(); TestablePythonConsole.WriteLine();
Assert.AreEqual(Environment.NewLine, mockTextEditor.Text); Assert.AreEqual(Environment.NewLine, MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void WriteLineWithText() public void WriteLineWithText()
{ {
pythonConsole.WriteLine("test", Style.Out); TestablePythonConsole.WriteLine("test", Style.Out);
Assert.AreEqual("test" + Environment.NewLine, mockTextEditor.Text); Assert.AreEqual("test" + Environment.NewLine, MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void TwoWrites() public void TwoWrites()
{ {
pythonConsole.Write("a", Style.Out); TestablePythonConsole.Write("a", Style.Out);
pythonConsole.Write("b", Style.Out); TestablePythonConsole.Write("b", Style.Out);
Assert.AreEqual("ab", mockTextEditor.Text); Assert.AreEqual("ab", MockConsoleTextEditor.Text);
} }
[Test] [Test]
public void DoesNotHasLinesWaitingToBeRead() public void DoesNotHasLinesWaitingToBeRead()
{ {
Assert.IsFalse(pythonConsole.IsLineAvailable); Assert.IsFalse(TestablePythonConsole.IsLineAvailable);
} }
} }
} }

328
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/ThreadSafePythonConsoleTextEditorTests.cs

@ -0,0 +1,328 @@
// <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.Collections.Generic;
using System.Threading;
using System.Windows.Input;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
using PythonBinding.Tests.Utils.Tests;
namespace PythonBinding.Tests.Console
{
[TestFixture]
public class ThreadSafePythonConsoleTextEditorTests
{
ThreadSafePythonConsoleTextEditor threadSafeConsoleTextEditor;
TextEditor avalonEditTextEditor;
MockControlDispatcher dispatcher;
MockConsoleTextEditor fakeConsoleTextEditor;
ConsoleTextEditorKeyEventArgs actualKeyEventArgs;
[SetUp]
public void Init()
{
avalonEditTextEditor = new TextEditor();
dispatcher = new MockControlDispatcher();
dispatcher.CheckAccessReturnValue = true;
fakeConsoleTextEditor = new MockConsoleTextEditor();
threadSafeConsoleTextEditor = new ThreadSafePythonConsoleTextEditor(fakeConsoleTextEditor, dispatcher);
}
[Test]
public void PreviewKeyDown_PreviewKeyDownFiresInWrappedNonThreadSafeConsoleTextEditor_CausesPreviewKeyDownEventToFireInThreadSafeConsoleTextEditor()
{
threadSafeConsoleTextEditor.PreviewKeyDown += ThreadSafeConsoleTextEditorPreviewKeyDown;
MockConsoleTextEditorKeyEventArgs expectedKeyEventArgs = new MockConsoleTextEditorKeyEventArgs(Key.OemPeriod);
fakeConsoleTextEditor.RaisePreviewKeyDownEvent(expectedKeyEventArgs);
Assert.AreEqual(expectedKeyEventArgs, actualKeyEventArgs);
}
void ThreadSafeConsoleTextEditorPreviewKeyDown(object source, ConsoleTextEditorKeyEventArgs e)
{
actualKeyEventArgs = e;
}
[Test]
public void PreviewKeyDown_PreviewKeyDownFiresInWrappedNonThreadSafeConsoleTextEditorAfterEventHandlerRemoved_DoesNotFirePreviewKeyDownEventinThreadSafeConsoleTextEditor()
{
actualKeyEventArgs = null;
threadSafeConsoleTextEditor.PreviewKeyDown += ThreadSafeConsoleTextEditorPreviewKeyDown;
threadSafeConsoleTextEditor.PreviewKeyDown -= ThreadSafeConsoleTextEditorPreviewKeyDown;
MockConsoleTextEditorKeyEventArgs expectedKeyEventArgs = new MockConsoleTextEditorKeyEventArgs(Key.OemPeriod);
fakeConsoleTextEditor.RaisePreviewKeyDownEvent(expectedKeyEventArgs);
Assert.IsNull(actualKeyEventArgs);
}
[Test]
public void Dispose_WrappedNonThreadSafeConsoleTextEditor_DisposesWrappedNonThreadSafeConsoleTextEditor()
{
threadSafeConsoleTextEditor.Dispose();
bool disposed = fakeConsoleTextEditor.IsDisposed;
Assert.IsTrue(disposed);
}
[Test]
public void Column_WrappedConsoleTextEditorColumnIsThree_ReturnsThree()
{
fakeConsoleTextEditor.Column = 3;
int column = threadSafeConsoleTextEditor.Column;
int expectedColumn = 3;
Assert.AreEqual(expectedColumn, column);
}
[Test]
public void Column_SettingColumnToFour_SetsWrappedConsoleTextEditorColumnToFour()
{
threadSafeConsoleTextEditor.Column = 4;
int column = fakeConsoleTextEditor.Column;
int expectedColumn = 4;
Assert.AreEqual(expectedColumn, column);
}
[Test]
public void SelectionStart_WrappedConsoleTextEditorSelectionStartIsThree_ReturnsThree()
{
fakeConsoleTextEditor.SelectionStart = 3;
int index = threadSafeConsoleTextEditor.SelectionStart;
int expectedIndex = 3;
Assert.AreEqual(expectedIndex, index);
}
[Test]
public void SelectionLength_WrappedConsoleTextEditorSelectionLengthIsThree_ReturnsThree()
{
fakeConsoleTextEditor.SelectionLength = 3;
int length = threadSafeConsoleTextEditor.SelectionLength;
int expectedLength = 3;
Assert.AreEqual(expectedLength, length);
}
[Test]
public void Line_WrappedConsoleTextEditorLineIsTwo_ReturnsTwo()
{
fakeConsoleTextEditor.Line = 2;
int line = threadSafeConsoleTextEditor.Line;
int expectedLine = 2;
Assert.AreEqual(expectedLine, line);
}
[Test]
public void Line_SettingLineToOne_SetsWrappedConsoleTextEditorLineToOne()
{
threadSafeConsoleTextEditor.Line = 1;
int line = fakeConsoleTextEditor.Line;
int expectedLine = 1;
Assert.AreEqual(expectedLine, line);
}
[Test]
public void TotalLines_WrappedConsoleTextEditorTotalLinesIsOne_ReturnsOne()
{
fakeConsoleTextEditor.TotalLines = 1;
int total = threadSafeConsoleTextEditor.TotalLines;
int expectedTotal = 1;
Assert.AreEqual(expectedTotal, total);
}
[Test]
public void IsCompletionWindowDisplayed_WrappedConsoleTextEditorIsCompletionWindowDisplayedIsTrue_ReturnsTrue()
{
fakeConsoleTextEditor.IsCompletionWindowDisplayed = true;
bool result = threadSafeConsoleTextEditor.IsCompletionWindowDisplayed;
Assert.IsTrue(result);
}
[Test]
public void MakeCurrentContentReadOnly_WrappedConsoleTextEditor_CallsWrappedConsoleTextEditorMethod()
{
threadSafeConsoleTextEditor.MakeCurrentContentReadOnly();
Assert.IsTrue(fakeConsoleTextEditor.IsMakeCurrentContentReadOnlyCalled);
}
[Test]
public void ShowCompletionWindow_WrappedConsoleTextEditor_CallsWrappedConsoleTextEditorMethod()
{
PythonConsoleCompletionDataProvider expectedProvider = new PythonConsoleCompletionDataProvider(null);
threadSafeConsoleTextEditor.ShowCompletionWindow(expectedProvider);
PythonConsoleCompletionDataProvider provider = fakeConsoleTextEditor.CompletionProviderPassedToShowCompletionWindow;
Assert.AreEqual(expectedProvider, provider);
}
[Test]
public void Write_WrappedConsoleTextEditor_WritesTextToWrappedConsoleTextEditor()
{
threadSafeConsoleTextEditor.Write("abc");
string text = fakeConsoleTextEditor.TextPassedToWrite;
string expectedText = "abc";
Assert.AreEqual(expectedText, text);
}
[Test]
public void GetLine_GetFirstLine_GetsFirstLineFromWrappedConsoleTextEditor()
{
fakeConsoleTextEditor.LineBuilder.Append("abc\r\n");
string line = threadSafeConsoleTextEditor.GetLine(0);
string expectedText = "abc\r\n";
Assert.AreEqual(expectedText, line);
}
[Test]
public void Replace_WrappedConsoleTextEditor_ReplacementTextPassedToWrappedConsoleTextEditor()
{
fakeConsoleTextEditor.LineBuilder.Append("abc\r\n");
threadSafeConsoleTextEditor.Replace(1, 2, "ddd");
string replacementText = fakeConsoleTextEditor.TextPassedToReplace;
string expectedText = "ddd";
Assert.AreEqual(expectedText, replacementText);
}
[Test]
public void Replace_WrappedConsoleTextEditor_ReplacementIndexPassedToWrappedConsoleTextEditor()
{
fakeConsoleTextEditor.LineBuilder.Append("abc\r\n");
int expectedIndex = 1;
threadSafeConsoleTextEditor.Replace(expectedIndex, 2, "ddd");
int index = fakeConsoleTextEditor.IndexPassedToReplace;
Assert.AreEqual(expectedIndex, index);
}
[Test]
public void Replace_WrappedConsoleTextEditor_ReplacementLengthPassedToWrappedConsoleTextEditor()
{
fakeConsoleTextEditor.LineBuilder.Append("abc\r\n");
int expectedLength = 2;
threadSafeConsoleTextEditor.Replace(1, expectedLength, "ddd");
int length = fakeConsoleTextEditor.LengthPassedToReplace;
Assert.AreEqual(expectedLength, length);
}
[Test]
public void Write_DispatcherCheckAccessReturnsFalse_MethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
threadSafeConsoleTextEditor.Write("abc");
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void Write_DispatcherCheckAccessReturnsFalse_MethodIsInvokedWithTextAsArg()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
threadSafeConsoleTextEditor.Write("abc");
object[] expectedArgs = new object[] { "abc" };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void GetLine_DispatcherCheckAccessReturnsFalse_MethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
threadSafeConsoleTextEditor.GetLine(0);
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void GetLine_DispatcherCheckAccessReturnsFalse_MethodIsInvokedWithLineNumberAsArg()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
threadSafeConsoleTextEditor.GetLine(0);
object[] expectedArgs = new object[] { 0 };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void Replace_DispatcherCheckAccessReturnsFalse_MethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
fakeConsoleTextEditor.Text = "abcd";
threadSafeConsoleTextEditor.Replace(0, 2, "12");
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void Replace_DispatcherCheckAccessReturnsFalse_MethodIsInvokedWithThreeArgs()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
fakeConsoleTextEditor.Text = "abcd";
threadSafeConsoleTextEditor.Replace(0, 2, "12");
object[] expectedArgs = new object[] { 0, 2, "12" };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void MakeCurrentContentReadOnly_DispatcherCheckAccessReturnsFalse_MethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
threadSafeConsoleTextEditor.MakeCurrentContentReadOnly();
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void ShowCompletionWindow_DispatcherCheckAccessReturnsFalse_MethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
PythonConsoleCompletionDataProvider provider = new PythonConsoleCompletionDataProvider(null);
threadSafeConsoleTextEditor.ShowCompletionWindow(provider);
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void ShowCompletionWindow_DispatcherCheckAccessReturnsFalse_MethodIsInvokedWithDataProviderPassedToMethod()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
PythonConsoleCompletionDataProvider provider = new PythonConsoleCompletionDataProvider(null);
threadSafeConsoleTextEditor.ShowCompletionWindow(provider);
object[] expectedArgs = new object[] { provider };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
}
}

7
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TwoPythonConsoleLinesWaitingTestFixture.cs

@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console
{ {
string line1; string line1;
string line2; string line2;
PythonConsole pythonConsole; TestablePythonConsole pythonConsole;
bool lineAvailableBeforeFirstEnterKey; bool lineAvailableBeforeFirstEnterKey;
bool lineAvailableAfterFirstEnterKey; bool lineAvailableAfterFirstEnterKey;
bool lineAvailableAtEnd; bool lineAvailableAtEnd;
@ -37,9 +37,8 @@ namespace PythonBinding.Tests.Console
[TestFixtureSetUp] [TestFixtureSetUp]
public void SetUpFixture() public void SetUpFixture()
{ {
MockConsoleTextEditor textEditor = new MockConsoleTextEditor(); using (pythonConsole = new TestablePythonConsole()) {
using (pythonConsole = new PythonConsole(textEditor, null)) { MockConsoleTextEditor textEditor = pythonConsole.MockConsoleTextEditor;
textEditor.RaisePreviewKeyDownEvent(Input.Key.A); textEditor.RaisePreviewKeyDownEvent(Input.Key.A);
textEditor.RaisePreviewKeyDownEvent(Input.Key.B); textEditor.RaisePreviewKeyDownEvent(Input.Key.B);
textEditor.RaisePreviewKeyDownEvent(Input.Key.C); textEditor.RaisePreviewKeyDownEvent(Input.Key.C);

23
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertCSharpToPythonMenuCommandTestFixture.cs

@ -12,39 +12,28 @@ using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Converter namespace PythonBinding.Tests.Converter
{ {
/// <summary>
/// Tests the ConvertCSharpToPythonMenuCommand.
/// </summary>
[TestFixture] [TestFixture]
public class ConvertCSharpToPythonMenuCommandTestFixture : ConvertToPythonMenuCommand public class ConvertCSharpToPythonMenuCommandTestFixture : ConvertToPythonMenuCommand
{ {
string newFileText; string newFileText;
string defaultFileName; string defaultFileName;
string language; string language;
MockEditableViewContent mockViewContent;
[TestFixtureSetUp] [TestFixtureSetUp]
public void SetUpFixture() public void SetUpFixture()
{ {
mockViewContent = new MockEditableViewContent(); MockWorkbench workbench = MockWorkbench.CreateWorkbenchWithOneViewContent("test.cs");
mockViewContent.Text = "class Foo { }"; workbench.ActiveMockEditableViewContent.Text = "class Foo { }";
mockViewContent.PrimaryFileName = new ICSharpCode.Core.FileName("test.cs");
MockWorkbench workbench = new MockWorkbench(); MockTextEditorOptions options = workbench.ActiveMockEditableViewContent.MockTextEditorOptions;
MockWorkbenchWindow window = new MockWorkbenchWindow();
window.ActiveViewContent = mockViewContent;
workbench.ActiveWorkbenchWindow = window;
MockTextEditorOptions options = new MockTextEditorOptions();
options.IndentationSize = 4; options.IndentationSize = 4;
options.ConvertTabsToSpaces = true; options.ConvertTabsToSpaces = true;
mockViewContent.TextEditorOptions = options;
Run(workbench); Run(workbench);
} }
[Test] [Test]
public void GeneratedPythonCode() public void Run_CSharpFileOpen_PythonCodeGeneratedInNewFile()
{ {
string code = string code =
"class Foo(object):\r\n" + "class Foo(object):\r\n" +
@ -53,13 +42,13 @@ namespace PythonBinding.Tests.Converter
} }
[Test] [Test]
public void NewFileName() public void Run_CSharpFileOpen_NewFileNameIsGeneratedPy()
{ {
Assert.AreEqual("Generated.py", defaultFileName); Assert.AreEqual("Generated.py", defaultFileName);
} }
[Test] [Test]
public void NewFileLanguage() public void Run_CSharpFileOpen_NewFileLanguageIsPython()
{ {
Assert.AreEqual("Python", language); Assert.AreEqual("Python", language);
} }

33
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertVBNetToPythonMenuCommandTestFixture.cs

@ -12,53 +12,46 @@ using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Converter namespace PythonBinding.Tests.Converter
{ {
/// <summary>
/// Tests the ConvertVBNetToPythonMenuCommand.
/// </summary>
[TestFixture] [TestFixture]
public class ConvertVBNetToPythonMenuCommandTestFixture : ConvertToPythonMenuCommand public class ConvertVBNetToPythonMenuCommandTestFixture : ConvertToPythonMenuCommand
{ {
string newFileText; string newFileText;
string defaultFileName; string defaultFileName;
string language; string language;
MockEditableViewContent mockViewContent;
[TestFixtureSetUp] [SetUp]
public void SetUpFixture() public void Init()
{ {
mockViewContent = new MockEditableViewContent(); MockWorkbench workbench = MockWorkbench.CreateWorkbenchWithOneViewContent("test.vb");
mockViewContent.Text = workbench.ActiveMockEditableViewContent.Text =
"class Foo\r\n" + "class Foo\r\n" +
"end class"; "end class";
mockViewContent.PrimaryFileName = new ICSharpCode.Core.FileName("test.vb");
MockWorkbench workbench = new MockWorkbench(); MockTextEditorOptions options = workbench.ActiveMockEditableViewContent.MockTextEditorOptions;
MockWorkbenchWindow window = new MockWorkbenchWindow();
window.ActiveViewContent = mockViewContent;
workbench.ActiveWorkbenchWindow = window;
MockTextEditorOptions options = new MockTextEditorOptions();
options.ConvertTabsToSpaces = false; options.ConvertTabsToSpaces = false;
options.IndentationSize = 2; options.IndentationSize = 2;
mockViewContent.TextEditorOptions = options;
Run(workbench); Run(workbench);
} }
[Test] [Test]
public void GeneratedPythonCode() public void Run_VBNetFileOpen_PythonCodeIsSavedInFileCreated()
{ {
Assert.AreEqual("class Foo(object):\r\n\tpass", newFileText); string expectedNewFileText =
"class Foo(object):\r\n" +
"\tpass";
Assert.AreEqual(expectedNewFileText, newFileText);
} }
[Test] [Test]
public void NewFileName() public void Run_VBNetFileOpen_NewFileNameIsGeneratedPy()
{ {
Assert.AreEqual("Generated.py", defaultFileName); Assert.AreEqual("Generated.py", defaultFileName);
} }
[Test] [Test]
public void NewFileLanguage() public void Run_VBNetFileOpen_NewFileLanguageIsPython()
{ {
Assert.AreEqual("Python", language); Assert.AreEqual("Python", language);
} }

28
src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/DebugPythonCommandTestFixture.cs

@ -24,15 +24,8 @@ namespace PythonBinding.Tests.Gui
[TestFixtureSetUp] [TestFixtureSetUp]
public void SetUpFixture() public void SetUpFixture()
{ {
// Create dummy view content with the Python script. MockWorkbench workbench = MockWorkbench.CreateWorkbenchWithOneViewContent(@"C:\Projects\test.py");
MockViewContent viewContent = new MockViewContent();
viewContent.PrimaryFileName = new FileName(@"C:\Projects\test.py");
MockWorkbenchWindow workbenchWindow = new MockWorkbenchWindow();
workbenchWindow.ActiveViewContent = viewContent;
MockWorkbench workbench = new MockWorkbench();
workbench.ActiveWorkbenchWindow = workbenchWindow;
// Create the Python binding addin options.
Properties p = new Properties(); Properties p = new Properties();
PythonAddInOptions options = new PythonAddInOptions(p); PythonAddInOptions options = new PythonAddInOptions(p);
options.PythonFileName = @"C:\IronPython\ipy.exe"; options.PythonFileName = @"C:\IronPython\ipy.exe";
@ -43,21 +36,26 @@ namespace PythonBinding.Tests.Gui
} }
[Test] [Test]
public void DebuggerStartMethodCalled() public void Run_PythonFileOpen_DebuggerStartMethodCalled()
{ {
Assert.IsTrue(debugger.StartMethodCalled); bool result = debugger.StartMethodCalled;
Assert.IsTrue(result);
} }
[Test] [Test]
public void ProcessInfoFileName() public void Run_PythonFileOpen_IronPythonConsoleFileNamePassedToDebugger()
{ {
Assert.AreEqual(@"C:\IronPython\ipy.exe", debugger.ProcessStartInfo.FileName); string fileName = debugger.ProcessStartInfo.FileName;
string expectedFileName = @"C:\IronPython\ipy.exe";
Assert.AreEqual(expectedFileName, fileName);
} }
[Test] [Test]
public void ProcessInfoArgs() public void Run_PythonFileOpen_DebugOptionsPassedToIronPythonConsole()
{ {
Assert.AreEqual("-X:Debug \"C:\\Projects\\test.py\"", debugger.ProcessStartInfo.Arguments); string args = debugger.ProcessStartInfo.Arguments;
string expectedArgs = "-X:Debug \"C:\\Projects\\test.py\"";
Assert.AreEqual(expectedArgs, args);
} }
} }
} }

36
src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/RunPythonCommandTestFixture.cs → src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/RunPythonCommandTests.cs

@ -20,23 +20,16 @@ namespace PythonBinding.Tests.Gui
/// passing the filename of the python script active in SharpDevelop. /// passing the filename of the python script active in SharpDevelop.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class RunPythonCommandTestFixture public class RunPythonCommandTests
{ {
MockDebugger debugger; MockDebugger debugger;
RunPythonCommand command; RunPythonCommand command;
[TestFixtureSetUp] [SetUp]
public void SetUpFixture() public void Init()
{ {
// Create dummy view content with the Python script. MockWorkbench workbench = MockWorkbench.CreateWorkbenchWithOneViewContent(@"C:\Projects\test.py");
MockViewContent viewContent = new MockViewContent();
viewContent.PrimaryFileName = new FileName(@"C:\Projects\test.py");
MockWorkbenchWindow workbenchWindow = new MockWorkbenchWindow();
workbenchWindow.ActiveViewContent = viewContent;
MockWorkbench workbench = new MockWorkbench();
workbench.ActiveWorkbenchWindow = workbenchWindow;
// Create the Python binding addin options.
Properties p = new Properties(); Properties p = new Properties();
PythonAddInOptions options = new PythonAddInOptions(p); PythonAddInOptions options = new PythonAddInOptions(p);
options.PythonFileName = @"C:\IronPython\ipy.exe"; options.PythonFileName = @"C:\IronPython\ipy.exe";
@ -47,31 +40,36 @@ namespace PythonBinding.Tests.Gui
} }
[Test] [Test]
public void RunPythonCommandIsAbstractCommand() public void BaseClass_NewInstance_IsAbstractCommand()
{ {
Assert.IsNotNull(command as AbstractCommand); Assert.IsNotNull(command as AbstractCommand);
} }
[Test] [Test]
public void DebuggerStartWithoutDebuggingMethodCalled() public void Run_PythonFileOpen_DebuggerStartWithoutDebuggingMethodCalled()
{ {
Assert.IsTrue(debugger.StartWithoutDebuggingMethodCalled); bool result = debugger.StartWithoutDebuggingMethodCalled;
Assert.IsTrue(result);
} }
[Test] [Test]
public void ProcessInfoFileName() public void Run_PythonFileOpen_IronPythonConsoleFileNamePassedToDebugger()
{ {
Assert.AreEqual(@"C:\IronPython\ipy.exe", debugger.ProcessStartInfo.FileName); string fileName = debugger.ProcessStartInfo.FileName;
string expectedFileName = @"C:\IronPython\ipy.exe";
Assert.AreEqual(expectedFileName, fileName);
} }
[Test] [Test]
public void ProcessInfoArgs() public void Run_PythonFileOpen_PythonFileNamePassedToIronPythonConsole()
{ {
Assert.AreEqual("\"C:\\Projects\\test.py\"", debugger.ProcessStartInfo.Arguments); string args = debugger.ProcessStartInfo.Arguments;
string expectedArgs = "\"C:\\Projects\\test.py\"";
Assert.AreEqual(expectedArgs, args);
} }
[Test] [Test]
public void WorkingDirectoryIsPathToPythonScriptFileBeingRun() public void Run_PythonFileOpen_IronPythonConsoleWorkingDirectoryIsPathToPythonScriptFileBeingRun()
{ {
string workingDirectory = debugger.ProcessStartInfo.WorkingDirectory; string workingDirectory = debugger.ProcessStartInfo.WorkingDirectory;
string expectedWorkingDirectory = @"C:\Projects"; string expectedWorkingDirectory = @"C:\Projects";

93
src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/SendLineToPythonConsoleCommandTests.cs

@ -0,0 +1,93 @@
// <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.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Gui
{
[TestFixture]
public class SendLineToPythonConsoleCommandTests
{
SendLineToPythonConsoleCommand sendLineToConsoleCommand;
MockConsoleTextEditor fakeConsoleTextEditor;
MockTextEditor fakeTextEditor;
MockWorkbench workbench;
MockPythonConsole fakeConsole;
[Test]
public void Run_SingleLineInTextEditor_FirstLineSentToPythonConsole()
{
CreateSendLineToConsoleCommand();
AddSingleLineToTextEditor("print 'hello'");
sendLineToConsoleCommand.Run();
string text = fakeConsole.TextPassedToSendLine;
string expectedText = "print 'hello'";
Assert.AreEqual(expectedText, text);
}
void CreateSendLineToConsoleCommand()
{
workbench = MockWorkbench.CreateWorkbenchWithOneViewContent("test.py");
fakeConsoleTextEditor = workbench.MockPythonConsolePad.MockConsoleTextEditor;
fakeConsole = workbench.MockPythonConsolePad.MockPythonConsole;
fakeTextEditor = workbench.ActiveMockEditableViewContent.MockTextEditor;
sendLineToConsoleCommand = new SendLineToPythonConsoleCommand(workbench);
}
void AddSingleLineToTextEditor(string line)
{
fakeTextEditor.Document.Text = line;
fakeTextEditor.Caret.Line = 1;
SetTextToReturnFromTextEditorGetLine(line);
}
void SetTextToReturnFromTextEditorGetLine(string line)
{
FakeDocumentLine documentLine = new FakeDocumentLine();
documentLine.Text = line;
fakeTextEditor.FakeDocument.DocumentLineToReturnFromGetLine = documentLine;
}
[Test]
public void Run_TwoLinesInTextEditorCursorOnFirstLine_FirstLineSentToPythonConsole()
{
CreateSendLineToConsoleCommand();
fakeTextEditor.Document.Text =
"print 'hello'\r\n" +
"print 'world'\r\n";
fakeTextEditor.Caret.Line = 1;
SetTextToReturnFromTextEditorGetLine("print 'hello'");
sendLineToConsoleCommand.Run();
string text = fakeConsole.TextPassedToSendLine;
string expectedText = "print 'hello'";
Assert.AreEqual(expectedText, text);
}
[Test]
public void Run_SingleLineInTextEditor_PythonConsolePadBroughtToFront()
{
CreateSendLineToConsoleCommand();
AddSingleLineToTextEditor("print 'hello'");
sendLineToConsoleCommand.Run();
bool broughtToFront = workbench.MockPythonConsolePad.BringToFrontCalled;
Assert.IsTrue(broughtToFront);
}
}
}

22
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -100,10 +100,11 @@
<Compile Include="Completion\PythonImportExpressionContextTestFixture.cs" /> <Compile Include="Completion\PythonImportExpressionContextTestFixture.cs" />
<Compile Include="Completion\PythonSocketLibraryDocumentationTestFixture.cs" /> <Compile Include="Completion\PythonSocketLibraryDocumentationTestFixture.cs" />
<Compile Include="Completion\SysModuleMembersInPythonContextTestFixture.cs" /> <Compile Include="Completion\SysModuleMembersInPythonContextTestFixture.cs" />
<Compile Include="Configuration\AddInFileTestFixture.cs" />
<Compile Include="Configuration\AddInOptionsTestFixture.cs" /> <Compile Include="Configuration\AddInOptionsTestFixture.cs" />
<Compile Include="Console\BuiltinCodeCompletionTestFixture.cs" /> <Compile Include="Console\BuiltinCodeCompletionTestFixture.cs" />
<Compile Include="Console\ConsoleTextEditorThreadSafetyTestFixture.cs" /> <Compile Include="Console\PythonConsoleSendLineTests.cs" />
<Compile Include="Console\PythonConsoleTestsBase.cs" />
<Compile Include="Console\ThreadSafePythonConsoleTextEditorTests.cs" />
<Compile Include="Console\InsertConsoleCompletionDataTestFixture.cs" /> <Compile Include="Console\InsertConsoleCompletionDataTestFixture.cs" />
<Compile Include="Console\KeysPressedWhenCompletionWindowOpenTestFixture.cs" /> <Compile Include="Console\KeysPressedWhenCompletionWindowOpenTestFixture.cs" />
<Compile Include="Console\CommandLineHistoryTestFixture.cs" /> <Compile Include="Console\CommandLineHistoryTestFixture.cs" />
@ -123,7 +124,7 @@
<Compile Include="Console\PythonConsoleUnreadLinesTestFixture.cs" /> <Compile Include="Console\PythonConsoleUnreadLinesTestFixture.cs" />
<Compile Include="Console\PythonConsoleWriteTestFixture.cs" /> <Compile Include="Console\PythonConsoleWriteTestFixture.cs" />
<Compile Include="Console\PythonOutputStreamTestFixture.cs" /> <Compile Include="Console\PythonOutputStreamTestFixture.cs" />
<Compile Include="Console\ConsoleTextEditorTestFixture.cs" /> <Compile Include="Console\PythonConsoleTextEditorTests.cs" />
<Compile Include="Console\TwoPythonConsoleLinesWaitingTestFixture.cs" /> <Compile Include="Console\TwoPythonConsoleLinesWaitingTestFixture.cs" />
<Compile Include="Converter\AddHandlerConversionTestFixture.cs" /> <Compile Include="Converter\AddHandlerConversionTestFixture.cs" />
<Compile Include="Converter\ArrayCastConversionTestFixture.cs" /> <Compile Include="Converter\ArrayCastConversionTestFixture.cs" />
@ -346,7 +347,8 @@
<Compile Include="Gui\FormsDesignerDisplayBindingTestFixture.cs" /> <Compile Include="Gui\FormsDesignerDisplayBindingTestFixture.cs" />
<Compile Include="Gui\PythonIndentationTests.cs" /> <Compile Include="Gui\PythonIndentationTests.cs" />
<Compile Include="Gui\PythonOptionsPanelTestFixture.cs" /> <Compile Include="Gui\PythonOptionsPanelTestFixture.cs" />
<Compile Include="Gui\RunPythonCommandTestFixture.cs" /> <Compile Include="Gui\RunPythonCommandTests.cs" />
<Compile Include="Gui\SendLineToPythonConsoleCommandTests.cs" />
<Compile Include="Parsing\ClassWithBaseClassTestFixture.cs" /> <Compile Include="Parsing\ClassWithBaseClassTestFixture.cs" />
<Compile Include="Parsing\InvalidCastInPythonParserTestFixture.cs" /> <Compile Include="Parsing\InvalidCastInPythonParserTestFixture.cs" />
<Compile Include="Parsing\MethodWithParametersTestFixture.cs" /> <Compile Include="Parsing\MethodWithParametersTestFixture.cs" />
@ -455,6 +457,10 @@
<Compile Include="Utils\DerivedToolStripMenuItem.cs" /> <Compile Include="Utils\DerivedToolStripMenuItem.cs" />
<Compile Include="Utils\DoublePropertyUserControl.cs" /> <Compile Include="Utils\DoublePropertyUserControl.cs" />
<Compile Include="Utils\DummySynchronizeInvoke.cs" /> <Compile Include="Utils\DummySynchronizeInvoke.cs" />
<Compile Include="Utils\FakeCaret.cs" />
<Compile Include="Utils\FakeDocument.cs" />
<Compile Include="Utils\FakeDocumentLine.cs" />
<Compile Include="Utils\FakeLock.cs" />
<Compile Include="Utils\FooItemCollection.cs" /> <Compile Include="Utils\FooItemCollection.cs" />
<Compile Include="Utils\MockComponentCreator.cs" /> <Compile Include="Utils\MockComponentCreator.cs" />
<Compile Include="Utils\MockConsoleTextEditor.cs" /> <Compile Include="Utils\MockConsoleTextEditor.cs" />
@ -468,10 +474,11 @@
<Compile Include="Utils\MockEventDescriptor.cs" /> <Compile Include="Utils\MockEventDescriptor.cs" />
<Compile Include="Utils\MockExtenderProviderService.cs" /> <Compile Include="Utils\MockExtenderProviderService.cs" />
<Compile Include="Utils\MockOpenedFile.cs" /> <Compile Include="Utils\MockOpenedFile.cs" />
<Compile Include="Utils\MockPadDescriptor.cs" />
<Compile Include="Utils\MockProject.cs" /> <Compile Include="Utils\MockProject.cs" />
<Compile Include="Utils\MockProjectContent.cs" /> <Compile Include="Utils\MockProjectContent.cs" />
<Compile Include="Utils\MockPropertyDescriptor.cs" /> <Compile Include="Utils\MockPropertyDescriptor.cs" />
<Compile Include="Utils\MockPythonConsole.cs" />
<Compile Include="Utils\MockPythonConsolePad.cs" />
<Compile Include="Utils\MockPythonFileService.cs" /> <Compile Include="Utils\MockPythonFileService.cs" />
<Compile Include="Utils\MockResourceReader.cs" /> <Compile Include="Utils\MockResourceReader.cs" />
<Compile Include="Utils\MockResourceService.cs" /> <Compile Include="Utils\MockResourceService.cs" />
@ -482,15 +489,12 @@
<Compile Include="Utils\MockTypeResolutionService.cs" /> <Compile Include="Utils\MockTypeResolutionService.cs" />
<Compile Include="Utils\MockViewContent.cs" /> <Compile Include="Utils\MockViewContent.cs" />
<Compile Include="Utils\MockWorkbench.cs" /> <Compile Include="Utils\MockWorkbench.cs" />
<Compile Include="Utils\MockWorkbenchWindow.cs" />
<Compile Include="Utils\MSBuildEngineHelper.cs" /> <Compile Include="Utils\MSBuildEngineHelper.cs" />
<Compile Include="Utils\TestablePythonConsole.cs" />
<Compile Include="Utils\Tests\AddInPathHelperTestFixture.cs" /> <Compile Include="Utils\Tests\AddInPathHelperTestFixture.cs" />
<EmbeddedResource Include="..\Project\PythonBinding.addin"> <EmbeddedResource Include="..\Project\PythonBinding.addin">
<Link>PythonBinding.addin</Link> <Link>PythonBinding.addin</Link>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="..\Project\Templates\Empty.xft">
<Link>Empty.xft</Link>
</EmbeddedResource>
<None Include="app.config" /> <None Include="app.config" />
<Compile Include="Parsing\AddInvalidSourceSpanToErrorSinkTestFixture.cs" /> <Compile Include="Parsing\AddInvalidSourceSpanToErrorSinkTestFixture.cs" />
<Compile Include="Utils\NullPropertyUserControl.cs" /> <Compile Include="Utils\NullPropertyUserControl.cs" />

53
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeCaret.cs

@ -0,0 +1,53 @@
// <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.Editor;
namespace PythonBinding.Tests.Utils
{
public class FakeCaret : ITextEditorCaret
{
public event EventHandler PositionChanged;
protected virtual void OnPositionChanged(EventArgs e)
{
if (PositionChanged != null) {
PositionChanged(this, e);
}
}
public int Offset {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public int Line { get; set; }
public int Column {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public ICSharpCode.NRefactory.Location Position {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
}
}

139
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeDocument.cs

@ -0,0 +1,139 @@
// <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.IO;
using System.Text;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
namespace PythonBinding.Tests.Utils
{
public class FakeDocument : IDocument
{
#pragma warning disable 0067
public event EventHandler<TextChangeEventArgs> Changing;
public event EventHandler<TextChangeEventArgs> Changed;
public event EventHandler TextChanged;
#pragma warning restore 0067
public FakeDocumentLine DocumentLineToReturnFromGetLine;
public int LineNumberPassedToGetLine;
public string Text { get; set; }
public int TotalNumberOfLines {
get {
throw new NotImplementedException();
}
}
public ITextBufferVersion Version {
get {
throw new NotImplementedException();
}
}
public int TextLength {
get {
throw new NotImplementedException();
}
}
public IDocumentLine GetLine(int lineNumber)
{
LineNumberPassedToGetLine = lineNumber;
return DocumentLineToReturnFromGetLine;
}
public IDocumentLine GetLineForOffset(int offset)
{
throw new NotImplementedException();
}
public int PositionToOffset(int line, int column)
{
throw new NotImplementedException();
}
public Location OffsetToPosition(int offset)
{
throw new NotImplementedException();
}
public void Insert(int offset, string text)
{
throw new NotImplementedException();
}
public void Remove(int offset, int length)
{
throw new NotImplementedException();
}
public void Replace(int offset, int length, string newText)
{
throw new NotImplementedException();
}
public void StartUndoableAction()
{
throw new NotImplementedException();
}
public void EndUndoableAction()
{
throw new NotImplementedException();
}
public IDisposable OpenUndoGroup()
{
throw new NotImplementedException();
}
public ITextAnchor CreateAnchor(int offset)
{
throw new NotImplementedException();
}
public ITextBuffer CreateSnapshot()
{
throw new NotImplementedException();
}
public ITextBuffer CreateSnapshot(int offset, int length)
{
throw new NotImplementedException();
}
public TextReader CreateReader()
{
throw new NotImplementedException();
}
public TextReader CreateReader(int offset, int length)
{
throw new NotImplementedException();
}
public char GetCharAt(int offset)
{
throw new NotImplementedException();
}
public string GetText(int offset, int length)
{
throw new NotImplementedException();
}
public object GetService(Type serviceType)
{
throw new NotImplementedException();
}
}
}

23
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeDocumentLine.cs

@ -0,0 +1,23 @@
// <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.Editor;
namespace PythonBinding.Tests.Utils
{
public class FakeDocumentLine : IDocumentLine
{
public int Offset { get; set; }
public int Length { get; set; }
public int EndOffset { get; set; }
public int TotalLength { get; set; }
public int DelimiterLength { get; set; }
public int LineNumber { get; set; }
public string Text { get; set; }
}
}

33
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeLock.cs

@ -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.Collections.Generic;
using ICSharpCode.PythonBinding;
namespace PythonBinding.Tests.Utils
{
public class FakeLock : ILock
{
public List<string> Lines;
public bool IsDisposed;
public int UnreadLineCountWhenLockCreated = -1;
public int UnreadLineCountWhenLockDisposed = -1;
public FakeLock(List<string> lines)
{
this.Lines = lines;
UnreadLineCountWhenLockCreated = lines.Count;
}
public void Dispose()
{
UnreadLineCountWhenLockDisposed = Lines.Count;
IsDisposed = true;
}
}
}

195
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockConsoleTextEditor.cs

@ -8,77 +8,69 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Input;
using System.Text; using System.Text;
using System.Windows.Input;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding; using ICSharpCode.PythonBinding;
namespace PythonBinding.Tests.Utils namespace PythonBinding.Tests.Utils
{ {
public class MockConsoleTextEditor : IConsoleTextEditor public class MockConsoleTextEditor : IConsoleTextEditor
{ {
StringBuilder previousLines = new StringBuilder(); public bool IsDisposed;
StringBuilder lineBuilder = new StringBuilder(); public bool IsWriteCalled;
bool writeCalled;
int column; public bool IsShowCompletionWindowCalled;
int selectionStart; public bool IsMakeCurrentContentReadOnlyCalled;
int selectionLength; public PythonConsoleCompletionDataProvider CompletionProviderPassedToShowCompletionWindow;
int line; public string TextPassedToWrite;
int totalLines = 1; public string TextPassedToReplace;
bool showCompletionWindowCalled; public int LengthPassedToReplace = -1;
bool completionWindowDisplayed; public int IndexPassedToReplace = -1;
bool makeReadOnlyCalled; public Location CursorLocationWhenWriteTextCalled;
PythonConsoleCompletionDataProvider completionProvider; public bool IsColumnChangedBeforeTextWritten;
public MockConsoleTextEditor() public StringBuilder PreviousLines = new StringBuilder();
{ public StringBuilder LineBuilder = new StringBuilder();
}
public event ConsoleTextEditorKeyEventHandler PreviewKeyDown; public event ConsoleTextEditorKeyEventHandler PreviewKeyDown;
public void Write(string text) public MockConsoleTextEditor()
{ {
writeCalled = true; TotalLines = 1;
lineBuilder.Append(text);
column += text.Length;
} }
public bool IsWriteCalled { public void Dispose()
get { return writeCalled; } {
set { writeCalled = value; } IsDisposed = true;
}
public bool IsShowCompletionWindowCalled {
get { return showCompletionWindowCalled; }
}
public bool IsMakeCurrentContentReadOnlyCalled {
get { return makeReadOnlyCalled; }
} }
/// <summary> public void Write(string text)
/// Returns the code completion data provider passed to the ShowCompletionWindow method. {
/// </summary> TextPassedToWrite = text;
public PythonConsoleCompletionDataProvider CompletionDataProvider { CursorLocationWhenWriteTextCalled = new Location(Column, Line);
get { return completionProvider; } IsWriteCalled = true;
LineBuilder.Append(text);
Column += text.Length;
} }
public string Text { public string Text {
get { return previousLines.ToString() + lineBuilder.ToString(); } get { return PreviousLines.ToString() + LineBuilder.ToString(); }
set { set {
previousLines = new StringBuilder(); PreviousLines = new StringBuilder();
lineBuilder = new StringBuilder(); LineBuilder = new StringBuilder();
totalLines = 1; TotalLines = 1;
foreach (char ch in value) { foreach (char ch in value) {
lineBuilder.Append(ch); LineBuilder.Append(ch);
if (ch == '\n') { if (ch == '\n') {
totalLines++; TotalLines++;
previousLines.Append(lineBuilder.ToString()); PreviousLines.Append(LineBuilder.ToString());
lineBuilder = new StringBuilder(); LineBuilder = new StringBuilder();
} }
} }
column = lineBuilder.Length; Column = LineBuilder.Length;
selectionStart = column; SelectionStart = Column;
} }
} }
@ -90,12 +82,12 @@ namespace PythonBinding.Tests.Utils
KeyConverter converter = new KeyConverter(); KeyConverter converter = new KeyConverter();
string text = converter.ConvertToString(key); string text = converter.ConvertToString(key);
if (IsCursorAtEnd) { if (IsCursorAtEnd) {
lineBuilder.Append(text); LineBuilder.Append(text);
} else { } else {
lineBuilder.Insert(column, text); LineBuilder.Insert(Column, text);
} }
column++; Column++;
selectionStart = column; SelectionStart = Column;
} }
return e.Handled; return e.Handled;
} }
@ -107,6 +99,11 @@ namespace PythonBinding.Tests.Utils
} }
} }
public void RaisePreviewKeyDownEvent(MockConsoleTextEditorKeyEventArgs e)
{
OnPreviewKeyDown(e);
}
public bool RaisePreviewKeyDownEventForDialogKey(Key key) public bool RaisePreviewKeyDownEventForDialogKey(Key key)
{ {
MockConsoleTextEditorKeyEventArgs e = new MockConsoleTextEditorKeyEventArgs(key); MockConsoleTextEditorKeyEventArgs e = new MockConsoleTextEditorKeyEventArgs(key);
@ -115,22 +112,22 @@ namespace PythonBinding.Tests.Utils
switch (key) { switch (key) {
case Key.Enter: { case Key.Enter: {
if (IsCursorAtEnd) { if (IsCursorAtEnd) {
lineBuilder.Append(Environment.NewLine); LineBuilder.Append(Environment.NewLine);
previousLines.Append(lineBuilder.ToString()); PreviousLines.Append(LineBuilder.ToString());
lineBuilder = new StringBuilder(); LineBuilder = new StringBuilder();
column = 0; Column = 0;
selectionStart = column; SelectionStart = Column;
} else { } else {
int length = lineBuilder.Length; int length = LineBuilder.Length;
string currentLine = lineBuilder.ToString(); string currentLine = LineBuilder.ToString();
previousLines.Append(currentLine.Substring(0, column) + Environment.NewLine); PreviousLines.Append(currentLine.Substring(0, Column) + Environment.NewLine);
lineBuilder = new StringBuilder(); LineBuilder = new StringBuilder();
lineBuilder.Append(currentLine.Substring(column)); LineBuilder.Append(currentLine.Substring(Column));
column = length - column; Column = length - Column;
selectionStart = column; SelectionStart = Column;
} }
totalLines++; TotalLines++;
line++; Line++;
} }
break; break;
case Key.Back: { case Key.Back: {
@ -138,13 +135,13 @@ namespace PythonBinding.Tests.Utils
} }
break; break;
case Key.Left: { case Key.Left: {
column--; Column--;
selectionStart = column; SelectionStart = Column;
} }
break; break;
case Key.Right: { case Key.Right: {
column++; Column++;
selectionStart = column; SelectionStart = Column;
} }
break; break;
} }
@ -152,72 +149,54 @@ namespace PythonBinding.Tests.Utils
return e.Handled; return e.Handled;
} }
public int Column { public bool IsCompletionWindowDisplayed { get; set; }
get { return column; } public int Column { get; set; }
set { column = value; } public int SelectionStart { get; set; }
} public int SelectionLength { get; set; }
public int Line { get; set; }
public int SelectionStart { public int TotalLines { get; set; }
get { return selectionStart; }
set { selectionStart = value; }
}
public int SelectionLength {
get { return selectionLength; }
set { selectionLength = value; }
}
public int Line {
get { return line; }
set { line = value; }
}
public int TotalLines {
get { return totalLines; }
}
public string GetLine(int index) public string GetLine(int index)
{ {
if (index == totalLines - 1) { if (index == TotalLines - 1) {
return lineBuilder.ToString(); return LineBuilder.ToString();
} }
return "aaaa"; return "aaaa";
} }
public void Replace(int index, int length, string text) public void Replace(int index, int length, string text)
{ {
lineBuilder.Remove(index, length); TextPassedToReplace = text;
lineBuilder.Insert(index, text); IndexPassedToReplace = index;
LengthPassedToReplace = length;
LineBuilder.Remove(index, length);
LineBuilder.Insert(index, text);
} }
public void ShowCompletionWindow(PythonConsoleCompletionDataProvider completionDataProvider) public void ShowCompletionWindow(PythonConsoleCompletionDataProvider completionDataProvider)
{ {
showCompletionWindowCalled = true; IsShowCompletionWindowCalled = true;
completionWindowDisplayed = true; IsCompletionWindowDisplayed = true;
this.completionProvider = completionDataProvider; this.CompletionProviderPassedToShowCompletionWindow = completionDataProvider;
}
public bool IsCompletionWindowDisplayed {
get { return completionWindowDisplayed; }
set { completionWindowDisplayed = value; }
} }
public void MakeCurrentContentReadOnly() public void MakeCurrentContentReadOnly()
{ {
makeReadOnlyCalled = true; IsMakeCurrentContentReadOnlyCalled = true;
} }
bool IsCursorAtEnd { bool IsCursorAtEnd {
get { return column == lineBuilder.ToString().Length; } get { return Column == LineBuilder.ToString().Length; }
} }
void OnBackspaceKeyPressed() void OnBackspaceKeyPressed()
{ {
if (SelectionLength == 0) { if (SelectionLength == 0) {
// Remove a single character to the left of the cursor position. // Remove a single character to the left of the cursor position.
lineBuilder.Remove(Column - 1, 1); LineBuilder.Remove(Column - 1, 1);
} else { } else {
lineBuilder.Remove(SelectionStart, SelectionLength); LineBuilder.Remove(SelectionStart, SelectionLength);
} }
} }
} }

21
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockEditableViewContent.cs

@ -18,30 +18,31 @@ namespace PythonBinding.Tests.Utils
/// </summary> /// </summary>
public class MockEditableViewContent : MockViewContent, IEditable, ITextEditorProvider public class MockEditableViewContent : MockViewContent, IEditable, ITextEditorProvider
{ {
MockTextEditor textEditor = new MockTextEditor(); public MockTextEditor MockTextEditor = new MockTextEditor();
string text = String.Empty;
public MockEditableViewContent() public MockEditableViewContent()
{ {
Text = String.Empty;
} }
public string Text { public string Text { get; set; }
get { return text; }
set { text = value; }
}
public ITextBuffer CreateSnapshot() public ITextBuffer CreateSnapshot()
{ {
return new StringTextBuffer(text); return new StringTextBuffer(Text);
} }
public ITextEditorOptions TextEditorOptions { public ITextEditorOptions TextEditorOptions {
get { return textEditor.Options; } get { return MockTextEditor.Options; }
set { textEditor.Options = value; } }
public MockTextEditorOptions MockTextEditorOptions {
get { return MockTextEditor.MockTextEditorOptions; }
set { MockTextEditor.MockTextEditorOptions = value; }
} }
public ITextEditor TextEditor { public ITextEditor TextEditor {
get { return textEditor; } get { return MockTextEditor; }
} }
public IDocument GetDocumentForFile(OpenedFile file) public IDocument GetDocumentForFile(OpenedFile file)

40
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPadDescriptor.cs

@ -1,40 +0,0 @@
// <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.Windows.Forms;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop.Gui;
namespace PythonBinding.Tests.Utils
{
/// <summary>
/// Dummy IPadDescriptor class.
/// </summary>
public class MockPadDescriptor : IPadDescriptor
{
bool bringPadToFrontCalled;
public MockPadDescriptor()
{
}
public void BringPadToFront()
{
bringPadToFrontCalled = true;
}
/// <summary>
/// Gets whether the BringPadToFront was called.
/// </summary>
public bool BringPadToFrontCalled {
get {
return bringPadToFrontCalled;
}
}
}
}

22
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPythonConsole.cs

@ -0,0 +1,22 @@
// <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.PythonBinding;
namespace PythonBinding.Tests.Utils
{
public class MockPythonConsole : IPythonConsole
{
public string TextPassedToSendLine;
public void SendLine(string text)
{
TextPassedToSendLine = text;
}
}
}

33
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPythonConsolePad.cs

@ -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 ICSharpCode.PythonBinding;
namespace PythonBinding.Tests.Utils
{
public class MockPythonConsolePad : IPythonConsolePad
{
public MockConsoleTextEditor MockConsoleTextEditor = new MockConsoleTextEditor();
public MockPythonConsole MockPythonConsole = new MockPythonConsole();
public bool BringToFrontCalled;
public void BringToFront()
{
BringToFrontCalled = true;
}
public IConsoleTextEditor ConsoleTextEditor {
get { return MockConsoleTextEditor; }
}
public IPythonConsole PythonConsole {
get { return MockPythonConsole; }
}
}
}

18
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTextEditor.cs

@ -13,11 +13,10 @@ namespace PythonBinding.Tests.Utils
{ {
public class MockTextEditor : ITextEditor public class MockTextEditor : ITextEditor
{ {
ITextEditorOptions options; public MockTextEditorOptions MockTextEditorOptions = new MockTextEditorOptions();
public MockTextEditor() public FakeDocument FakeDocument = new FakeDocument();
{ public FakeCaret FakeCaret = new FakeCaret();
}
public event EventHandler SelectionChanged; public event EventHandler SelectionChanged;
@ -44,20 +43,15 @@ namespace PythonBinding.Tests.Utils
} }
public IDocument Document { public IDocument Document {
get { get { return FakeDocument; }
throw new NotImplementedException();
}
} }
public ITextEditorCaret Caret { public ITextEditorCaret Caret {
get { get { return FakeCaret; }
throw new NotImplementedException();
}
} }
public ITextEditorOptions Options { public ITextEditorOptions Options {
get { return options; } get { return MockTextEditorOptions; }
set { options = value; }
} }
public ICSharpCode.SharpDevelop.ILanguageBinding Language { public ICSharpCode.SharpDevelop.ILanguageBinding Language {

158
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs

@ -8,165 +8,37 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
namespace PythonBinding.Tests.Utils namespace PythonBinding.Tests.Utils
{ {
/// <summary> public class MockWorkbench : IPythonWorkbench
/// Dummy IWorkbench class.
/// </summary>
public class MockWorkbench : IWorkbench
{ {
DummySynchronizeInvoke synchronizeInvoke = new DummySynchronizeInvoke(); public MockPythonConsolePad MockPythonConsolePad = new MockPythonConsolePad();
Form form = new Form(); public MockEditableViewContent ActiveMockEditableViewContent;
public event EventHandler ActiveWorkbenchWindowChanged { add {} remove {} }
public event EventHandler ActiveViewContentChanged { add {} remove {} }
public event EventHandler ActiveContentChanged { add {} remove {} }
public event ViewContentEventHandler ViewOpened { add {} remove {} }
public event ViewContentEventHandler ViewClosed { add {} remove {} }
public IWin32Window MainWin32Window {
get { return form; }
}
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject {
get { return synchronizeInvoke; }
}
public System.Windows.Window MainWindow {
get { return null; }
}
public IStatusBarService StatusBar {
get { throw new NotImplementedException(); }
}
public string Title {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public ICollection<IViewContent> ViewContentCollection {
get {
throw new NotImplementedException();
}
}
public ICollection<IViewContent> PrimaryViewContents {
get {
throw new NotImplementedException();
}
}
public IList<IWorkbenchWindow> WorkbenchWindowCollection {
get {
throw new NotImplementedException();
}
}
public IList<PadDescriptor> PadContentCollection {
get {
throw new NotImplementedException();
}
}
public IWorkbenchWindow ActiveWorkbenchWindow {
get; set;
}
public IViewContent ActiveViewContent {
get {
if (ActiveWorkbenchWindow != null)
return ActiveWorkbenchWindow.ActiveViewContent;
else
return null;
}
}
public object ActiveContent {
get {
throw new NotImplementedException();
}
}
public IWorkbenchLayout WorkbenchLayout {
get { return null; }
set { }
}
public bool IsActiveWindow { public static MockWorkbench CreateWorkbenchWithOneViewContent(string fileName)
get {
throw new NotImplementedException();
}
}
public void Initialize()
{
}
public void ShowView(IViewContent content)
{
throw new NotImplementedException();
}
public void ShowView(IViewContent content, bool switchToOpenedView)
{
throw new NotImplementedException();
}
public void ShowPad(PadDescriptor content)
{
throw new NotImplementedException();
}
public void UnloadPad(PadDescriptor content)
{ {
throw new NotImplementedException(); MockEditableViewContent viewContent = new MockEditableViewContent();
} viewContent.PrimaryFileName = new FileName(fileName);
public PadDescriptor GetPad(Type type)
{
throw new NotImplementedException();
}
public void CloseAllViews()
{
throw new NotImplementedException();
}
public void RedrawAllComponents() MockWorkbench workbench = new MockWorkbench();
{ workbench.ActiveMockEditableViewContent = viewContent;
throw new NotImplementedException();
}
public void UpdateRenderer() return workbench;
{
throw new NotImplementedException();
} }
public Properties CreateMemento() public IViewContent ActiveViewContent {
{ get { return ActiveMockEditableViewContent; }
throw new NotImplementedException();
} }
public void SetMemento(Properties memento) public IPythonConsolePad GetPythonConsolePad()
{ {
} return MockPythonConsolePad;
public bool FullScreen {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
} }
} }
} }

129
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbenchWindow.cs

@ -1,129 +0,0 @@
// <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.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
namespace PythonBinding.Tests.Utils
{
/// <summary>
/// Dummy IWorkbenchWindow class.
/// </summary>
public class MockWorkbenchWindow : IWorkbenchWindow
{
IViewContent viewContent;
public MockWorkbenchWindow()
{
}
public event EventHandler WindowSelected;
public event EventHandler WindowDeselected;
public event EventHandler TitleChanged;
public event EventHandler CloseEvent;
public event EventHandler ActiveViewContentChanged;
public string Title {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public bool IsDisposed {
get {
throw new NotImplementedException();
}
}
public IViewContent ActiveViewContent {
get {
return viewContent;
}
set {
viewContent = value;
}
}
public bool CloseWindow(bool force)
{
throw new NotImplementedException();
}
public void SelectWindow()
{
throw new NotImplementedException();
}
public void RedrawContent()
{
throw new NotImplementedException();
}
public void SwitchView(int viewNumber)
{
throw new NotImplementedException();
}
public void OnWindowDeselected(EventArgs e)
{
if (WindowDeselected != null) {
WindowDeselected(this, e);
}
}
public void OnWindowSelected(EventArgs e)
{
if (WindowSelected != null) {
WindowSelected(this, e);
}
}
public System.Windows.Media.ImageSource Icon {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public IList<IViewContent> ViewContents {
get {
throw new NotImplementedException();
}
}
protected virtual void OnTitleChanged(EventArgs e)
{
if (TitleChanged != null) {
TitleChanged(this, e);
}
}
protected virtual void OnCloseEvent(EventArgs e)
{
if (CloseEvent != null) {
CloseEvent(this, e);
}
}
protected virtual void OnActiveViewContentChanged(EventArgs e)
{
if (ActiveViewContentChanged != null) {
ActiveViewContentChanged(this, e);
}
}
}
}

56
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/TestablePythonConsole.cs

@ -0,0 +1,56 @@
// <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.Collections.Generic;
using ICSharpCode.PythonBinding;
using IronPython.Hosting;
namespace PythonBinding.Tests.Utils
{
public class TestablePythonConsole : PythonConsole
{
public MockConsoleTextEditor MockConsoleTextEditor;
public FakeLock LockCreated;
public bool IsLineReceivedEventFired;
public int UnreadLineCountWhenLineReceivedEventFired = -1;
public TestablePythonConsole()
: this(new MockConsoleTextEditor(), new PythonCommandLine())
{
}
TestablePythonConsole(IConsoleTextEditor consoleTextEditor, PythonCommandLine commandLine)
: base(consoleTextEditor)
{
CommandLine = commandLine;
MockConsoleTextEditor = (MockConsoleTextEditor)consoleTextEditor;
}
public List<string> GetUnreadLinesList()
{
return base.unreadLines;
}
public string[] GetUnreadLines()
{
return base.unreadLines.ToArray();
}
protected override ILock CreateLock(List<string> lines)
{
LockCreated = new FakeLock(lines);
return LockCreated;
}
protected override void FireLineReceivedEvent()
{
IsLineReceivedEventFired = true;
UnreadLineCountWhenLineReceivedEventFired = LockCreated.Lines.Count;
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockEditableViewContentTestFixture.cs

@ -42,7 +42,7 @@ namespace PythonBinding.Tests.Utils.Tests
public void CanReplaceTextEditorOptions() public void CanReplaceTextEditorOptions()
{ {
MockTextEditorOptions options = new MockTextEditorOptions(); MockTextEditorOptions options = new MockTextEditorOptions();
view.TextEditorOptions = options; view.MockTextEditorOptions = options;
Assert.AreSame(options, view.TextEditor.Options); Assert.AreSame(options, view.TextEditor.Options);
} }
} }

Loading…
Cancel
Save