39 changed files with 624 additions and 1928 deletions
@ -1,32 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the disposing of the PythonConsole.
|
||||
/// </summary>
|
||||
[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)); |
||||
} |
||||
} |
||||
} |
@ -1,87 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PythonConsole's command line history.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -1,47 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PythonConsole's GetCurrentLine method.
|
||||
/// </summary>
|
||||
[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()); |
||||
} |
||||
} |
||||
} |
@ -1,119 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PythonConsole ReadLine method.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Should return false for any character that should be handled by the text editor itself.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RaiseKeyPressEventReturnedFalse() |
||||
{ |
||||
Assert.IsFalse(raiseKeyPressEvent); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Should return false for any character that should be handled by the text editor itself.
|
||||
/// </summary>
|
||||
[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"); |
||||
} |
||||
} |
||||
} |
@ -1,22 +0,0 @@
@@ -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; |
||||
} |
||||
} |
||||
} |
@ -1,55 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PythonConsole's GetUnreadLines method.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -1,102 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Ensures that both lines of text can be read from the python console if they are written
|
||||
/// before ReadLine is called.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -1,32 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the disposing of the RubyConsole.
|
||||
/// </summary>
|
||||
[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)); |
||||
} |
||||
} |
||||
} |
@ -1,55 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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)); |
||||
} |
||||
} |
||||
} |
@ -1,55 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// When the dot character is typed in after an object the code completion window should appear.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -1,60 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -1,49 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// The Home Key should return the user to the start of the line after the prompt.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -1,160 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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()); |
||||
} |
||||
} |
||||
} |
@ -1,170 +0,0 @@
@@ -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<string> lines = TestableRubyConsole.LockCreated.Lines; |
||||
List<string> 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); |
||||
} |
||||
} |
||||
} |
@ -1,22 +0,0 @@
@@ -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; |
||||
} |
||||
} |
||||
} |
@ -1,53 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the RubyConsole Write method correctly update the text editor.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,334 @@
@@ -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<string> unreadLines = new List<string>(); |
||||
|
||||
public ScriptingConsole(IScriptingConsoleTextEditor textEditor) |
||||
{ |
||||
waitHandles = new WaitHandle[] {lineReceivedEvent, disposedEvent}; |
||||
|
||||
this.textEditor = textEditor; |
||||
textEditor.PreviewKeyDown += ProcessPreviewKeyDown; |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
disposedEvent.Set(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the next line typed in by the console user. If no line is available this method
|
||||
/// will block.
|
||||
/// </summary>
|
||||
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); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes text to the console.
|
||||
/// </summary>
|
||||
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; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes text followed by a newline to the console.
|
||||
/// </summary>
|
||||
public void WriteLine(string text, ScriptingStyle style) |
||||
{ |
||||
Write(text + Environment.NewLine, style); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes an empty line to the console.
|
||||
/// </summary>
|
||||
public void WriteLine() |
||||
{ |
||||
Write(Environment.NewLine, ScriptingStyle.Out); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Indicates whether there is a line already read by the console and waiting to be processed.
|
||||
/// </summary>
|
||||
public bool IsLineAvailable { |
||||
get { |
||||
lock (unreadLines) { |
||||
return (unreadLines.Count > 0); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Processes characters entered into the text editor by the user.
|
||||
/// </summary>
|
||||
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); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns true if the cursor is in a readonly text editor region.
|
||||
/// </summary>
|
||||
bool IsInReadOnlyRegion { |
||||
get { return IsCurrentLineReadOnly || IsInPrompt; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Only the last line in the text editor is not read only.
|
||||
/// </summary>
|
||||
bool IsCurrentLineReadOnly { |
||||
get { return textEditor.Line < (textEditor.TotalLines - 1); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the current cursor position is in a prompt.
|
||||
/// </summary>
|
||||
bool IsInPrompt { |
||||
get { return (textEditor.Column - promptLength) < 0; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns true if the user can backspace at the current cursor position.
|
||||
/// </summary>
|
||||
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); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The home position is at the start of the line after the prompt.
|
||||
/// </summary>
|
||||
void MoveToHomePosition() |
||||
{ |
||||
textEditor.Column = promptLength; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the previous command line in the command line history.
|
||||
/// </summary>
|
||||
void MoveToPreviousCommandLine() |
||||
{ |
||||
if (commandLineHistory.MovePrevious()) { |
||||
ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the next command line in the command line history.
|
||||
/// </summary>
|
||||
void MoveToNextCommandLine() |
||||
{ |
||||
if (commandLineHistory.MoveNext()) { |
||||
ReplaceCurrentLineTextAfterPrompt(commandLineHistory.Current); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Replaces the current line text after the prompt with the specified text.
|
||||
/// </summary>
|
||||
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<string> 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<string> GetMemberNames(string name) |
||||
{ |
||||
return new string[0]; |
||||
} |
||||
|
||||
public virtual IList<string> GetGlobals(string name) |
||||
{ |
||||
return new string[0]; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Scripting |
||||
{ |
||||
public enum ScriptingStyle |
||||
{ |
||||
Prompt, |
||||
Out, |
||||
Error, |
||||
Warning |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -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)); |
||||
} |
||||
} |
||||
} |
@ -1,35 +1,38 @@
@@ -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)
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.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 |
||||
{ |
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
@ -0,0 +1,21 @@
@@ -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; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -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<string> GetUnreadLinesList() |
||||
{ |
||||
return base.unreadLines; |
||||
} |
||||
|
||||
public string[] GetUnreadLines() |
||||
{ |
||||
return base.unreadLines.ToArray(); |
||||
} |
||||
|
||||
protected override ILock CreateLock(List<string> lines) |
||||
{ |
||||
LockCreated = new FakeLock(lines); |
||||
return LockCreated; |
||||
} |
||||
|
||||
protected override void FireLineReceivedEvent() |
||||
{ |
||||
IsLineReceivedEventFired = true; |
||||
UnreadLineCountWhenLineReceivedEventFired = LockCreated.Lines.Count; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue