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. 116
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs
  14. 15
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleHost.cs
  15. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsolePad.cs
  16. 60
      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. 21
      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. 117
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs
  35. 35
      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. 26
      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. 199
      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. 168
      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 @@ @@ -231,6 +231,9 @@
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Klassendiagram weergeven</value>
</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">
<value>Inhoud</value>
</data>

3
data/resources/StringResources.resx

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

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

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

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

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

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

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

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

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

@ -16,7 +16,7 @@ namespace ICSharpCode.PythonBinding @@ -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
/// be invoked.
/// </summary>
public interface IConsoleTextEditor
public interface IConsoleTextEditor : IDisposable
{
/// <summary>
/// Fired when a key is pressed but before any text has been added to the text editor.
@ -55,7 +55,7 @@ namespace ICSharpCode.PythonBinding @@ -55,7 +55,7 @@ namespace ICSharpCode.PythonBinding
/// <summary>
/// Gets the current line the cursor is on. This is zero based.
/// </summary>
int Line {get;}
int Line {get; set;}
/// <summary>
/// Gets the total number of lines in the text editor.

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

@ -0,0 +1,16 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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; }
}
}

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

@ -13,11 +13,12 @@ using System.Text; @@ -13,11 +13,12 @@ using System.Text;
using System.Threading;
using System.Windows.Input;
using ICSharpCode.AvalonEdit.CodeCompletion;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting.Shell;
namespace ICSharpCode.PythonBinding
{
public class PythonConsole : IConsole, IDisposable, IMemberProvider
public class PythonConsole : IConsole, IDisposable, IMemberProvider, IPythonConsole
{
IConsoleTextEditor textEditor;
int lineReceivedEventIndex = 0; // The index into the waitHandles array where the lineReceivedEvent is stored.
@ -25,20 +26,22 @@ namespace ICSharpCode.PythonBinding @@ -25,20 +26,22 @@ namespace ICSharpCode.PythonBinding
ManualResetEvent disposedEvent = new ManualResetEvent(false);
WaitHandle[] waitHandles;
int promptLength;
List<string> previousLines = new List<string>();
CommandLine commandLine;
bool firstPromptDisplayed;
string savedSendLineText;
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};
this.commandLine = commandLine;
this.textEditor = textEditor;
textEditor.PreviewKeyDown += ProcessPreviewKeyDown;
}
public CommandLine CommandLine { get; set; }
public void Dispose()
{
disposedEvent.Set();
@ -59,12 +62,12 @@ namespace ICSharpCode.PythonBinding @@ -59,12 +62,12 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public IList<string> GetMemberNames(string name)
{
return commandLine.GetMemberNames(name);
return CommandLine.GetMemberNames(name);
}
public IList<string> GetGlobals(string name)
{
return commandLine.GetGlobals(name);
return CommandLine.GetGlobals(name);
}
/// <summary>
@ -73,9 +76,8 @@ namespace ICSharpCode.PythonBinding @@ -73,9 +76,8 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public string ReadLine(int autoIndentSize)
{
string indent = String.Empty;
string indent = GetIndent(autoIndentSize);
if (autoIndentSize > 0) {
indent = String.Empty.PadLeft(autoIndentSize);
Write(indent, Style.Prompt);
}
@ -86,6 +88,11 @@ namespace ICSharpCode.PythonBinding @@ -86,6 +88,11 @@ namespace ICSharpCode.PythonBinding
return null;
}
string GetIndent(int autoIndentSize)
{
return String.Empty.PadLeft(autoIndentSize);
}
/// <summary>
/// Writes text to the console.
/// </summary>
@ -93,11 +100,21 @@ namespace ICSharpCode.PythonBinding @@ -93,11 +100,21 @@ namespace ICSharpCode.PythonBinding
{
textEditor.Write(text);
if (style == Style.Prompt) {
WriteSavedLineTextAfterFirstPrompt(text);
promptLength = text.Length;
textEditor.MakeCurrentContentReadOnly();
}
}
void WriteSavedLineTextAfterFirstPrompt(string promptText)
{
firstPromptDisplayed = true;
if (savedSendLineText != null) {
textEditor.Write(savedSendLineText + "\r\n");
savedSendLineText = null;
}
}
/// <summary>
/// Writes text followed by a newline to the console.
/// </summary>
@ -119,8 +136,8 @@ namespace ICSharpCode.PythonBinding @@ -119,8 +136,8 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public bool IsLineAvailable {
get {
lock (previousLines) {
return (previousLines.Count > 0);
lock (unreadLines) {
return (unreadLines.Count > 0);
}
}
}
@ -135,28 +152,19 @@ namespace ICSharpCode.PythonBinding @@ -135,28 +152,19 @@ namespace ICSharpCode.PythonBinding
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()
{
return textEditor.GetLine(textEditor.TotalLines - 1);
}
string ReadLineFromTextEditor()
{
{
int result = WaitHandle.WaitAny(waitHandles);
if (result == lineReceivedEventIndex) {
lock (previousLines) {
string line = previousLines[0];
previousLines.RemoveAt(0);
if (previousLines.Count == 0) {
lock (unreadLines) {
string line = unreadLines[0];
unreadLines.RemoveAt(0);
if (unreadLines.Count == 0) {
lineReceivedEvent.Reset();
}
return line;
@ -216,23 +224,28 @@ namespace ICSharpCode.PythonBinding @@ -216,23 +224,28 @@ namespace ICSharpCode.PythonBinding
return false;
}
/// <summary>
/// Move cursor to the end of the line before retrieving the line.
/// </summary>
void OnEnterKeyPressed()
{
lock (previousLines) {
// Move cursor to the end of the line.
textEditor.Column = GetLastTextEditorLine().Length;
// Append line.
string currentLine = GetCurrentLine();
previousLines.Add(currentLine);
commandLineHistory.Add(currentLine);
lock (unreadLines) {
MoveCursorToEndOfLastTextEditorLine();
SaveLastTextEditorLine();
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>
/// Returns true if the cursor is in a readonly text editor region.
@ -311,5 +324,34 @@ namespace ICSharpCode.PythonBinding @@ -311,5 +324,34 @@ namespace ICSharpCode.PythonBinding
// Put cursor at end.
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;
}
}
}
}

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

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

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

@ -11,23 +11,31 @@ using AvalonEdit = ICSharpCode.AvalonEdit; @@ -11,23 +11,31 @@ using AvalonEdit = ICSharpCode.AvalonEdit;
namespace ICSharpCode.PythonBinding
{
public class PythonConsolePad : AbstractPadContent
public class PythonConsolePad : AbstractPadContent, IPythonConsolePad
{
PythonConsoleTextEditor consoleTextEditor;
ThreadSafePythonConsoleTextEditor consoleTextEditor;
AvalonEdit.TextEditor textEditor;
PythonConsoleHost host;
public PythonConsolePad()
{
textEditor = new AvalonEdit.TextEditor();
consoleTextEditor = new PythonConsoleTextEditor(textEditor);
consoleTextEditor = new ThreadSafePythonConsoleTextEditor(textEditor);
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 {
get { return textEditor; }
}
}
public override void Dispose()
{

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

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

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

@ -1,33 +0,0 @@ @@ -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 @@ -20,9 +20,9 @@ namespace ICSharpCode.PythonBinding
ITextEditor textEditor;
ITextEditorOptions textEditorOptions;
public PythonTextEditorViewContent(IWorkbench workbench)
public PythonTextEditorViewContent(IPythonWorkbench workbench)
{
Init(workbench.ActiveWorkbenchWindow.ActiveViewContent);
Init(workbench.ActiveViewContent);
}
public PythonTextEditorViewContent(IViewContent view)

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

@ -0,0 +1,33 @@ @@ -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 @@ -15,14 +15,14 @@ namespace ICSharpCode.PythonBinding
{
public class RunDebugPythonCommand : RunPythonCommand
{
public RunDebugPythonCommand(IWorkbench workbench, PythonAddInOptions options, IDebugger debugger)
public RunDebugPythonCommand(IPythonWorkbench workbench, PythonAddInOptions options, IDebugger debugger)
: base(workbench, options, debugger)
{
Debug = true;
}
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 @@ -23,15 +23,15 @@ namespace ICSharpCode.PythonBinding
{
IDebugger debugger;
PythonAddInOptions options;
IWorkbench workbench;
IPythonWorkbench workbench;
PythonConsoleApplication ipy;
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.debugger = debugger;
@ -56,7 +56,7 @@ namespace ICSharpCode.PythonBinding @@ -56,7 +56,7 @@ namespace ICSharpCode.PythonBinding
ProcessStartInfo GetProcessStartInfo()
{
string scriptFileName = workbench.ActiveWorkbenchWindow.ActiveViewContent.PrimaryFileName;
string scriptFileName = workbench.ActiveViewContent.PrimaryFileName;
ipy.PythonScriptFileName = scriptFileName;
ipy.WorkingDirectory = Path.GetDirectoryName(scriptFileName);
return ipy.GetProcessStartInfo();

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

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

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

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

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

@ -20,29 +20,26 @@ namespace PythonBinding.Tests.Console @@ -20,29 +20,26 @@ namespace PythonBinding.Tests.Console
/// When the dot character is typed in after an object the code completion window should appear.
/// </summary>
[TestFixture]
public class PythonConsoleCodeCompletionTestFixture
public class PythonConsoleCodeCompletionTestFixture : PythonConsoleTestsBase
{
MockConsoleTextEditor textEditor;
PythonConsole console;
string prompt = ">>> ";
bool showCompletionWindowCalledBeforeDotTypedIn;
[TestFixtureSetUp]
public void SetUpFixture()
{
textEditor = new MockConsoleTextEditor();
console = new PythonConsole(textEditor, null);
console.WriteLine(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.A);
showCompletionWindowCalledBeforeDotTypedIn = textEditor.IsShowCompletionWindowCalled;
textEditor.RaisePreviewKeyDownEvent(Key.OemPeriod);
base.CreatePythonConsole();
TestablePythonConsole.WriteLine(prompt, Style.Prompt);
MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
showCompletionWindowCalledBeforeDotTypedIn = MockConsoleTextEditor.IsShowCompletionWindowCalled;
MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.OemPeriod);
}
[Test]
public void ShowCompletionWindowCalled()
{
Assert.IsTrue(textEditor.IsShowCompletionWindowCalled);
Assert.IsTrue(MockConsoleTextEditor.IsShowCompletionWindowCalled);
}
[Test]
@ -54,7 +51,7 @@ namespace PythonBinding.Tests.Console @@ -54,7 +51,7 @@ namespace PythonBinding.Tests.Console
[Test]
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 @@ -21,74 +21,71 @@ namespace PythonBinding.Tests.Console
/// Tests the PythonConsole's command line history.
/// </summary>
[TestFixture]
public class PythonConsoleCommandLineHistoryTestFixture
public class PythonConsoleCommandLineHistoryTestFixture : PythonConsoleTestsBase
{
PythonConsole pythonConsole;
MockConsoleTextEditor textEditor;
string prompt = ">>> ";
[SetUp]
public void Init()
{
textEditor = new MockConsoleTextEditor();
pythonConsole = new PythonConsole(textEditor, null);
pythonConsole.Write(prompt, Style.Prompt);
base.CreatePythonConsole();
TestablePythonConsole.Write(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
pythonConsole.Write(prompt, Style.Prompt);
textEditor.RaisePreviewKeyDownEvent(Key.B);
textEditor.RaisePreviewKeyDownEvent(Key.C);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
pythonConsole.Write(prompt, Style.Prompt);
MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
TestablePythonConsole.Write(prompt, Style.Prompt);
MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
TestablePythonConsole.Write(prompt, Style.Prompt);
}
[Test]
public void UpArrowKeyPressed()
{
Assert.IsTrue(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up));
Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up));
}
[Test]
public void CurrentLineAfterUpArrowKeyPressed()
{
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual("BC", pythonConsole.GetCurrentLine());
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual("BC", TestablePythonConsole.GetCurrentLine());
}
[Test]
public void TextEditorCursorIsAtEndOfLineAfterUpArrowKeyPressed()
{
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual(prompt.Length + 2, textEditor.Column);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual(prompt.Length + 2, MockConsoleTextEditor.Column);
}
[Test]
public void TextAfterUpArrowKeyPressedTwiceThenDownArrowKey()
{
UpArrowKeyPressedTwiceThenDownArrowKey();
Assert.AreEqual("BC", pythonConsole.GetCurrentLine());
Assert.AreEqual("BC", TestablePythonConsole.GetCurrentLine());
}
[Test]
public void TextEditorCursorAfterUpArrowKeyPressedTwice()
{
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual(prompt.Length + 1, textEditor.Column);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
Assert.AreEqual(prompt.Length + 1, MockConsoleTextEditor.Column);
}
[Test]
public void DownArrowKeyHandled()
{
Assert.IsTrue(textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down));
Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down));
}
void UpArrowKeyPressedTwiceThenDownArrowKey()
{
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down);
}
}
}

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

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

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

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

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

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

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

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

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

@ -0,0 +1,174 @@ @@ -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 @@ @@ -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; @@ -18,7 +18,7 @@ using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Console
{
[TestFixture]
public class ConsoleTextEditorTestFixture
public class PythonConsoleTextEditorTests
{
PythonConsoleTextEditor consoleTextEditor;
TextEditor avalonEditTextEditor;
@ -31,51 +31,62 @@ namespace PythonBinding.Tests.Console @@ -31,51 +31,62 @@ namespace PythonBinding.Tests.Console
}
[Test]
public void PythonConsoleTextEditorImplementsIConsoleTextEditorInterface()
public void InterfaceImplemented_NewInstance_ImplementsIConsoleTextEditorInterface()
{
Assert.IsNotNull(consoleTextEditor as IConsoleTextEditor);
}
[Test]
public void MakeCurrentTextEditorContentReadOnlyExtendsReadOnlyRegionToEntireDocument()
public void MakeCurrentContentReadOnly_OneLineOfTextInTextEditor_ExtendsReadOnlyRegionToEntireDocument()
{
avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc" + Environment.NewLine);
consoleTextEditor.MakeCurrentContentReadOnly();
IReadOnlySectionProvider readOnlySection = avalonEditTextEditor.TextArea.ReadOnlySectionProvider;
Assert.IsFalse(readOnlySection.CanInsert(2));
bool canInsertInsideText = readOnlySection.CanInsert(2);
Assert.IsFalse(canInsertInsideText);
}
[Test]
public void WriteMethodUpdatesTextEditor()
public void Write_TextEditorHasNoText_UpdatesTextEditor()
{
avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc");
Assert.AreEqual("abc", avalonEditTextEditor.Text);
string text = avalonEditTextEditor.Text;
string expectedText = "abc";
Assert.AreEqual(expectedText, text);
}
[Test]
public void ZeroBasedConsoleTextEditorColumnPositionIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased()
public void Column_TextEditorColumnSetToThree_ZeroBasedConsoleTextEditorColumnPositionReturnsTwoWhichIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased()
{
avalonEditTextEditor.Text = "test";
avalonEditTextEditor.TextArea.Caret.Column = 3;
Assert.AreEqual(2, consoleTextEditor.Column);
int column = consoleTextEditor.Column;
int expectedColumn = 2;
Assert.AreEqual(expectedColumn, column);
}
[Test]
public void SettingConsoleTextEditorColumnPositionUpdatesAvalonTextEditorColumnPosition()
public void Column_SettingConsoleTextEditorColumnPosition_UpdatesAvalonTextEditorColumnPosition()
{
avalonEditTextEditor.Text = "test";
avalonEditTextEditor.TextArea.Caret.Column = 0;
consoleTextEditor.Column = 1;
Assert.AreEqual(2, avalonEditTextEditor.TextArea.Caret.Column);
int column = avalonEditTextEditor.TextArea.Caret.Column;
int expectedColumn = 2;
Assert.AreEqual(expectedColumn, column);
}
[Test]
public void GetSelectionStartAndLengthWhenThreeCharactersSelected()
public void SelectionStart_ThreeCharactersSelectedInTextEditor_ConsoleTextEditorSelectionIsEqualToTextEditorSelection()
{
avalonEditTextEditor.Text = "te000xt";
int startOffset = 2;
@ -98,7 +109,7 @@ namespace PythonBinding.Tests.Console @@ -98,7 +109,7 @@ namespace PythonBinding.Tests.Console
}
[Test]
public void GetSelectionStartAndLengthWhenNothingSelected()
public void SelectionLength_NothingSelectedInTextEditor_ConsoleTextEditorSelectionMatchesTextEditorSelection()
{
avalonEditTextEditor.Text = "text";
avalonEditTextEditor.TextArea.Caret.Column = 1;
@ -109,37 +120,62 @@ namespace PythonBinding.Tests.Console @@ -109,37 +120,62 @@ namespace PythonBinding.Tests.Console
}
[Test]
public void ConsoleTextEditorLineEqualsOneLessThanAvalonTextEditorCaretLine()
public void Line_TextEditorCaretLineIsTwo_ConsoleTextEditorLineEqualsOneLessThanAvalonTextEditorCaretLine()
{
avalonEditTextEditor.Text = "abc\r\ndef";
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]
public void ConsoleTextEditorTotalLinesEqualsAvalonTextEditorTotalLines()
public void TotalLines_ThreeLinesInTextEditor_ReturnsThreeLines()
{
avalonEditTextEditor.Text = "abc\r\ndef\r\nghi";
Assert.AreEqual(3, consoleTextEditor.TotalLines);
int total = consoleTextEditor.TotalLines;
int expected = 3;
Assert.AreEqual(expected, total);
}
[Test]
public void GetLineForZerothLineReturnsFirstLineInAvalonTextEditor()
public void GetLine_GetLineForZerothLine_ReturnsFirstLineInAvalonTextEditor()
{
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]
public void ReplaceTextReplacesTextInAvalonEditTextEditor()
public void Replace_ReplaceSingleCharacterOnSecondLine_ReplacesCorrectTextInAvalonEditTextEditor()
{
avalonEditTextEditor.Text = "abc\r\ndef";
avalonEditTextEditor.Text =
"abc\r\n" +
"def";
avalonEditTextEditor.TextArea.Caret.Line = 2;
int lineOffset = 1;
int length = 1;
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 @@ -23,40 +23,37 @@ namespace PythonBinding.Tests.Console
/// Tests the PythonConsole's GetUnreadLines method.
/// </summary>
[TestFixture]
public class PythonConsoleUnreadLinesTestFixture
public class PythonConsoleUnreadLinesTestFixture : PythonConsoleTestsBase
{
PythonConsole pythonConsole;
MockConsoleTextEditor textEditor;
[SetUp]
public void Init()
{
textEditor = new MockConsoleTextEditor();
pythonConsole = new PythonConsole(textEditor, null);
base.CreatePythonConsole();
}
[Test]
public void NoUnreadLinesAtStart()
{
Assert.AreEqual(0, pythonConsole.GetUnreadLines().Length);
Assert.AreEqual(0, TestablePythonConsole.GetUnreadLines().Length);
}
[Test]
public void HasUnreadLines()
{
Assert.IsFalse(pythonConsole.IsLineAvailable);
Assert.IsFalse(TestablePythonConsole.IsLineAvailable);
}
[Test]
public void AddOneLine()
{
textEditor.RaisePreviewKeyDownEvent(System.Windows.Input.Key.A);
textEditor.RaisePreviewKeyDownEventForDialogKey(System.Windows.Input.Key.Enter);
MockConsoleTextEditor.RaisePreviewKeyDownEvent(System.Windows.Input.Key.A);
MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(System.Windows.Input.Key.Enter);
string[] lines = TestablePythonConsole.GetUnreadLines();
string[] expectedLines = new string[] {"A"};
Assert.AreEqual(expectedLines, pythonConsole.GetUnreadLines());
Assert.IsTrue(pythonConsole.IsLineAvailable);
Assert.AreEqual(expectedLines, lines);
Assert.IsTrue(TestablePythonConsole.IsLineAvailable);
}
}
}

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

@ -18,45 +18,41 @@ namespace PythonBinding.Tests.Console @@ -18,45 +18,41 @@ namespace PythonBinding.Tests.Console
/// Tests that the PythonConsole Write method correctly update the text editor.
/// </summary>
[TestFixture]
public class PythonConsoleWriteTestFixture
public class PythonConsoleWriteTestFixture : PythonConsoleTestsBase
{
PythonConsole pythonConsole;
MockConsoleTextEditor mockTextEditor;
[SetUp]
public void Init()
{
mockTextEditor = new MockConsoleTextEditor();
mockTextEditor.Text = String.Empty;
pythonConsole = new PythonConsole(mockTextEditor, null);
base.CreatePythonConsole();
MockConsoleTextEditor.Text = String.Empty;
}
[Test]
public void WriteLine()
{
pythonConsole.WriteLine();
Assert.AreEqual(Environment.NewLine, mockTextEditor.Text);
TestablePythonConsole.WriteLine();
Assert.AreEqual(Environment.NewLine, MockConsoleTextEditor.Text);
}
[Test]
public void WriteLineWithText()
{
pythonConsole.WriteLine("test", Style.Out);
Assert.AreEqual("test" + Environment.NewLine, mockTextEditor.Text);
TestablePythonConsole.WriteLine("test", Style.Out);
Assert.AreEqual("test" + Environment.NewLine, MockConsoleTextEditor.Text);
}
[Test]
public void TwoWrites()
{
pythonConsole.Write("a", Style.Out);
pythonConsole.Write("b", Style.Out);
Assert.AreEqual("ab", mockTextEditor.Text);
TestablePythonConsole.Write("a", Style.Out);
TestablePythonConsole.Write("b", Style.Out);
Assert.AreEqual("ab", MockConsoleTextEditor.Text);
}
[Test]
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 @@ @@ -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 @@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console
{
string line1;
string line2;
PythonConsole pythonConsole;
TestablePythonConsole pythonConsole;
bool lineAvailableBeforeFirstEnterKey;
bool lineAvailableAfterFirstEnterKey;
bool lineAvailableAtEnd;
@ -37,9 +37,8 @@ namespace PythonBinding.Tests.Console @@ -37,9 +37,8 @@ namespace PythonBinding.Tests.Console
[TestFixtureSetUp]
public void SetUpFixture()
{
MockConsoleTextEditor textEditor = new MockConsoleTextEditor();
using (pythonConsole = new PythonConsole(textEditor, null)) {
using (pythonConsole = new TestablePythonConsole()) {
MockConsoleTextEditor textEditor = pythonConsole.MockConsoleTextEditor;
textEditor.RaisePreviewKeyDownEvent(Input.Key.A);
textEditor.RaisePreviewKeyDownEvent(Input.Key.B);
textEditor.RaisePreviewKeyDownEvent(Input.Key.C);

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

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

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

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

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

@ -24,15 +24,8 @@ namespace PythonBinding.Tests.Gui @@ -24,15 +24,8 @@ namespace PythonBinding.Tests.Gui
[TestFixtureSetUp]
public void SetUpFixture()
{
// Create dummy view content with the Python script.
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;
MockWorkbench workbench = MockWorkbench.CreateWorkbenchWithOneViewContent(@"C:\Projects\test.py");
// Create the Python binding addin options.
Properties p = new Properties();
PythonAddInOptions options = new PythonAddInOptions(p);
options.PythonFileName = @"C:\IronPython\ipy.exe";
@ -43,21 +36,26 @@ namespace PythonBinding.Tests.Gui @@ -43,21 +36,26 @@ namespace PythonBinding.Tests.Gui
}
[Test]
public void DebuggerStartMethodCalled()
public void Run_PythonFileOpen_DebuggerStartMethodCalled()
{
Assert.IsTrue(debugger.StartMethodCalled);
bool result = debugger.StartMethodCalled;
Assert.IsTrue(result);
}
[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]
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 @@ -20,23 +20,16 @@ namespace PythonBinding.Tests.Gui
/// passing the filename of the python script active in SharpDevelop.
/// </summary>
[TestFixture]
public class RunPythonCommandTestFixture
public class RunPythonCommandTests
{
MockDebugger debugger;
RunPythonCommand command;
[TestFixtureSetUp]
public void SetUpFixture()
[SetUp]
public void Init()
{
// Create dummy view content with the Python script.
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;
MockWorkbench workbench = MockWorkbench.CreateWorkbenchWithOneViewContent(@"C:\Projects\test.py");
// Create the Python binding addin options.
Properties p = new Properties();
PythonAddInOptions options = new PythonAddInOptions(p);
options.PythonFileName = @"C:\IronPython\ipy.exe";
@ -47,31 +40,36 @@ namespace PythonBinding.Tests.Gui @@ -47,31 +40,36 @@ namespace PythonBinding.Tests.Gui
}
[Test]
public void RunPythonCommandIsAbstractCommand()
public void BaseClass_NewInstance_IsAbstractCommand()
{
Assert.IsNotNull(command as AbstractCommand);
}
[Test]
public void DebuggerStartWithoutDebuggingMethodCalled()
public void Run_PythonFileOpen_DebuggerStartWithoutDebuggingMethodCalled()
{
Assert.IsTrue(debugger.StartWithoutDebuggingMethodCalled);
bool result = debugger.StartWithoutDebuggingMethodCalled;
Assert.IsTrue(result);
}
[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]
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]
public void WorkingDirectoryIsPathToPythonScriptFileBeingRun()
public void Run_PythonFileOpen_IronPythonConsoleWorkingDirectoryIsPathToPythonScriptFileBeingRun()
{
string workingDirectory = debugger.ProcessStartInfo.WorkingDirectory;
string expectedWorkingDirectory = @"C:\Projects";

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

@ -0,0 +1,93 @@ @@ -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 @@ @@ -100,10 +100,11 @@
<Compile Include="Completion\PythonImportExpressionContextTestFixture.cs" />
<Compile Include="Completion\PythonSocketLibraryDocumentationTestFixture.cs" />
<Compile Include="Completion\SysModuleMembersInPythonContextTestFixture.cs" />
<Compile Include="Configuration\AddInFileTestFixture.cs" />
<Compile Include="Configuration\AddInOptionsTestFixture.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\KeysPressedWhenCompletionWindowOpenTestFixture.cs" />
<Compile Include="Console\CommandLineHistoryTestFixture.cs" />
@ -123,7 +124,7 @@ @@ -123,7 +124,7 @@
<Compile Include="Console\PythonConsoleUnreadLinesTestFixture.cs" />
<Compile Include="Console\PythonConsoleWriteTestFixture.cs" />
<Compile Include="Console\PythonOutputStreamTestFixture.cs" />
<Compile Include="Console\ConsoleTextEditorTestFixture.cs" />
<Compile Include="Console\PythonConsoleTextEditorTests.cs" />
<Compile Include="Console\TwoPythonConsoleLinesWaitingTestFixture.cs" />
<Compile Include="Converter\AddHandlerConversionTestFixture.cs" />
<Compile Include="Converter\ArrayCastConversionTestFixture.cs" />
@ -346,7 +347,8 @@ @@ -346,7 +347,8 @@
<Compile Include="Gui\FormsDesignerDisplayBindingTestFixture.cs" />
<Compile Include="Gui\PythonIndentationTests.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\InvalidCastInPythonParserTestFixture.cs" />
<Compile Include="Parsing\MethodWithParametersTestFixture.cs" />
@ -455,6 +457,10 @@ @@ -455,6 +457,10 @@
<Compile Include="Utils\DerivedToolStripMenuItem.cs" />
<Compile Include="Utils\DoublePropertyUserControl.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\MockComponentCreator.cs" />
<Compile Include="Utils\MockConsoleTextEditor.cs" />
@ -468,10 +474,11 @@ @@ -468,10 +474,11 @@
<Compile Include="Utils\MockEventDescriptor.cs" />
<Compile Include="Utils\MockExtenderProviderService.cs" />
<Compile Include="Utils\MockOpenedFile.cs" />
<Compile Include="Utils\MockPadDescriptor.cs" />
<Compile Include="Utils\MockProject.cs" />
<Compile Include="Utils\MockProjectContent.cs" />
<Compile Include="Utils\MockPropertyDescriptor.cs" />
<Compile Include="Utils\MockPythonConsole.cs" />
<Compile Include="Utils\MockPythonConsolePad.cs" />
<Compile Include="Utils\MockPythonFileService.cs" />
<Compile Include="Utils\MockResourceReader.cs" />
<Compile Include="Utils\MockResourceService.cs" />
@ -482,15 +489,12 @@ @@ -482,15 +489,12 @@
<Compile Include="Utils\MockTypeResolutionService.cs" />
<Compile Include="Utils\MockViewContent.cs" />
<Compile Include="Utils\MockWorkbench.cs" />
<Compile Include="Utils\MockWorkbenchWindow.cs" />
<Compile Include="Utils\MSBuildEngineHelper.cs" />
<Compile Include="Utils\TestablePythonConsole.cs" />
<Compile Include="Utils\Tests\AddInPathHelperTestFixture.cs" />
<EmbeddedResource Include="..\Project\PythonBinding.addin">
<Link>PythonBinding.addin</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\Project\Templates\Empty.xft">
<Link>Empty.xft</Link>
</EmbeddedResource>
<None Include="app.config" />
<Compile Include="Parsing\AddInvalidSourceSpanToErrorSinkTestFixture.cs" />
<Compile Include="Utils\NullPropertyUserControl.cs" />

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

@ -0,0 +1,53 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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;
}
}
}

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

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

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

@ -1,40 +0,0 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ -13,11 +13,10 @@ namespace PythonBinding.Tests.Utils
{
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;
@ -44,20 +43,15 @@ namespace PythonBinding.Tests.Utils @@ -44,20 +43,15 @@ namespace PythonBinding.Tests.Utils
}
public IDocument Document {
get {
throw new NotImplementedException();
}
get { return FakeDocument; }
}
public ITextEditorCaret Caret {
get {
throw new NotImplementedException();
}
get { return FakeCaret; }
}
public ITextEditorOptions Options {
get { return options; }
set { options = value; }
get { return MockTextEditorOptions; }
}
public ICSharpCode.SharpDevelop.ILanguageBinding Language {

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

@ -8,165 +8,37 @@ @@ -8,165 +8,37 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
namespace PythonBinding.Tests.Utils
{
/// <summary>
/// Dummy IWorkbench class.
/// </summary>
public class MockWorkbench : IWorkbench
{
DummySynchronizeInvoke synchronizeInvoke = new DummySynchronizeInvoke();
Form form = new Form();
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 {
get {
throw new NotImplementedException();
}
}
public class MockWorkbench : IPythonWorkbench
{
public MockPythonConsolePad MockPythonConsolePad = new MockPythonConsolePad();
public MockEditableViewContent ActiveMockEditableViewContent;
public void Initialize()
public static MockWorkbench CreateWorkbenchWithOneViewContent(string fileName)
{
MockEditableViewContent viewContent = new MockEditableViewContent();
viewContent.PrimaryFileName = new FileName(fileName);
MockWorkbench workbench = new MockWorkbench();
workbench.ActiveMockEditableViewContent = viewContent;
return workbench;
}
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();
}
public PadDescriptor GetPad(Type type)
{
throw new NotImplementedException();
}
public void CloseAllViews()
{
throw new NotImplementedException();
}
public void RedrawAllComponents()
{
throw new NotImplementedException();
}
public void UpdateRenderer()
{
throw new NotImplementedException();
}
public Properties CreateMemento()
{
throw new NotImplementedException();
}
public void SetMemento(Properties memento)
public IViewContent ActiveViewContent {
get { return ActiveMockEditableViewContent; }
}
public IPythonConsolePad GetPythonConsolePad()
{
}
public bool FullScreen {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
return MockPythonConsolePad;
}
}
}

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

@ -1,129 +0,0 @@ @@ -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 @@ @@ -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 @@ -42,7 +42,7 @@ namespace PythonBinding.Tests.Utils.Tests
public void CanReplaceTextEditorOptions()
{
MockTextEditorOptions options = new MockTextEditorOptions();
view.TextEditorOptions = options;
view.MockTextEditorOptions = options;
Assert.AreSame(options, view.TextEditor.Options);
}
}

Loading…
Cancel
Save