From 4608b9b5800b8efec8491f981f3bad1b6dc6c0f3 Mon Sep 17 00:00:00 2001 From: mrward Date: Sun, 5 Sep 2010 20:17:27 +0100 Subject: [PATCH] Move IronPython and IronRuby console classes to common Scripting project. --- .../Project/Src/PythonConsole.cs | 313 +--------------- .../DisposedPythonConsoleTestFixture.cs | 32 -- ...honConsoleCommandLineHistoryTestFixture.cs | 87 ----- .../PythonConsoleCurrentLineTestFixture.cs | 47 --- .../Console/PythonConsoleReadTestFixture.cs | 119 ------- .../Test/Console/PythonConsoleTestsBase.cs | 22 -- .../PythonConsoleUnreadLinesTestFixture.cs | 55 --- ...TwoPythonConsoleLinesWaitingTestFixture.cs | 102 ------ .../Test/PythonBinding.Tests.csproj | 14 - .../RubyBinding/Project/Src/RubyConsole.cs | 316 +---------------- .../Console/DisposedRubyConsoleTestFixture.cs | 32 -- ...ssedWhenCompletionWindowOpenTestFixture.cs | 55 --- .../RubyConsoleCodeCompletionTestFixture.cs | 55 --- .../Console/RubyConsoleEnterKeyTestFixture.cs | 60 ---- .../Console/RubyConsoleHomeKeyTestFixture.cs | 49 --- .../RubyConsoleReadOnlyRegionsTestFixture.cs | 160 --------- .../Test/Console/RubyConsoleSendLineTests.cs | 170 --------- .../Test/Console/RubyConsoleTestsBase.cs | 22 -- .../Console/RubyConsoleWriteTestFixture.cs | 53 --- .../RubyBinding/Test/RubyBinding.Tests.csproj | 14 - .../Project/ICSharpCode.Scripting.csproj | 2 + .../Scripting/Project/Src/ScriptingConsole.cs | 334 ++++++++++++++++++ .../Scripting/Project/Src/ScriptingStyle.cs | 19 + .../Console/DisposedScriptingConsoleTests.cs | 29 ++ ...ysPressedWhenCompletionWindowOpenTests.cs} | 25 +- .../ScriptingConsoleCodeCompletionTests.cs} | 12 +- ...criptingConsoleCommandLineHistoryTests.cs} | 25 +- .../ScriptingConsoleCurrentLineTests.cs} | 24 +- .../Console/ScriptingConsoleEnterKeyTests.cs} | 17 +- .../Console/ScriptingConsoleHomeKeyTests.cs} | 13 +- .../ScriptingConsoleReadOnlyRegionsTests.cs} | 35 +- .../Console/ScriptingConsoleReadTests.cs} | 17 +- .../Console/ScriptingConsoleSendLineTests.cs} | 53 ++- .../Test/Console/ScriptingConsoleTestsBase.cs | 21 ++ .../ScriptingConsoleUnreadLinesTests.cs} | 26 +- .../Console/ScriptingConsoleWriteTests.cs} | 26 +- .../Console/TwoConsoleLinesWaitingTests.cs} | 31 +- .../Test/ICSharpCode.Scripting.Tests.csproj | 15 + .../Test/Utils/TestableScriptingConsole.cs | 51 +++ 39 files changed, 624 insertions(+), 1928 deletions(-) delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCommandLineHistoryTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCurrentLineTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTestsBase.cs delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleUnreadLinesTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TwoPythonConsoleLinesWaitingTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/DisposedRubyConsoleTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCodeCompletionTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleEnterKeyTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleHomeKeyTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleReadOnlyRegionsTestFixture.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleSendLineTests.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleTestsBase.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleWriteTestFixture.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingStyle.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Console/DisposedScriptingConsoleTests.cs rename src/AddIns/BackendBindings/{Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs => Scripting/Test/Console/KeysPressedWhenCompletionWindowOpenTests.cs} (60%) rename src/AddIns/BackendBindings/{Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs => Scripting/Test/Console/ScriptingConsoleCodeCompletionTests.cs} (82%) rename src/AddIns/BackendBindings/{Ruby/RubyBinding/Test/Console/RubyConsoleCommandLineHistoryTestFixture.cs => Scripting/Test/Console/ScriptingConsoleCommandLineHistoryTests.cs} (76%) rename src/AddIns/BackendBindings/{Ruby/RubyBinding/Test/Console/RubyConsoleCurrentLineTestFixture.cs => Scripting/Test/Console/ScriptingConsoleCurrentLineTests.cs} (51%) rename src/AddIns/BackendBindings/{Python/PythonBinding/Test/Console/PythonConsoleEnterKeyTestFixture.cs => Scripting/Test/Console/ScriptingConsoleEnterKeyTests.cs} (80%) rename src/AddIns/BackendBindings/{Python/PythonBinding/Test/Console/PythonConsoleHomeKeyTestFixture.cs => Scripting/Test/Console/ScriptingConsoleHomeKeyTests.cs} (78%) rename src/AddIns/BackendBindings/{Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs => Scripting/Test/Console/ScriptingConsoleReadOnlyRegionsTests.cs} (80%) rename src/AddIns/BackendBindings/{Ruby/RubyBinding/Test/Console/RubyConsoleReadTestFixture.cs => Scripting/Test/Console/ScriptingConsoleReadTests.cs} (88%) rename src/AddIns/BackendBindings/{Python/PythonBinding/Test/Console/PythonConsoleSendLineTests.cs => Scripting/Test/Console/ScriptingConsoleSendLineTests.cs} (71%) create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs rename src/AddIns/BackendBindings/{Ruby/RubyBinding/Test/Console/RubyConsoleUnreadLinesTestFixture.cs => Scripting/Test/Console/ScriptingConsoleUnreadLinesTests.cs} (55%) rename src/AddIns/BackendBindings/{Python/PythonBinding/Test/Console/PythonConsoleWriteTestFixture.cs => Scripting/Test/Console/ScriptingConsoleWriteTests.cs} (51%) rename src/AddIns/BackendBindings/{Ruby/RubyBinding/Test/Console/TwoRubyConsoleLinesWaitingTestFixture.cs => Scripting/Test/Console/TwoConsoleLinesWaitingTests.cs} (70%) create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingConsole.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs index 6c7b73067d..ad525e2506 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs @@ -3,47 +3,22 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.IO; -using System.Text; -using System.Threading; -using System.Windows.Input; -using ICSharpCode.AvalonEdit.CodeCompletion; + using ICSharpCode.Scripting; -using IronPython.Hosting; using Microsoft.Scripting.Hosting.Shell; namespace ICSharpCode.PythonBinding { - public class PythonConsole : IConsole, IDisposable, IMemberProvider, IScriptingConsole + public class PythonConsole : ScriptingConsole, IConsole { - IScriptingConsoleTextEditor textEditor; - int lineReceivedEventIndex = 0; // The index into the waitHandles array where the lineReceivedEvent is stored. - ManualResetEvent lineReceivedEvent = new ManualResetEvent(false); - ManualResetEvent disposedEvent = new ManualResetEvent(false); - WaitHandle[] waitHandles; - int promptLength; - bool firstPromptDisplayed; - string savedSendLineText; - CommandLineHistory commandLineHistory = new CommandLineHistory(); - - protected List unreadLines = new List(); - public PythonConsole(IScriptingConsoleTextEditor textEditor) + : base(textEditor) { - waitHandles = new WaitHandle[] {lineReceivedEvent, disposedEvent}; - - this.textEditor = textEditor; - textEditor.PreviewKeyDown += ProcessPreviewKeyDown; } public CommandLine CommandLine { get; set; } - public void Dispose() - { - disposedEvent.Set(); - } - public TextWriter Output { get { return null; } set { } @@ -57,298 +32,24 @@ namespace ICSharpCode.PythonBinding /// /// Gets the member names of the specified item. /// - public IList GetMemberNames(string name) + public override IList GetMemberNames(string name) { return CommandLine.GetMemberNames(name); } - public IList GetGlobals(string name) + public override IList GetGlobals(string name) { return CommandLine.GetGlobals(name); } - /// - /// Returns the next line typed in by the console user. If no line is available this method - /// will block. - /// - public string ReadLine(int autoIndentSize) - { - string indent = GetIndent(autoIndentSize); - if (autoIndentSize > 0) { - Write(indent, Style.Prompt); - } - - string line = ReadLineFromTextEditor(); - if (line != null) { - return indent + line; - } - return null; - } - - string GetIndent(int autoIndentSize) - { - return String.Empty.PadLeft(autoIndentSize); - } - - /// - /// Writes text to the console. - /// public void Write(string text, Style style) { - textEditor.Write(text); - if (style == Style.Prompt) { - WriteSavedLineTextAfterFirstPrompt(text); - promptLength = text.Length; - textEditor.MakeCurrentContentReadOnly(); - } + base.Write(text, (ScriptingStyle)style); } - void WriteSavedLineTextAfterFirstPrompt(string promptText) - { - firstPromptDisplayed = true; - if (savedSendLineText != null) { - textEditor.Write(savedSendLineText + "\r\n"); - savedSendLineText = null; - } - } - - /// - /// Writes text followed by a newline to the console. - /// public void WriteLine(string text, Style style) { - Write(text + Environment.NewLine, style); - } - - /// - /// Writes an empty line to the console. - /// - public void WriteLine() - { - Write(Environment.NewLine, Style.Out); - } - - /// - /// Indicates whether there is a line already read by the console and waiting to be processed. - /// - public bool IsLineAvailable { - get { - lock (unreadLines) { - return (unreadLines.Count > 0); - } - } - } - - /// - /// Gets the text that is yet to be processed from the console. This is the text that is being - /// typed in by the user who has not yet pressed the enter key. - /// - public string GetCurrentLine() - { - string fullLine = GetLastTextEditorLine(); - return fullLine.Substring(promptLength); - } - - string GetLastTextEditorLine() - { - return textEditor.GetLine(textEditor.TotalLines - 1); - } - - string ReadLineFromTextEditor() - { - int result = WaitHandle.WaitAny(waitHandles); - if (result == lineReceivedEventIndex) { - lock (unreadLines) { - string line = unreadLines[0]; - unreadLines.RemoveAt(0); - if (unreadLines.Count == 0) { - lineReceivedEvent.Reset(); - } - return line; - } - } - return null; - } - - /// - /// Processes characters entered into the text editor by the user. - /// - void ProcessPreviewKeyDown(object source, ConsoleTextEditorKeyEventArgs e) - { - Key keyPressed = e.Key; - e.Handled = HandleKeyDown(keyPressed); - } - - bool HandleKeyDown(Key keyPressed) - { - if (textEditor.IsCompletionWindowDisplayed) { - return false; - } - - if (IsInReadOnlyRegion) { - switch (keyPressed) { - case Key.Left: - case Key.Right: - case Key.Up: - case Key.Down: - return false; - default: - return true; - } - } - - switch (keyPressed) { - case Key.Back: - return !CanBackspace; - case Key.Home: - MoveToHomePosition(); - return true; - case Key.Down: - MoveToNextCommandLine(); - return true; - case Key.Up: - MoveToPreviousCommandLine(); - return true; - } - - if (keyPressed == Key.Return) { - OnEnterKeyPressed(); - } - - if (keyPressed == Key.OemPeriod) { - ShowCompletionWindow(); - } - return false; - } - - void OnEnterKeyPressed() - { - 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); - } - - /// - /// Returns true if the cursor is in a readonly text editor region. - /// - bool IsInReadOnlyRegion { - get { return IsCurrentLineReadOnly || IsInPrompt; } - } - - /// - /// Only the last line in the text editor is not read only. - /// - bool IsCurrentLineReadOnly { - get { return textEditor.Line < (textEditor.TotalLines - 1); } - } - - /// - /// Determines whether the current cursor position is in a prompt. - /// - bool IsInPrompt { - get { return (textEditor.Column - promptLength) < 0; } - } - - /// - /// Returns true if the user can backspace at the current cursor position. - /// - bool CanBackspace { - get { - int cursorIndex = textEditor.Column - promptLength; - int selectionStartIndex = textEditor.SelectionStart - promptLength; - return (cursorIndex > 0) && (selectionStartIndex > 0); - } - } - - void ShowCompletionWindow() - { - ScriptingConsoleCompletionDataProvider completionProvider = new ScriptingConsoleCompletionDataProvider(this); - textEditor.ShowCompletionWindow(completionProvider); - } - - /// - /// The home position is at the start of the line after the prompt. - /// - void MoveToHomePosition() - { - textEditor.Column = promptLength; - } - - /// - /// Shows the previous command line in the command line history. - /// - void MoveToPreviousCommandLine() - { - if (commandLineHistory.MovePrevious()) { - ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); - } - } - - /// - /// Shows the next command line in the command line history. - /// - void MoveToNextCommandLine() - { - if (commandLineHistory.MoveNext()) { - ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); - } - } - - /// - /// Replaces the current line text after the prompt with the specified text. - /// - void ReplaceCurrentLineTextAfterPrompt(string text) - { - string currentLine = GetCurrentLine(); - textEditor.Replace(promptLength, currentLine.Length, text); - - // 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 lines) - { - return new StringListLock(lines); - } - - protected virtual void FireLineReceivedEvent() - { - lineReceivedEvent.Set(); - } - - void WriteLineIfFirstPromptHasBeenDisplayed(string text) - { - if (firstPromptDisplayed) { - WriteLine(text, Style.Out); - } else { - savedSendLineText = text; - } + base.WriteLine(text, (ScriptingStyle)style); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs deleted file mode 100644 index 971f787bed..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.PythonBinding; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests.Console -{ - /// - /// Tests the disposing of the PythonConsole. - /// - [TestFixture] - public class DisposedPythonConsoleTestFixture : PythonConsoleTestsBase - { - [Test] - public void PythonConsoleImplementsIDisposable() - { - base.CreatePythonConsole(); - Assert.IsNotNull(TestablePythonConsole as IDisposable); - } - - [Test] - public void ReadLineReturnsNullWhenConsoleDisposed() - { - base.CreatePythonConsole(); - TestablePythonConsole.Dispose(); - Assert.IsNull(TestablePythonConsole.ReadLine(0)); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCommandLineHistoryTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCommandLineHistoryTestFixture.cs deleted file mode 100644 index af6223b16b..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCommandLineHistoryTestFixture.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Windows.Input; - -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; -using ICSharpCode.PythonBinding; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests.Console -{ - /// - /// Tests the PythonConsole's command line history. - /// - [TestFixture] - public class PythonConsoleCommandLineHistoryTestFixture : PythonConsoleTestsBase - { - string prompt = ">>> "; - - [SetUp] - public void Init() - { - base.CreatePythonConsole(); - TestablePythonConsole.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(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up)); - } - - [Test] - public void CurrentLineAfterUpArrowKeyPressed() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); - Assert.AreEqual("BC", TestablePythonConsole.GetCurrentLine()); - } - - [Test] - public void TextEditorCursorIsAtEndOfLineAfterUpArrowKeyPressed() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); - Assert.AreEqual(prompt.Length + 2, MockConsoleTextEditor.Column); - } - - [Test] - public void TextAfterUpArrowKeyPressedTwiceThenDownArrowKey() - { - UpArrowKeyPressedTwiceThenDownArrowKey(); - Assert.AreEqual("BC", TestablePythonConsole.GetCurrentLine()); - } - - [Test] - public void TextEditorCursorAfterUpArrowKeyPressedTwice() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); - Assert.AreEqual(prompt.Length + 1, MockConsoleTextEditor.Column); - } - - [Test] - public void DownArrowKeyHandled() - { - Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); - } - - void UpArrowKeyPressedTwiceThenDownArrowKey() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCurrentLineTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCurrentLineTestFixture.cs deleted file mode 100644 index 87d7416dc5..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCurrentLineTestFixture.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Windows.Input; -using ICSharpCode.PythonBinding; -using ICSharpCode.Scripting.Tests.Utils; -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests.Console -{ - /// - /// Tests the PythonConsole's GetCurrentLine method. - /// - [TestFixture] - public class PythonConsoleCurrentLineTestFixture - { - TestablePythonConsole pythonConsole; - MockConsoleTextEditor textEditor; - string prompt = ">>> "; - - [SetUp] - public void Init() - { - pythonConsole = new TestablePythonConsole(); - pythonConsole.Write(prompt, Style.Prompt); - textEditor = pythonConsole.MockConsoleTextEditor; - } - - [Test] - public void CurrentLineIsEmpty() - { - Assert.AreEqual(String.Empty, pythonConsole.GetCurrentLine()); - } - - [Test] - public void SingleCharacterAddedToTextEditor() - { - textEditor.RaisePreviewKeyDownEvent(Key.A); - Assert.AreEqual("A", pythonConsole.GetCurrentLine()); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs deleted file mode 100644 index c1a86e6b82..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Threading; -using System.Windows.Input; - -using ICSharpCode.PythonBinding; -using ICSharpCode.Scripting.Tests.Utils; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests.Console -{ - /// - /// Tests the PythonConsole ReadLine method. - /// - [TestFixture] - public class PythonConsoleReadTestFixture : PythonConsoleTestsBase - { - int initialAutoIndentSize = 4; - string readLine; - int autoIndentSize; - bool raiseKeyPressEvent; - bool raiseDialogKeyPressEvent; - - [TestFixtureSetUp] - public void Init() - { - base.CreatePythonConsole(); - - autoIndentSize = initialAutoIndentSize; - Thread thread = new Thread(ReadLineFromConsoleOnDifferentThread); - thread.Start(); - - int sleepInterval = 10; - int maxWait = 2000; - int currentWait = 0; - while ((MockConsoleTextEditor.Text.Length < autoIndentSize) && (currentWait < maxWait)) { - Thread.Sleep(sleepInterval); - currentWait += sleepInterval; - } - - raiseKeyPressEvent = MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - raiseDialogKeyPressEvent = MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - - currentWait = 0; - while ((MockConsoleTextEditor.Text.Length < autoIndentSize + 2) && (currentWait < maxWait)) { - Thread.Sleep(10); - currentWait += sleepInterval; - } - thread.Join(2000); - } - - [TestFixtureTearDown] - public void TearDown() - { - TestablePythonConsole.Dispose(); - } - - [Test] - public void ReadLineFromConsole() - { - string expectedString = String.Empty.PadLeft(initialAutoIndentSize) + "A"; - Assert.AreEqual(expectedString, readLine); - } - - [Test] - public void ReadLineWithNonZeroAutoIndentSizeWritesSpacesToTextEditor() - { - string expectedString = String.Empty.PadLeft(initialAutoIndentSize) + "A\r\n"; - Assert.AreEqual(expectedString, MockConsoleTextEditor.Text); - } - - [Test] - public void DocumentInsertCalledWhenAutoIndentIsNonZero() - { - Assert.IsTrue(MockConsoleTextEditor.IsWriteCalled); - } - - [Test] - public void NoTextWrittenWhenAutoIndentSizeIsZero() - { - TestablePythonConsole pythonConsole = new TestablePythonConsole(); - MockConsoleTextEditor textEditor = pythonConsole.MockConsoleTextEditor; - textEditor.RaisePreviewKeyDownEvent(Key.A); - textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - - textEditor.IsWriteCalled = false; - pythonConsole.ReadLine(0); - Assert.IsFalse(textEditor.IsWriteCalled); - } - - /// - /// Should return false for any character that should be handled by the text editor itself. - /// - [Test] - public void RaiseKeyPressEventReturnedFalse() - { - Assert.IsFalse(raiseKeyPressEvent); - } - - /// - /// Should return false for any character that should be handled by the text editor itself. - /// - [Test] - public void RaiseDialogKeyPressEventReturnedFalse() - { - Assert.IsFalse(raiseDialogKeyPressEvent); - } - - void ReadLineFromConsoleOnDifferentThread() - { - System.Console.WriteLine("Reading on different thread"); - readLine = TestablePythonConsole.ReadLine(autoIndentSize); - System.Console.WriteLine("Finished reading on different thread"); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTestsBase.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTestsBase.cs deleted file mode 100644 index 3be7b5d71f..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTestsBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.PythonBinding; -using ICSharpCode.Scripting.Tests.Utils; -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; - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleUnreadLinesTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleUnreadLinesTestFixture.cs deleted file mode 100644 index e969ded84e..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleUnreadLinesTestFixture.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Windows.Input; - -using ICSharpCode.PythonBinding; -using IronPython.Hosting; -using IronPython.Runtime; -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests.Console -{ - /// - /// Tests the PythonConsole's GetUnreadLines method. - /// - [TestFixture] - public class PythonConsoleUnreadLinesTestFixture : PythonConsoleTestsBase - { - [SetUp] - public void Init() - { - base.CreatePythonConsole(); - } - - [Test] - public void NoUnreadLinesAtStart() - { - Assert.AreEqual(0, TestablePythonConsole.GetUnreadLines().Length); - } - - [Test] - public void HasUnreadLines() - { - Assert.IsFalse(TestablePythonConsole.IsLineAvailable); - } - - [Test] - public void AddOneLine() - { - 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, lines); - Assert.IsTrue(TestablePythonConsole.IsLineAvailable); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TwoPythonConsoleLinesWaitingTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TwoPythonConsoleLinesWaitingTestFixture.cs deleted file mode 100644 index 31c1ab0f71..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TwoPythonConsoleLinesWaitingTestFixture.cs +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Threading; -using ICSharpCode.PythonBinding; -using ICSharpCode.Scripting.Tests.Utils; -using IronPython.Hosting; -using IronPython.Runtime; -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using PythonBinding.Tests.Utils; -using Input = System.Windows.Input; - -namespace PythonBinding.Tests.Console -{ - /// - /// Ensures that both lines of text can be read from the python console if they are written - /// before ReadLine is called. - /// - [TestFixture] - public class TwoPythonConsoleLinesWaitingTestFixture - { - string line1; - string line2; - TestablePythonConsole pythonConsole; - bool lineAvailableBeforeFirstEnterKey; - bool lineAvailableAfterFirstEnterKey; - bool lineAvailableAtEnd; - - [TestFixtureSetUp] - public void SetUpFixture() - { - using (pythonConsole = new TestablePythonConsole()) { - MockConsoleTextEditor textEditor = pythonConsole.MockConsoleTextEditor; - textEditor.RaisePreviewKeyDownEvent(Input.Key.A); - textEditor.RaisePreviewKeyDownEvent(Input.Key.B); - textEditor.RaisePreviewKeyDownEvent(Input.Key.C); - lineAvailableBeforeFirstEnterKey = pythonConsole.IsLineAvailable; - textEditor.RaisePreviewKeyDownEventForDialogKey(Input.Key.Enter); - lineAvailableAfterFirstEnterKey = pythonConsole.IsLineAvailable; - - textEditor.RaisePreviewKeyDownEvent(Input.Key.D); - textEditor.RaisePreviewKeyDownEvent(Input.Key.E); - textEditor.RaisePreviewKeyDownEvent(Input.Key.F); - textEditor.RaisePreviewKeyDownEventForDialogKey(Input.Key.Enter); - - Thread t = new Thread(ReadLinesOnSeparateThread); - t.Start(); - - int sleepInterval = 20; - int currentWait = 0; - int maxWait = 2000; - - while (line2 == null && currentWait < maxWait) { - Thread.Sleep(sleepInterval); - currentWait += sleepInterval; - } - - lineAvailableAtEnd = pythonConsole.IsLineAvailable; - } - } - - [Test] - public void FirstLineRead() - { - Assert.AreEqual("ABC", line1); - } - - [Test] - public void SecondLineRead() - { - Assert.AreEqual("DEF", line2); - } - - [Test] - public void LineAvailableBeforeEnterKeyPressed() - { - Assert.IsFalse(lineAvailableBeforeFirstEnterKey); - } - - [Test] - public void LineAvailableAfterEnterKeyPressed() - { - Assert.IsTrue(lineAvailableAfterFirstEnterKey); - } - - [Test] - public void LineAvailableAfterAllLinesRead() - { - Assert.IsFalse(lineAvailableAtEnd); - } - - void ReadLinesOnSeparateThread() - { - line1 = pythonConsole.ReadLine(0); - line2 = pythonConsole.ReadLine(0); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 8e670d7551..aae42c5325 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -102,21 +102,7 @@ - - - - - - - - - - - - - - diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsole.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsole.cs index 06559bfcb6..b0d75aca64 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsole.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsole.cs @@ -2,56 +2,21 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.Collections.Generic; using System.IO; -using System.Threading; -using System.Windows.Input; -using ICSharpCode.AvalonEdit.CodeCompletion; using ICSharpCode.Scripting; -using Microsoft.Scripting.Hosting; using Microsoft.Scripting.Hosting.Shell; namespace ICSharpCode.RubyBinding { - public class RubyConsole : IConsole, IDisposable, IMemberProvider, IScriptingConsole + public class RubyConsole : ScriptingConsole, IConsole { - IScriptingConsoleTextEditor textEditor; - int lineReceivedEventIndex = 0; // The index into the waitHandles array where the lineReceivedEvent is stored. - ManualResetEvent lineReceivedEvent = new ManualResetEvent(false); - ManualResetEvent disposedEvent = new ManualResetEvent(false); - WaitHandle[] waitHandles; - int promptLength; - bool firstPromptDisplayed; - string savedSendLineText; - CommandLineHistory commandLineHistory = new CommandLineHistory(); - - protected List unreadLines = new List(); - public RubyConsole(IScriptingConsoleTextEditor textEditor) + : base(textEditor) { - waitHandles = new WaitHandle[] {lineReceivedEvent, disposedEvent}; - - this.textEditor = textEditor; - textEditor.PreviewKeyDown += ProcessPreviewKeyDown; } - public CommandLine CommandLine { get; set; } - - public void Dispose() - { - disposedEvent.Set(); - } + public CommandLine CommandLine { get; set; } - /// - /// Gets the text that is yet to be processed from the console. This is the text that is being - /// typed in by the user who has not yet pressed the enter key. - /// - public string GetCurrentLine() - { - string fullLine = GetLastTextEditorLine(); - return fullLine.Substring(promptLength); - } - public TextWriter Output { get { return null; } set { } @@ -62,285 +27,14 @@ namespace ICSharpCode.RubyBinding set { } } - public string ReadLine(int autoIndentSize) - { - string indent = GetIndent(autoIndentSize); - if (autoIndentSize > 0) { - Write(indent, Style.Prompt); - } - - string line = ReadLineFromTextEditor(); - if (line != null) { - return indent + line; - } - return null; - } - - string GetIndent(int autoIndentSize) - { - return String.Empty.PadLeft(autoIndentSize); - } - public void Write(string text, Style style) { - 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; - } + base.Write(text, (ScriptingStyle)style); } public void WriteLine(string text, Style style) { - Write(text + Environment.NewLine, style); - } - - /// - /// Writes an empty line to the console. - /// - public void WriteLine() - { - Write(Environment.NewLine, Style.Out); - } - - /// - /// Indicates whether there is a line already read by the console and waiting to be processed. - /// - public bool IsLineAvailable { - get { - lock (unreadLines) { - return (unreadLines.Count > 0); - } - } - } - - /// - /// Gets the member names of the specified item. - /// - public IList GetMemberNames(string name) - { - return CommandLine.GetMemberNames(name); - } - - public IList GetGlobals(string name) - { - return CommandLine.GetGlobals(name); - } - - /// - /// Processes characters entered into the text editor by the user. - /// - void ProcessPreviewKeyDown(object source, ConsoleTextEditorKeyEventArgs e) - { - Key keyPressed = e.Key; - e.Handled = HandleKeyDown(keyPressed); - } - - bool HandleKeyDown(Key keyPressed) - { - if (textEditor.IsCompletionWindowDisplayed) { - return false; - } - - if (IsInReadOnlyRegion) { - switch (keyPressed) { - case Key.Left: - case Key.Right: - case Key.Up: - case Key.Down: - return false; - default: - return true; - } - } - - switch (keyPressed) { - case Key.Back: - return !CanBackspace; - case Key.Home: - MoveToHomePosition(); - return true; - case Key.Down: - MoveToNextCommandLine(); - return true; - case Key.Up: - MoveToPreviousCommandLine(); - return true; - } - - if (keyPressed == Key.Return) { - OnEnterKeyPressed(); - } - - if (keyPressed == Key.OemPeriod) { - ShowCompletionWindow(); - } - return false; - } - - string ReadLineFromTextEditor() - { - int result = WaitHandle.WaitAny(waitHandles); - if (result == lineReceivedEventIndex) { - lock (unreadLines) { - string line = unreadLines[0]; - unreadLines.RemoveAt(0); - if (unreadLines.Count == 0) { - lineReceivedEvent.Reset(); - } - return line; - } - } - return null; - } - - /// - /// Move cursor to the end of the line before retrieving the line. - /// - void OnEnterKeyPressed() - { - 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); - } - - string GetLastTextEditorLine() - { - return textEditor.GetLine(textEditor.TotalLines - 1); - } - - /// - /// Returns true if the cursor is in a readonly text editor region. - /// - bool IsInReadOnlyRegion { - get { return IsCurrentLineReadOnly || IsInPrompt; } - } - - /// - /// Only the last line in the text editor is not read only. - /// - bool IsCurrentLineReadOnly { - get { return textEditor.Line < (textEditor.TotalLines - 1); } - } - - /// - /// Determines whether the current cursor position is in a prompt. - /// - bool IsInPrompt { - get { return (textEditor.Column - promptLength) < 0; } - } - - /// - /// Returns true if the user can backspace at the current cursor position. - /// - bool CanBackspace { - get { - int cursorIndex = textEditor.Column - promptLength; - int selectionStartIndex = textEditor.SelectionStart - promptLength; - return (cursorIndex > 0) && (selectionStartIndex > 0); - } - } - - /// - /// The home position is at the start of the line after the prompt. - /// - void MoveToHomePosition() - { - textEditor.Column = promptLength; - } - - /// - /// Shows the previous command line in the command line history. - /// - void MoveToPreviousCommandLine() - { - if (commandLineHistory.MovePrevious()) { - ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); - } - } - - /// - /// Shows the next command line in the command line history. - /// - void MoveToNextCommandLine() - { - if (commandLineHistory.MoveNext()) { - ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); - } - } - - /// - /// Replaces the current line text after the prompt with the specified text. - /// - void ReplaceCurrentLineTextAfterPrompt(string text) - { - string currentLine = GetCurrentLine(); - textEditor.Replace(promptLength, currentLine.Length, text); - - // Put cursor at end. - textEditor.Column = promptLength + text.Length; - } - - void ShowCompletionWindow() - { - ScriptingConsoleCompletionDataProvider completionProvider = new ScriptingConsoleCompletionDataProvider(this); - textEditor.ShowCompletionWindow(completionProvider); - } - - public void SendLine(string text) - { - using (ILock linesLock = CreateLock(unreadLines)) { - unreadLines.Add(text); - } - FireLineReceivedEvent(); - MoveCursorToEndOfLastTextEditorLine(); - WriteLineIfFirstPromptHasBeenDisplayed(text); - } - - protected virtual ILock CreateLock(List lines) - { - return new StringListLock(lines); - } - - protected virtual void FireLineReceivedEvent() - { - lineReceivedEvent.Set(); - } - - void WriteLineIfFirstPromptHasBeenDisplayed(string text) - { - if (firstPromptDisplayed) { - WriteLine(text, Style.Out); - } else { - savedSendLineText = text; - } + base.WriteLine(text, (ScriptingStyle)style); } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/DisposedRubyConsoleTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/DisposedRubyConsoleTestFixture.cs deleted file mode 100644 index 3d55c67155..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/DisposedRubyConsoleTestFixture.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.RubyBinding; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - /// - /// Tests the disposing of the RubyConsole. - /// - [TestFixture] - public class DisposedRubyConsoleTestFixture : RubyConsoleTestsBase - { - [Test] - public void RubyConsoleImplementsIDisposable() - { - base.CreateRubyConsole(); - Assert.IsNotNull(TestableRubyConsole as IDisposable); - } - - [Test] - public void ReadLineReturnsNullWhenConsoleDisposed() - { - base.CreateRubyConsole(); - TestableRubyConsole.Dispose(); - Assert.IsNull(TestableRubyConsole.ReadLine(0)); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs deleted file mode 100644 index 0d720e5ee0..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Windows.Input; - -using ICSharpCode.RubyBinding; -using ICSharpCode.SharpDevelop; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - /// - /// Pressing the up key closes the completion window when it should not. This fixture tests - /// that the up, down, home and end key do not close this window. - /// - [TestFixture] - public class KeysPressedWhenCompletionWindowOpenTestFixture : RubyConsoleTestsBase - { - string prompt = ">>> "; - - [SetUp] - public void Init() - { - base.CreateRubyConsole(); - TestableRubyConsole.Write(prompt, Style.Prompt); - - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestableRubyConsole.Write(prompt, Style.Prompt); - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.OemPeriod); - } - - [Test] - public void ShowCompletionWindowIsCalled() - { - Assert.IsTrue(MockConsoleTextEditor.IsShowCompletionWindowCalled); - } - - [Test] - public void UpKeyDoesNothing() - { - Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up)); - } - - [Test] - public void DownKeyDoesNothing() - { - Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCodeCompletionTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCodeCompletionTestFixture.cs deleted file mode 100644 index 6b3cb6b3ea..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCodeCompletionTestFixture.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Threading; -using System.Windows.Input; - -using ICSharpCode.RubyBinding; -using ICSharpCode.Scripting; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - /// - /// When the dot character is typed in after an object the code completion window should appear. - /// - [TestFixture] - public class RubyConsoleCodeCompletionTestFixture : RubyConsoleTestsBase - { - string prompt = ">>> "; - bool showCompletionWindowCalledBeforeDotTypedIn; - - [TestFixtureSetUp] - public void SetUpFixture() - { - base.CreateRubyConsole(); - TestableRubyConsole.WriteLine(prompt, Style.Prompt); - - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - showCompletionWindowCalledBeforeDotTypedIn = MockConsoleTextEditor.IsShowCompletionWindowCalled; - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.OemPeriod); - } - - [Test] - public void ShowCompletionWindowCalled() - { - Assert.IsTrue(MockConsoleTextEditor.IsShowCompletionWindowCalled); - } - - [Test] - public void ShowCompletionWindowNotCalledBeforeDotTypedIn() - { - Assert.IsFalse(showCompletionWindowCalledBeforeDotTypedIn); - } - - [Test] - public void ScriptingConsoleCompletionDataProviderPassedToShowCompletionWindowMethod() - { - Assert.IsInstanceOf(typeof(ScriptingConsoleCompletionDataProvider), MockConsoleTextEditor.CompletionProviderPassedToShowCompletionWindow); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleEnterKeyTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleEnterKeyTestFixture.cs deleted file mode 100644 index f239e7fa95..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleEnterKeyTestFixture.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Windows.Input; -using Microsoft.Scripting.Hosting.Shell; -using ICSharpCode.RubyBinding; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - /// - /// Tests that pressing the enter key in the middle of a typed in line in the Ruby console - /// leaves the line alone and moves the cursor to the next line. By default the text editor - /// will break the line and move the last part to the second line. - /// - [TestFixture] - public class RubyConsoleEnterKeyTestFixture : RubyConsoleTestsBase - { - string prompt = ">>> "; - - [SetUp] - public void Init() - { - base.CreateRubyConsole(); - TestableRubyConsole.Write(prompt, Style.Prompt); - } - - [Test] - public void EnterKeyDoesNotBreakUpExistingLine() - { - 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", MockConsoleTextEditor.Text); - } - - [Test] - public void PreviousLineIsReadOnlyAfterEnterPressed() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestableRubyConsole.Write(prompt, Style.Prompt); - - // Move up a line with cursor. - MockConsoleTextEditor.Line = 0; - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C); - - string expectedText = - ">>> AB\r\n" + - ">>> "; - Assert.AreEqual(expectedText, MockConsoleTextEditor.Text); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleHomeKeyTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleHomeKeyTestFixture.cs deleted file mode 100644 index ddf64bf233..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleHomeKeyTestFixture.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using System.Windows.Input; -using System.Threading; -using Microsoft.Scripting.Hosting.Shell; -using ICSharpCode.RubyBinding; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - /// - /// The Home Key should return the user to the start of the line after the prompt. - /// - [TestFixture] - public class RubyConsoleHomeKeyTestFixture : RubyConsoleTestsBase - { - string prompt = ">>> "; - - [SetUp] - public void Init() - { - base.CreateRubyConsole(); - TestableRubyConsole.Write(prompt, Style.Prompt); - } - - [Test] - public void HomeKeyPressedWhenNoUserTextInConsole() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Home); - - int expectedColumn = prompt.Length; - Assert.AreEqual(expectedColumn, MockConsoleTextEditor.Column); - } - - [Test] - public void HomeKeyPressedWhenTextInConsole() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Home); - - int expectedColumn = prompt.Length; - Assert.AreEqual(expectedColumn, MockConsoleTextEditor.Column); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleReadOnlyRegionsTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleReadOnlyRegionsTestFixture.cs deleted file mode 100644 index 01d5c8881c..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleReadOnlyRegionsTestFixture.cs +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Windows.Input; - -using ICSharpCode.RubyBinding; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - /// - /// Tests that the user cannot type into read-only regions of the text editor. The - /// RubyConsole itself restricts typing itself by handling key press events. - /// - [TestFixture] - public class RubyConsoleReadOnlyRegionsTestFixture : RubyConsoleTestsBase - { - string prompt = ">>> "; - - [SetUp] - public void Init() - { - base.CreateRubyConsole(); - TestableRubyConsole.Write(prompt, Style.Prompt); - } - - [Test] - public void MakeCurrentContentReadOnlyIsCalled() - { - Assert.IsTrue(MockConsoleTextEditor.IsMakeCurrentContentReadOnlyCalled); - } - - [Test] - public void LeftArrowThenInsertNewCharacterInsertsText() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C); - - Assert.AreEqual("ACB", TestableRubyConsole.GetCurrentLine()); - } - - [Test] - public void MoveOneCharacterIntoPromptTypingShouldBePrevented() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - - Assert.AreEqual(String.Empty, TestableRubyConsole.GetCurrentLine()); - } - - [Test] - public void MoveOneCharacterIntoPromptAndBackspaceKeyShouldNotRemoveAnything() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - - Assert.AreEqual("A", TestableRubyConsole.GetCurrentLine()); - Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text); - } - - [Test] - public void MoveTwoCharactersIntoPromptAndBackspaceKeyShouldNotRemoveAnything() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - - Assert.AreEqual("A", TestableRubyConsole.GetCurrentLine()); - Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text); - } - - [Test] - public void SelectLastCharacterOfPromptThenPressingTheBackspaceKeyShouldNotRemoveAnything() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.SelectionStart = prompt.Length - 1; - MockConsoleTextEditor.SelectionLength = 2; - MockConsoleTextEditor.Column += 2; - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - - Assert.AreEqual("A", TestableRubyConsole.GetCurrentLine()); - Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text); - } - - [Test] - public void CanMoveIntoPromptRegionWithLeftCursorKey() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); - Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left)); - } - - [Test] - public void CanMoveOutOfPromptRegionWithRightCursorKey() - { - MockConsoleTextEditor.Column = 0; - Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Right)); - } - - [Test] - public void CanMoveOutOfPromptRegionWithUpCursorKey() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestableRubyConsole.Write(prompt, Style.Prompt); - MockConsoleTextEditor.Column = 0; - Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up)); - } - - [Test] - public void CanMoveInReadOnlyRegionWithDownCursorKey() - { - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestableRubyConsole.Write(prompt, Style.Prompt); - MockConsoleTextEditor.Column = 0; - MockConsoleTextEditor.Line = 0; - Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); - } - - [Test] - public void BackspaceKeyPressedIgnoredIfLineIsEmpty() - { - Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back)); - } - - [Test] - public void BackspaceOnPreviousLine() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - - TestableRubyConsole.Write(prompt, Style.Prompt); - - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C); - - // Move up a line with cursor. - MockConsoleTextEditor.Line = 0; - - Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back)); - Assert.AreEqual("C", TestableRubyConsole.GetCurrentLine()); - } - - [Test] - public void CanBackspaceFirstCharacterOnLine() - { - MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - MockConsoleTextEditor.Column = 5; - MockConsoleTextEditor.SelectionStart = 5; - MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - - Assert.AreEqual(String.Empty, TestableRubyConsole.GetCurrentLine()); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleSendLineTests.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleSendLineTests.cs deleted file mode 100644 index c0238753d0..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleSendLineTests.cs +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; -using ICSharpCode.NRefactory; -using ICSharpCode.RubyBinding; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - [TestFixture] - public class RubyConsoleSendLineTests : RubyConsoleTestsBase - { - [Test] - public void SendLine_NoUnreadLines_AddsLineToUnreadLines() - { - SendLineToConsole("test"); - string[] unreadLines = TestableRubyConsole.GetUnreadLines(); - - string[] expectedUnreadlines = new string[] {"test"}; - - Assert.AreEqual(expectedUnreadlines, unreadLines); - } - - void SendLineToConsole(string text) - { - base.CreateRubyConsole(); - WritePrompt(); - TestableRubyConsole.SendLine(text); - } - - void WritePrompt() - { - TestableRubyConsole.Write(">>> ", Style.Prompt); - } - - [Test] - public void SendLine_NoUnreadLines_CreatesLockForPreviousLines() - { - SendLineToConsole("test"); - List lines = TestableRubyConsole.LockCreated.Lines; - List expectedLines = TestableRubyConsole.GetUnreadLinesList(); - - Assert.AreEqual(expectedLines, lines); - } - - [Test] - public void SendLine_NoUnreadLines_LockForPreviousLinesIsDisposed() - { - SendLineToConsole("test"); - bool disposed = TestableRubyConsole.LockCreated.IsDisposed; - - Assert.IsTrue(disposed); - } - - [Test] - public void SendLine_NoUnreadLines_LineNotAddedBeforeLockCreated() - { - SendLineToConsole("test"); - int count = TestableRubyConsole.LockCreated.UnreadLineCountWhenLockCreated; - int expectedCount = 0; - - Assert.AreEqual(expectedCount, count); - } - - [Test] - public void SendLine_NoUnreadLines_LineAddedBeforeLockDisposed() - { - SendLineToConsole("test"); - int count = TestableRubyConsole.LockCreated.UnreadLineCountWhenLockDisposed; - int expectedCount = 1; - - Assert.AreEqual(expectedCount, count); - } - - [Test] - public void SendLine_NoUnreadLines_LineReceivedEventIsFired() - { - SendLineToConsole("test"); - bool fired = TestableRubyConsole.IsLineReceivedEventFired; - Assert.IsTrue(fired); - } - - [Test] - public void SendLine_NoUnreadLines_LineReceivedEventAfterLineAddedToUnreadLines() - { - SendLineToConsole("test"); - int count = TestableRubyConsole.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.CreateRubyConsole(); - WritePrompt(); - MockConsoleTextEditor.Text = - ">>> first\r\n" + - ">>> second\r\n" + - ">>> "; - - MockConsoleTextEditor.Line = 0; - MockConsoleTextEditor.Column = 0; - TestableRubyConsole.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.CreateRubyConsole(); - TestableRubyConsole.SendLine("test"); - string text = MockConsoleTextEditor.TextPassedToWrite; - - Assert.IsNull(text); - } - - [Test] - public void Write_SendLineCalledButNoPromptWritten_WritesOutSavedSendLineText() - { - base.CreateRubyConsole(); - TestableRubyConsole.SendLine("test"); - - TestableRubyConsole.Write(">>> ", Style.Prompt); - string text = MockConsoleTextEditor.Text; - - string expectedText = - ">>> test\r\n"; - Assert.AreEqual(expectedText, text); - } - - [Test] - public void Write_CalledTwiceAfterSendLineCalledButNoPromptWritten_WritesOutSavedSendLineTextOnlyOnce() - { - base.CreateRubyConsole(); - TestableRubyConsole.SendLine("test"); - - TestableRubyConsole.Write(">>> ", Style.Prompt); - TestableRubyConsole.Write(">>> ", Style.Prompt); - - string text = MockConsoleTextEditor.Text; - - string expectedText = - ">>> test\r\n" + - ">>> "; - Assert.AreEqual(expectedText, text); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleTestsBase.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleTestsBase.cs deleted file mode 100644 index 6c67803521..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleTestsBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using ICSharpCode.RubyBinding; -using ICSharpCode.Scripting.Tests.Utils; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - public class RubyConsoleTestsBase - { - public MockConsoleTextEditor MockConsoleTextEditor; - public TestableRubyConsole TestableRubyConsole; - - public void CreateRubyConsole() - { - TestableRubyConsole = new TestableRubyConsole(); - MockConsoleTextEditor = TestableRubyConsole.MockConsoleTextEditor; - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleWriteTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleWriteTestFixture.cs deleted file mode 100644 index dafed14687..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleWriteTestFixture.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Drawing; -using ICSharpCode.RubyBinding; -using Microsoft.Scripting.Hosting.Shell; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Console -{ - /// - /// Tests that the RubyConsole Write method correctly update the text editor. - /// - [TestFixture] - public class RubyConsoleWriteTestFixture : RubyConsoleTestsBase - { - [SetUp] - public void Init() - { - base.CreateRubyConsole(); - } - - [Test] - public void WriteLine() - { - TestableRubyConsole.WriteLine(); - Assert.AreEqual(Environment.NewLine, MockConsoleTextEditor.Text); - } - - [Test] - public void WriteLineWithText() - { - TestableRubyConsole.WriteLine("test", Style.Out); - Assert.AreEqual("test" + Environment.NewLine, MockConsoleTextEditor.Text); - } - - [Test] - public void TwoWrites() - { - TestableRubyConsole.Write("a", Style.Out); - TestableRubyConsole.Write("b", Style.Out); - Assert.AreEqual("ab", MockConsoleTextEditor.Text); - } - - [Test] - public void DoesNotHasLinesWaitingToBeRead() - { - Assert.IsFalse(TestableRubyConsole.IsLineAvailable); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj index 681f7b8d66..e19dcc35a1 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj @@ -72,21 +72,7 @@ - - - - - - - - - - - - - - diff --git a/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj b/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj index 5e4ebb7ca5..53aa562d09 100644 --- a/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj +++ b/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj @@ -79,6 +79,7 @@ + @@ -88,6 +89,7 @@ + diff --git a/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs new file mode 100644 index 0000000000..cdeba40f42 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs @@ -0,0 +1,334 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Windows.Input; + +using ICSharpCode.Scripting; + +namespace ICSharpCode.Scripting +{ + public class ScriptingConsole : IDisposable, IMemberProvider, IScriptingConsole + { + IScriptingConsoleTextEditor textEditor; + int lineReceivedEventIndex = 0; // The index into the waitHandles array where the lineReceivedEvent is stored. + ManualResetEvent lineReceivedEvent = new ManualResetEvent(false); + ManualResetEvent disposedEvent = new ManualResetEvent(false); + WaitHandle[] waitHandles; + int promptLength; + bool firstPromptDisplayed; + string savedSendLineText; + CommandLineHistory commandLineHistory = new CommandLineHistory(); + + protected List unreadLines = new List(); + + public ScriptingConsole(IScriptingConsoleTextEditor textEditor) + { + waitHandles = new WaitHandle[] {lineReceivedEvent, disposedEvent}; + + this.textEditor = textEditor; + textEditor.PreviewKeyDown += ProcessPreviewKeyDown; + } + + public void Dispose() + { + disposedEvent.Set(); + } + + /// + /// Returns the next line typed in by the console user. If no line is available this method + /// will block. + /// + public string ReadLine(int autoIndentSize) + { + string indent = GetIndent(autoIndentSize); + if (autoIndentSize > 0) { + Write(indent, ScriptingStyle.Prompt); + } + + string line = ReadLineFromTextEditor(); + if (line != null) { + return indent + line; + } + return null; + } + + string GetIndent(int autoIndentSize) + { + return String.Empty.PadLeft(autoIndentSize); + } + + /// + /// Writes text to the console. + /// + public void Write(string text, ScriptingStyle style) + { + textEditor.Write(text); + if (style == ScriptingStyle.Prompt) { + WriteSavedLineTextAfterFirstPrompt(text); + promptLength = text.Length; + textEditor.MakeCurrentContentReadOnly(); + } + } + + void WriteSavedLineTextAfterFirstPrompt(string promptText) + { + firstPromptDisplayed = true; + if (savedSendLineText != null) { + textEditor.Write(savedSendLineText + "\r\n"); + savedSendLineText = null; + } + } + + /// + /// Writes text followed by a newline to the console. + /// + public void WriteLine(string text, ScriptingStyle style) + { + Write(text + Environment.NewLine, style); + } + + /// + /// Writes an empty line to the console. + /// + public void WriteLine() + { + Write(Environment.NewLine, ScriptingStyle.Out); + } + + /// + /// Indicates whether there is a line already read by the console and waiting to be processed. + /// + public bool IsLineAvailable { + get { + lock (unreadLines) { + return (unreadLines.Count > 0); + } + } + } + + /// + /// Gets the text that is yet to be processed from the console. This is the text that is being + /// typed in by the user who has not yet pressed the enter key. + /// + public string GetCurrentLine() + { + string fullLine = GetLastTextEditorLine(); + return fullLine.Substring(promptLength); + } + + string GetLastTextEditorLine() + { + return textEditor.GetLine(textEditor.TotalLines - 1); + } + + string ReadLineFromTextEditor() + { + int result = WaitHandle.WaitAny(waitHandles); + if (result == lineReceivedEventIndex) { + lock (unreadLines) { + string line = unreadLines[0]; + unreadLines.RemoveAt(0); + if (unreadLines.Count == 0) { + lineReceivedEvent.Reset(); + } + return line; + } + } + return null; + } + + /// + /// Processes characters entered into the text editor by the user. + /// + void ProcessPreviewKeyDown(object source, ConsoleTextEditorKeyEventArgs e) + { + Key keyPressed = e.Key; + e.Handled = HandleKeyDown(keyPressed); + } + + bool HandleKeyDown(Key keyPressed) + { + if (textEditor.IsCompletionWindowDisplayed) { + return false; + } + + if (IsInReadOnlyRegion) { + switch (keyPressed) { + case Key.Left: + case Key.Right: + case Key.Up: + case Key.Down: + return false; + default: + return true; + } + } + + switch (keyPressed) { + case Key.Back: + return !CanBackspace; + case Key.Home: + MoveToHomePosition(); + return true; + case Key.Down: + MoveToNextCommandLine(); + return true; + case Key.Up: + MoveToPreviousCommandLine(); + return true; + } + + if (keyPressed == Key.Return) { + OnEnterKeyPressed(); + } + + if (keyPressed == Key.OemPeriod) { + ShowCompletionWindow(); + } + return false; + } + + void OnEnterKeyPressed() + { + 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); + } + + /// + /// Returns true if the cursor is in a readonly text editor region. + /// + bool IsInReadOnlyRegion { + get { return IsCurrentLineReadOnly || IsInPrompt; } + } + + /// + /// Only the last line in the text editor is not read only. + /// + bool IsCurrentLineReadOnly { + get { return textEditor.Line < (textEditor.TotalLines - 1); } + } + + /// + /// Determines whether the current cursor position is in a prompt. + /// + bool IsInPrompt { + get { return (textEditor.Column - promptLength) < 0; } + } + + /// + /// Returns true if the user can backspace at the current cursor position. + /// + bool CanBackspace { + get { + int cursorIndex = textEditor.Column - promptLength; + int selectionStartIndex = textEditor.SelectionStart - promptLength; + return (cursorIndex > 0) && (selectionStartIndex > 0); + } + } + + void ShowCompletionWindow() + { + ScriptingConsoleCompletionDataProvider completionProvider = new ScriptingConsoleCompletionDataProvider(this); + textEditor.ShowCompletionWindow(completionProvider); + } + + /// + /// The home position is at the start of the line after the prompt. + /// + void MoveToHomePosition() + { + textEditor.Column = promptLength; + } + + /// + /// Shows the previous command line in the command line history. + /// + void MoveToPreviousCommandLine() + { + if (commandLineHistory.MovePrevious()) { + ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); + } + } + + /// + /// Shows the next command line in the command line history. + /// + void MoveToNextCommandLine() + { + if (commandLineHistory.MoveNext()) { + ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); + } + } + + /// + /// Replaces the current line text after the prompt with the specified text. + /// + void ReplaceCurrentLineTextAfterPrompt(string text) + { + string currentLine = GetCurrentLine(); + textEditor.Replace(promptLength, currentLine.Length, text); + + // 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 lines) + { + return new StringListLock(lines); + } + + protected virtual void FireLineReceivedEvent() + { + lineReceivedEvent.Set(); + } + + void WriteLineIfFirstPromptHasBeenDisplayed(string text) + { + if (firstPromptDisplayed) { + WriteLine(text, ScriptingStyle.Out); + } else { + savedSendLineText = text; + } + } + + public virtual IList GetMemberNames(string name) + { + return new string[0]; + } + + public virtual IList GetGlobals(string name) + { + return new string[0]; + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingStyle.cs b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingStyle.cs new file mode 100644 index 0000000000..c8852765fb --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingStyle.cs @@ -0,0 +1,19 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.Scripting +{ + public enum ScriptingStyle + { + Prompt, + Out, + Error, + Warning + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/Console/DisposedScriptingConsoleTests.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/DisposedScriptingConsoleTests.cs new file mode 100644 index 0000000000..9b506e5c45 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/DisposedScriptingConsoleTests.cs @@ -0,0 +1,29 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.Scripting; +using NUnit.Framework; +using ICSharpCode.Scripting.Tests.Utils; + +namespace ICSharpCode.Scripting.Tests.Console +{ + [TestFixture] + public class DisposedScriptingConsoleTests : ScriptingConsoleTestsBase + { + [Test] + public void ConsoleImplementsIDisposable() + { + base.CreateConsole(); + Assert.IsNotNull(TestableScriptingConsole as IDisposable); + } + + [Test] + public void ReadLineReturnsNullWhenConsoleDisposed() + { + base.CreateConsole(); + TestableScriptingConsole.Dispose(); + Assert.IsNull(TestableScriptingConsole.ReadLine(0)); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/KeysPressedWhenCompletionWindowOpenTests.cs similarity index 60% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/KeysPressedWhenCompletionWindowOpenTests.cs index 2f45c86464..844b244158 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/KeysPressedWhenCompletionWindowOpenTests.cs @@ -1,35 +1,38 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +// +// +// +// +// $Revision$ +// using System; using System.Windows.Input; -using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; using ICSharpCode.SharpDevelop; -using Microsoft.Scripting.Hosting.Shell; using NUnit.Framework; -using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// /// Pressing the up key closes the completion window when it should not. This fixture tests /// that the up, down, home and end key do not close this window. /// [TestFixture] - public class KeysPressedWhenCompletionWindowOpenTestFixture : PythonConsoleTestsBase + public class KeysPressedWhenCompletionWindowOpenTests : ScriptingConsoleTestsBase { string prompt = ">>> "; [SetUp] public void Init() { - base.CreatePythonConsole(); - TestablePythonConsole.Write(prompt, Style.Prompt); + base.CreateConsole(); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestablePythonConsole.Write(prompt, Style.Prompt); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.OemPeriod); } @@ -44,6 +47,6 @@ namespace PythonBinding.Tests.Console public void DownKeyDoesNothing() { Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); - } + } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCodeCompletionTests.cs similarity index 82% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCodeCompletionTests.cs index ceeabc0ab8..0d7243c9b9 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCodeCompletionTests.cs @@ -6,19 +6,17 @@ using System.Collections.Generic; using System.Threading; using System.Windows.Input; -using ICSharpCode.PythonBinding; using ICSharpCode.Scripting; -using Microsoft.Scripting.Hosting.Shell; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; -using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// /// When the dot character is typed in after an object the code completion window should appear. /// [TestFixture] - public class PythonConsoleCodeCompletionTestFixture : PythonConsoleTestsBase + public class ScriptingConsoleCodeCompletionTests : ScriptingConsoleTestsBase { string prompt = ">>> "; bool showCompletionWindowCalledBeforeDotTypedIn; @@ -26,8 +24,8 @@ namespace PythonBinding.Tests.Console [TestFixtureSetUp] public void SetUpFixture() { - base.CreatePythonConsole(); - TestablePythonConsole.WriteLine(prompt, Style.Prompt); + base.CreateConsole(); + TestableScriptingConsole.WriteLine(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); showCompletionWindowCalledBeforeDotTypedIn = MockConsoleTextEditor.IsShowCompletionWindowCalled; diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCommandLineHistoryTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCommandLineHistoryTests.cs similarity index 76% rename from src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCommandLineHistoryTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCommandLineHistoryTests.cs index 96a055b238..cda6ffa4f9 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCommandLineHistoryTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCommandLineHistoryTests.cs @@ -4,36 +4,33 @@ using System; using System.Windows.Input; -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; -using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; -using RubyBinding.Tests.Utils; -namespace RubyBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// - /// Tests the RubyConsole's command line history. + /// Tests the ScriptingConsole's command line history. /// [TestFixture] - public class RubyConsoleCommandLineHistoryTestFixture : RubyConsoleTestsBase + public class ScriptingConsoleCommandLineHistoryTestFixture : ScriptingConsoleTestsBase { string prompt = ">>> "; [SetUp] public void Init() { - base.CreateRubyConsole(); - TestableRubyConsole.Write(prompt, Style.Prompt); + base.CreateConsole(); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestableRubyConsole.Write(prompt, Style.Prompt); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestableRubyConsole.Write(prompt, Style.Prompt); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); } [Test] @@ -46,7 +43,7 @@ namespace RubyBinding.Tests.Console public void CurrentLineAfterUpArrowKeyPressed() { MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up); - Assert.AreEqual("BC", TestableRubyConsole.GetCurrentLine()); + Assert.AreEqual("BC", TestableScriptingConsole.GetCurrentLine()); } [Test] @@ -60,7 +57,7 @@ namespace RubyBinding.Tests.Console public void TextAfterUpArrowKeyPressedTwiceThenDownArrowKey() { UpArrowKeyPressedTwiceThenDownArrowKey(); - Assert.AreEqual("BC", TestableRubyConsole.GetCurrentLine()); + Assert.AreEqual("BC", TestableScriptingConsole.GetCurrentLine()); } [Test] diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCurrentLineTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCurrentLineTests.cs similarity index 51% rename from src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCurrentLineTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCurrentLineTests.cs index cad5f896d0..a95acc2312 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleCurrentLineTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleCurrentLineTests.cs @@ -3,45 +3,41 @@ using System; using System.Windows.Input; -using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting; using ICSharpCode.Scripting.Tests.Utils; -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; using NUnit.Framework; -using RubyBinding.Tests.Utils; -namespace RubyBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// - /// Tests the RubyConsole's GetCurrentLine method. + /// Tests the ScriptingConsole's GetCurrentLine method. /// [TestFixture] - public class RubyConsoleCurrentLineTestFixture + public class ScriptingConsoleCurrentLineTests { - TestableRubyConsole rubyConsole; + TestableScriptingConsole console; MockConsoleTextEditor textEditor; string prompt = ">>> "; [SetUp] public void Init() { - rubyConsole = new TestableRubyConsole(); - rubyConsole.Write(prompt, Style.Prompt); - textEditor = rubyConsole.MockConsoleTextEditor; + console = new TestableScriptingConsole(); + console.Write(prompt, ScriptingStyle.Prompt); + textEditor = console.MockConsoleTextEditor; } [Test] public void CurrentLineIsEmpty() { - Assert.AreEqual(String.Empty, rubyConsole.GetCurrentLine()); + Assert.AreEqual(String.Empty, console.GetCurrentLine()); } [Test] public void SingleCharacterAddedToTextEditor() { textEditor.RaisePreviewKeyDownEvent(Key.A); - Assert.AreEqual("A", rubyConsole.GetCurrentLine()); + Assert.AreEqual("A", console.GetCurrentLine()); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleEnterKeyTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleEnterKeyTests.cs similarity index 80% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleEnterKeyTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleEnterKeyTests.cs index d42f83d571..181fb77c57 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleEnterKeyTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleEnterKeyTests.cs @@ -3,28 +3,27 @@ using System; using System.Windows.Input; -using Microsoft.Scripting.Hosting.Shell; -using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting; using NUnit.Framework; -using PythonBinding.Tests.Utils; +using ICSharpCode.Scripting.Tests.Utils; -namespace PythonBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// - /// Tests that pressing the enter key in the middle of a typed in line in the python console + /// Tests that pressing the enter key in the middle of a typed in line in the console /// leaves the line alone and moves the cursor to the next line. By default the text editor /// will break the line and move the last part to the second line. /// [TestFixture] - public class PythonConsoleEnterKeyTestFixture : PythonConsoleTestsBase + public class ScriptingConsoleEnterKeyTests : ScriptingConsoleTestsBase { string prompt = ">>> "; [SetUp] public void Init() { - base.CreatePythonConsole(); - TestablePythonConsole.Write(prompt, Style.Prompt); + base.CreateConsole(); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); } public void EnterKeyDoesNotBreakUpExistingLine() @@ -44,7 +43,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestablePythonConsole.Write(prompt, Style.Prompt); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); // Move up a line with cursor. MockConsoleTextEditor.Line = 0; diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHomeKeyTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleHomeKeyTests.cs similarity index 78% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHomeKeyTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleHomeKeyTests.cs index 4b23ce4261..f5d7d8de29 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHomeKeyTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleHomeKeyTests.cs @@ -5,26 +5,25 @@ using System; using System.Collections.Generic; using System.Windows.Input; using System.Threading; -using Microsoft.Scripting.Hosting.Shell; -using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting; using NUnit.Framework; -using PythonBinding.Tests.Utils; +using ICSharpCode.Scripting.Tests.Utils; -namespace PythonBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// /// The Home Key should return the user to the start of the line after the prompt. /// [TestFixture] - public class PythonConsoleHomeKeyTestFixture : PythonConsoleTestsBase + public class ScriptingConsoleHomeKeyTests : ScriptingConsoleTestsBase { string prompt = ">>> "; [SetUp] public void Init() { - base.CreatePythonConsole(); - TestablePythonConsole.Write(prompt, Style.Prompt); + base.CreateConsole(); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); } [Test] diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadOnlyRegionsTests.cs similarity index 80% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadOnlyRegionsTests.cs index ebf7151c3c..3184f5637c 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadOnlyRegionsTests.cs @@ -4,27 +4,26 @@ using System; using System.Windows.Input; -using ICSharpCode.PythonBinding; -using Microsoft.Scripting.Hosting.Shell; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; -using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// /// Tests that the user cannot type into read-only regions of the text editor. The - /// PythonConsole itself restricts typing itself by handling key press events. + /// ScriptingConsole itself restricts typing itself by handling key press events. /// [TestFixture] - public class PythonConsoleReadOnlyRegionsTestFixture : PythonConsoleTestsBase + public class ScriptingConsoleReadOnlyRegionsTests : ScriptingConsoleTestsBase { string prompt = ">>> "; [SetUp] public void Init() { - base.CreatePythonConsole(); - TestablePythonConsole.Write(prompt, Style.Prompt); + base.CreateConsole(); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); } [Test] @@ -41,7 +40,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C); - Assert.AreEqual("ACB", TestablePythonConsole.GetCurrentLine()); + Assert.AreEqual("ACB", TestableScriptingConsole.GetCurrentLine()); } [Test] @@ -50,7 +49,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); - Assert.AreEqual(String.Empty, TestablePythonConsole.GetCurrentLine()); + Assert.AreEqual(String.Empty, TestableScriptingConsole.GetCurrentLine()); } [Test] @@ -60,7 +59,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - Assert.AreEqual("A", TestablePythonConsole.GetCurrentLine()); + Assert.AreEqual("A", TestableScriptingConsole.GetCurrentLine()); Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text); } @@ -72,7 +71,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Left); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - Assert.AreEqual("A", TestablePythonConsole.GetCurrentLine()); + Assert.AreEqual("A", TestableScriptingConsole.GetCurrentLine()); Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text); } @@ -85,7 +84,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.Column += 2; MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - Assert.AreEqual("A", TestablePythonConsole.GetCurrentLine()); + Assert.AreEqual("A", TestableScriptingConsole.GetCurrentLine()); Assert.AreEqual(prompt + "A", MockConsoleTextEditor.Text); } @@ -107,7 +106,7 @@ namespace PythonBinding.Tests.Console public void CanMoveOutOfPromptRegionWithUpCursorKey() { MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestablePythonConsole.Write(prompt, Style.Prompt); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.Column = 0; Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Up)); } @@ -116,7 +115,7 @@ namespace PythonBinding.Tests.Console public void CanMoveInReadOnlyRegionWithDownCursorKey() { MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestablePythonConsole.Write(prompt, Style.Prompt); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.Column = 0; MockConsoleTextEditor.Line = 0; Assert.IsFalse(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Down)); @@ -135,7 +134,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); - TestablePythonConsole.Write(prompt, Style.Prompt); + TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt); MockConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C); @@ -143,7 +142,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.Line = 0; Assert.IsTrue(MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back)); - Assert.AreEqual("C", TestablePythonConsole.GetCurrentLine()); + Assert.AreEqual("C", TestableScriptingConsole.GetCurrentLine()); } [Test] @@ -154,7 +153,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.SelectionStart = 5; MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Back); - Assert.AreEqual(String.Empty, TestablePythonConsole.GetCurrentLine()); + Assert.AreEqual(String.Empty, TestableScriptingConsole.GetCurrentLine()); } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleReadTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.cs similarity index 88% rename from src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleReadTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.cs index 061877a5c8..e4b0f86af8 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleReadTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.cs @@ -5,18 +5,17 @@ using System; using System.Threading; using System.Windows.Input; -using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting; using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; -using RubyBinding.Tests.Utils; -namespace RubyBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// - /// Tests the RubyConsole ReadLine method. + /// Tests the ScriptingConsole ReadLine method. /// [TestFixture] - public class RubyConsoleReadTestFixture : RubyConsoleTestsBase + public class ScriptingConsoleReadTests : ScriptingConsoleTestsBase { int initialAutoIndentSize = 4; string readLine; @@ -27,7 +26,7 @@ namespace RubyBinding.Tests.Console [TestFixtureSetUp] public void Init() { - base.CreateRubyConsole(); + base.CreateConsole(); autoIndentSize = initialAutoIndentSize; Thread thread = new Thread(ReadLineFromConsoleOnDifferentThread); @@ -55,7 +54,7 @@ namespace RubyBinding.Tests.Console [TestFixtureTearDown] public void TearDown() { - TestableRubyConsole.Dispose(); + TestableScriptingConsole.Dispose(); } [Test] @@ -81,7 +80,7 @@ namespace RubyBinding.Tests.Console [Test] public void NoTextWrittenWhenAutoIndentSizeIsZero() { - TestableRubyConsole console = new TestableRubyConsole(); + TestableScriptingConsole console = new TestableScriptingConsole(); MockConsoleTextEditor textEditor = console.MockConsoleTextEditor; textEditor.RaisePreviewKeyDownEvent(Key.A); textEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); @@ -112,7 +111,7 @@ namespace RubyBinding.Tests.Console void ReadLineFromConsoleOnDifferentThread() { System.Console.WriteLine("Reading on different thread"); - readLine = TestableRubyConsole.ReadLine(autoIndentSize); + readLine = TestableScriptingConsole.ReadLine(autoIndentSize); System.Console.WriteLine("Finished reading on different thread"); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleSendLineTests.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs similarity index 71% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleSendLineTests.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs index 6c47d8be29..1c76cbc83f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleSendLineTests.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs @@ -4,21 +4,20 @@ using System; using System.Collections.Generic; using ICSharpCode.NRefactory; -using ICSharpCode.PythonBinding; -using Microsoft.Scripting.Hosting.Shell; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; -using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { [TestFixture] - public class PythonConsoleSendLineTests : PythonConsoleTestsBase + public class ScriptingConsoleSendLineTests : ScriptingConsoleTestsBase { [Test] public void SendLine_NoUnreadLines_AddsLineToUnreadLines() { SendLineToConsole("test"); - string[] unreadLines = TestablePythonConsole.GetUnreadLines(); + string[] unreadLines = TestableScriptingConsole.GetUnreadLines(); string[] expectedUnreadlines = new string[] {"test"}; @@ -27,22 +26,22 @@ namespace PythonBinding.Tests.Console void SendLineToConsole(string text) { - base.CreatePythonConsole(); + base.CreateConsole(); WritePrompt(); - TestablePythonConsole.SendLine(text); + TestableScriptingConsole.SendLine(text); } void WritePrompt() { - TestablePythonConsole.Write(">>> ", Style.Prompt); + TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt); } [Test] public void SendLine_NoUnreadLines_CreatesLockForPreviousLines() { SendLineToConsole("test"); - List lines = TestablePythonConsole.LockCreated.Lines; - List expectedLines = TestablePythonConsole.GetUnreadLinesList(); + List lines = TestableScriptingConsole.LockCreated.Lines; + List expectedLines = TestableScriptingConsole.GetUnreadLinesList(); Assert.AreEqual(expectedLines, lines); } @@ -51,7 +50,7 @@ namespace PythonBinding.Tests.Console public void SendLine_NoUnreadLines_LockForPreviousLinesIsDisposed() { SendLineToConsole("test"); - bool disposed = TestablePythonConsole.LockCreated.IsDisposed; + bool disposed = TestableScriptingConsole.LockCreated.IsDisposed; Assert.IsTrue(disposed); } @@ -60,7 +59,7 @@ namespace PythonBinding.Tests.Console public void SendLine_NoUnreadLines_LineNotAddedBeforeLockCreated() { SendLineToConsole("test"); - int count = TestablePythonConsole.LockCreated.UnreadLineCountWhenLockCreated; + int count = TestableScriptingConsole.LockCreated.UnreadLineCountWhenLockCreated; int expectedCount = 0; Assert.AreEqual(expectedCount, count); @@ -70,7 +69,7 @@ namespace PythonBinding.Tests.Console public void SendLine_NoUnreadLines_LineAddedBeforeLockDisposed() { SendLineToConsole("test"); - int count = TestablePythonConsole.LockCreated.UnreadLineCountWhenLockDisposed; + int count = TestableScriptingConsole.LockCreated.UnreadLineCountWhenLockDisposed; int expectedCount = 1; Assert.AreEqual(expectedCount, count); @@ -80,7 +79,7 @@ namespace PythonBinding.Tests.Console public void SendLine_NoUnreadLines_LineReceivedEventIsFired() { SendLineToConsole("test"); - bool fired = TestablePythonConsole.IsLineReceivedEventFired; + bool fired = TestableScriptingConsole.IsLineReceivedEventFired; Assert.IsTrue(fired); } @@ -88,7 +87,7 @@ namespace PythonBinding.Tests.Console public void SendLine_NoUnreadLines_LineReceivedEventAfterLineAddedToUnreadLines() { SendLineToConsole("test"); - int count = TestablePythonConsole.UnreadLineCountWhenLineReceivedEventFired; + int count = TestableScriptingConsole.UnreadLineCountWhenLineReceivedEventFired; int expectedCount = 1; Assert.AreEqual(expectedCount, count); } @@ -106,7 +105,7 @@ namespace PythonBinding.Tests.Console [Test] public void SendLine_TwoLinesInConsoleTextEditorCursorOnFirstLine_CursorMovedToEndOfLastLineBeforeTextWritten() { - base.CreatePythonConsole(); + base.CreateConsole(); WritePrompt(); MockConsoleTextEditor.Text = ">>> first\r\n" + @@ -115,7 +114,7 @@ namespace PythonBinding.Tests.Console MockConsoleTextEditor.Line = 0; MockConsoleTextEditor.Column = 0; - TestablePythonConsole.SendLine("test"); + TestableScriptingConsole.SendLine("test"); int expectedLine = 2; int expectedColumn = 4; @@ -129,8 +128,8 @@ namespace PythonBinding.Tests.Console [Test] public void SendLine_NoUnreadLines_NoTextWrittenToConsoleTextEditorBeforeFirstPromptIsWritten() { - base.CreatePythonConsole(); - TestablePythonConsole.SendLine("test"); + base.CreateConsole(); + TestableScriptingConsole.SendLine("test"); string text = MockConsoleTextEditor.TextPassedToWrite; Assert.IsNull(text); @@ -139,10 +138,10 @@ namespace PythonBinding.Tests.Console [Test] public void Write_SendLineCalledButNoPromptWritten_WritesOutSavedSendLineText() { - base.CreatePythonConsole(); - TestablePythonConsole.SendLine("test"); + base.CreateConsole(); + TestableScriptingConsole.SendLine("test"); - TestablePythonConsole.Write(">>> ", Style.Prompt); + TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt); string text = MockConsoleTextEditor.Text; string expectedText = @@ -153,11 +152,11 @@ namespace PythonBinding.Tests.Console [Test] public void Write_CalledTwiceAfterSendLineCalledButNoPromptWritten_WritesOutSavedSendLineTextOnlyOnce() { - base.CreatePythonConsole(); - TestablePythonConsole.SendLine("test"); + base.CreateConsole(); + TestableScriptingConsole.SendLine("test"); - TestablePythonConsole.Write(">>> ", Style.Prompt); - TestablePythonConsole.Write(">>> ", Style.Prompt); + TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt); + TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt); string text = MockConsoleTextEditor.Text; diff --git a/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs new file mode 100644 index 0000000000..d7d8b96610 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs @@ -0,0 +1,21 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; + +namespace ICSharpCode.Scripting.Tests.Console +{ + public class ScriptingConsoleTestsBase + { + public MockConsoleTextEditor MockConsoleTextEditor; + public TestableScriptingConsole TestableScriptingConsole; + + public void CreateConsole() + { + TestableScriptingConsole = new TestableScriptingConsole(); + MockConsoleTextEditor = TestableScriptingConsole.MockConsoleTextEditor; + } + } +} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleUnreadLinesTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleUnreadLinesTests.cs similarity index 55% rename from src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleUnreadLinesTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleUnreadLinesTests.cs index 4b7aff37b5..3c9ae51a84 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleUnreadLinesTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleUnreadLinesTests.cs @@ -4,39 +4,35 @@ using System; using System.Windows.Input; -using ICSharpCode.RubyBinding; -using IronRuby.Hosting; -using IronRuby.Runtime; -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; -using RubyBinding.Tests.Utils; -namespace RubyBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// - /// Tests the RubyConsole's GetUnreadLines method. + /// Tests the ScriptingConsole's GetUnreadLines method. /// [TestFixture] - public class RubyConsoleUnreadLinesTestFixture : RubyConsoleTestsBase + public class ScriptingConsoleUnreadLinesTests : ScriptingConsoleTestsBase { [SetUp] public void Init() { - base.CreateRubyConsole(); + base.CreateConsole(); } [Test] public void NoUnreadLinesAtStart() { - Assert.AreEqual(0, TestableRubyConsole.GetUnreadLines().Length); + int length = TestableScriptingConsole.GetUnreadLines().Length; + Assert.AreEqual(0, length); } [Test] public void HasUnreadLines() { - Assert.IsFalse(TestableRubyConsole.IsLineAvailable); + Assert.IsFalse(TestableScriptingConsole.IsLineAvailable); } [Test] @@ -45,11 +41,11 @@ namespace RubyBinding.Tests.Console MockConsoleTextEditor.RaisePreviewKeyDownEvent(System.Windows.Input.Key.A); MockConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(System.Windows.Input.Key.Enter); - string[] lines = TestableRubyConsole.GetUnreadLines(); + string[] lines = TestableScriptingConsole.GetUnreadLines(); string[] expectedLines = new string[] {"A"}; Assert.AreEqual(expectedLines, lines); - Assert.IsTrue(TestableRubyConsole.IsLineAvailable); + Assert.IsTrue(TestableScriptingConsole.IsLineAvailable); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleWriteTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleWriteTests.cs similarity index 51% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleWriteTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleWriteTests.cs index ee503816a9..4aea543e64 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleWriteTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleWriteTests.cs @@ -3,52 +3,52 @@ using System; using System.Drawing; -using ICSharpCode.PythonBinding; -using Microsoft.Scripting.Hosting.Shell; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; -using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// - /// Tests that the PythonConsole Write method correctly update the text editor. + /// Tests that the ScriptingConsole Write method correctly update the text editor. /// [TestFixture] - public class PythonConsoleWriteTestFixture : PythonConsoleTestsBase + public class ScriptingConsoleWriteTestFixture : ScriptingConsoleTestsBase { [SetUp] public void Init() { - base.CreatePythonConsole(); + base.CreateConsole(); MockConsoleTextEditor.Text = String.Empty; } [Test] public void WriteLine() { - TestablePythonConsole.WriteLine(); + TestableScriptingConsole.WriteLine(); Assert.AreEqual(Environment.NewLine, MockConsoleTextEditor.Text); } [Test] public void WriteLineWithText() { - TestablePythonConsole.WriteLine("test", Style.Out); - Assert.AreEqual("test" + Environment.NewLine, MockConsoleTextEditor.Text); + TestableScriptingConsole.WriteLine("test", ScriptingStyle.Out); + string expectedText = "test" + Environment.NewLine; + Assert.AreEqual(expectedText, MockConsoleTextEditor.Text); } [Test] public void TwoWrites() { - TestablePythonConsole.Write("a", Style.Out); - TestablePythonConsole.Write("b", Style.Out); + TestableScriptingConsole.Write("a", ScriptingStyle.Out); + TestableScriptingConsole.Write("b", ScriptingStyle.Out); Assert.AreEqual("ab", MockConsoleTextEditor.Text); } [Test] public void DoesNotHasLinesWaitingToBeRead() { - Assert.IsFalse(TestablePythonConsole.IsLineAvailable); + Assert.IsFalse(TestableScriptingConsole.IsLineAvailable); } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/TwoRubyConsoleLinesWaitingTestFixture.cs b/src/AddIns/BackendBindings/Scripting/Test/Console/TwoConsoleLinesWaitingTests.cs similarity index 70% rename from src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/TwoRubyConsoleLinesWaitingTestFixture.cs rename to src/AddIns/BackendBindings/Scripting/Test/Console/TwoConsoleLinesWaitingTests.cs index e4dc244424..c043ae5d13 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/TwoRubyConsoleLinesWaitingTestFixture.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Console/TwoConsoleLinesWaitingTests.cs @@ -3,29 +3,22 @@ using System; using System.Threading; -using ICSharpCode.RubyBinding; using ICSharpCode.Scripting.Tests.Utils; -using IronRuby.Hosting; -using IronRuby.Runtime; -using Microsoft.Scripting; -using Microsoft.Scripting.Hosting; -using Microsoft.Scripting.Hosting.Shell; using NUnit.Framework; -using RubyBinding.Tests.Utils; using Input = System.Windows.Input; -namespace RubyBinding.Tests.Console +namespace ICSharpCode.Scripting.Tests.Console { /// - /// Ensures that both lines of text can be read from the Ruby console if they are written + /// Ensures that both lines of text can be read from the console if they are written /// before ReadLine is called. /// [TestFixture] - public class TwoRubyConsoleLinesWaitingTestFixture + public class TwoConsoleLinesWaitingTests { string line1; string line2; - TestableRubyConsole rubyConsole; + TestableScriptingConsole scriptingConsole; bool lineAvailableBeforeFirstEnterKey; bool lineAvailableAfterFirstEnterKey; bool lineAvailableAtEnd; @@ -33,15 +26,15 @@ namespace RubyBinding.Tests.Console [TestFixtureSetUp] public void SetUpFixture() { - using (rubyConsole = new TestableRubyConsole()) { - MockConsoleTextEditor textEditor = rubyConsole.MockConsoleTextEditor; + using (scriptingConsole = new TestableScriptingConsole()) { + MockConsoleTextEditor textEditor = scriptingConsole.MockConsoleTextEditor; textEditor.RaisePreviewKeyDownEvent(Input.Key.A); textEditor.RaisePreviewKeyDownEvent(Input.Key.B); textEditor.RaisePreviewKeyDownEvent(Input.Key.C); - lineAvailableBeforeFirstEnterKey = rubyConsole.IsLineAvailable; + lineAvailableBeforeFirstEnterKey = scriptingConsole.IsLineAvailable; textEditor.RaisePreviewKeyDownEventForDialogKey(Input.Key.Enter); - lineAvailableAfterFirstEnterKey = rubyConsole.IsLineAvailable; - + lineAvailableAfterFirstEnterKey = scriptingConsole.IsLineAvailable; + textEditor.RaisePreviewKeyDownEvent(Input.Key.D); textEditor.RaisePreviewKeyDownEvent(Input.Key.E); textEditor.RaisePreviewKeyDownEvent(Input.Key.F); @@ -59,7 +52,7 @@ namespace RubyBinding.Tests.Console currentWait += sleepInterval; } - lineAvailableAtEnd = rubyConsole.IsLineAvailable; + lineAvailableAtEnd = scriptingConsole.IsLineAvailable; } } @@ -95,8 +88,8 @@ namespace RubyBinding.Tests.Console void ReadLinesOnSeparateThread() { - line1 = rubyConsole.ReadLine(0); - line2 = rubyConsole.ReadLine(0); + line1 = scriptingConsole.ReadLine(0); + line2 = scriptingConsole.ReadLine(0); } } } diff --git a/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj b/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj index d5cb130b6a..e685022f5c 100644 --- a/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj +++ b/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj @@ -69,13 +69,27 @@ + + + + + + + + + + + + + + @@ -141,6 +155,7 @@ + diff --git a/src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingConsole.cs b/src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingConsole.cs new file mode 100644 index 0000000000..40d1f05158 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingConsole.cs @@ -0,0 +1,51 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; + +namespace ICSharpCode.Scripting.Tests.Utils +{ + public class TestableScriptingConsole : ScriptingConsole + { + public MockConsoleTextEditor MockConsoleTextEditor; + public FakeLock LockCreated; + public bool IsLineReceivedEventFired; + public int UnreadLineCountWhenLineReceivedEventFired = -1; + + public TestableScriptingConsole() + : this(new MockConsoleTextEditor()) + { + } + + TestableScriptingConsole(IScriptingConsoleTextEditor consoleTextEditor) + : base(consoleTextEditor) + { + MockConsoleTextEditor = (MockConsoleTextEditor)consoleTextEditor; + } + + public List GetUnreadLinesList() + { + return base.unreadLines; + } + + public string[] GetUnreadLines() + { + return base.unreadLines.ToArray(); + } + + protected override ILock CreateLock(List lines) + { + LockCreated = new FakeLock(lines); + return LockCreated; + } + + protected override void FireLineReceivedEvent() + { + IsLineReceivedEventFired = true; + UnreadLineCountWhenLineReceivedEventFired = LockCreated.Lines.Count; + } + } +}