Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3627 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
12 changed files with 475 additions and 1 deletions
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
/// <summary>
|
||||
/// Stores the command line history for the PythonConsole.
|
||||
/// </summary>
|
||||
public class CommandLineHistory |
||||
{ |
||||
List<string> lines = new List<string>(); |
||||
int position = -1; |
||||
|
||||
public CommandLineHistory() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the command line to the history.
|
||||
/// </summary>
|
||||
public void Add(string line) |
||||
{ |
||||
if (!String.IsNullOrEmpty(line)) { |
||||
int index = lines.Count - 1; |
||||
if (index >= 0) { |
||||
if (lines[index] != line) { |
||||
lines.Add(line); |
||||
} |
||||
} else { |
||||
lines.Add(line); |
||||
} |
||||
} |
||||
position = lines.Count; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current command line. By default this will be the last command line entered.
|
||||
/// </summary>
|
||||
public string Current { |
||||
get { |
||||
if ((position >= 0) && (position < lines.Count)) { |
||||
return lines[position]; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Moves to the next command line.
|
||||
/// </summary>
|
||||
public bool MoveNext() |
||||
{ |
||||
if (position < lines.Count) { |
||||
++position; |
||||
} |
||||
return position < lines.Count; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Moves to the previous command line.
|
||||
/// </summary>
|
||||
public bool MovePrevious() |
||||
{ |
||||
if (position >= 0) { |
||||
--position; |
||||
} |
||||
return position >= 0; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Console |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the CommandLineHistory class.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class CommandLineHistoryTestFixture |
||||
{ |
||||
CommandLineHistory history; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
history = new CommandLineHistory(); |
||||
history.Add("a"); |
||||
history.Add("b"); |
||||
history.Add("c"); |
||||
} |
||||
|
||||
[Test] |
||||
public void LastCommandLineIsNull() |
||||
{ |
||||
Assert.IsNull(history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void MovePreviousOnce() |
||||
{ |
||||
Assert.IsTrue(history.MovePrevious()); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentAfterMovePrevious() |
||||
{ |
||||
history.MovePrevious(); |
||||
Assert.AreEqual("c", history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddLineAfterMovePrevious() |
||||
{ |
||||
history.MovePrevious(); |
||||
history.MovePrevious(); |
||||
history.Add("d"); |
||||
|
||||
Assert.IsNull(history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyLineIgnored() |
||||
{ |
||||
history.Add(String.Empty); |
||||
history.MovePrevious(); |
||||
Assert.AreEqual("c", history.Current); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Console |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the CommandLineHistory class.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class EmptyCommandLineHistoryTestFixture |
||||
{ |
||||
CommandLineHistory history; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
history = new CommandLineHistory(); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentCommandLineIsNull() |
||||
{ |
||||
Assert.IsNull(history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void MoveNextReturnsFalse() |
||||
{ |
||||
Assert.IsFalse(history.MoveNext()); |
||||
} |
||||
|
||||
[Test] |
||||
public void MovePreviousReturnsFalse() |
||||
{ |
||||
Assert.IsFalse(history.MovePrevious()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Console |
||||
{ |
||||
[TestFixture] |
||||
public class OneItemCommandLineHistoryTestFixture |
||||
{ |
||||
CommandLineHistory history; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
history = new CommandLineHistory(); |
||||
history.Add("a"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Current() |
||||
{ |
||||
Assert.AreEqual(null, history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void MovePrevious() |
||||
{ |
||||
Assert.IsTrue(history.MovePrevious()); |
||||
} |
||||
|
||||
[Test] |
||||
public void MovePreviousTwice() |
||||
{ |
||||
history.MovePrevious(); |
||||
Assert.IsFalse(history.MovePrevious()); |
||||
} |
||||
|
||||
[Test] |
||||
public void MoveNextFails() |
||||
{ |
||||
Assert.IsFalse(history.MoveNext()); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentAfterMovePrevious() |
||||
{ |
||||
history.MovePrevious(); |
||||
Assert.AreEqual("a", history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentAfterMovePreviousTwice() |
||||
{ |
||||
history.MovePrevious(); |
||||
history.MovePrevious(); |
||||
Assert.IsNull(history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void MovePreviousThenBack() |
||||
{ |
||||
history.MovePrevious(); |
||||
Assert.IsFalse(history.MoveNext()); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentAfterMovePreviousThenBack() |
||||
{ |
||||
history.MovePrevious(); |
||||
history.MoveNext(); |
||||
Assert.IsNull(history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentAfterMovePreviousTwiceThenBack() |
||||
{ |
||||
history.MovePrevious(); |
||||
history.MovePrevious(); |
||||
history.MoveNext(); |
||||
Assert.AreEqual("a", history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void MoveNextTwiceThenBack() |
||||
{ |
||||
history.MoveNext(); |
||||
history.MoveNext(); |
||||
Assert.IsTrue(history.MovePrevious()); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentAfterMoveNextTwiceThenBack() |
||||
{ |
||||
MoveNextTwiceThenBack(); |
||||
Assert.AreEqual("a", history.Current); |
||||
} |
||||
|
||||
[Test] |
||||
public void IgnoreSameCommandLineEntered() |
||||
{ |
||||
history.Add("a"); |
||||
history.MovePrevious(); |
||||
Assert.IsFalse(history.MovePrevious()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
|
||||
using Microsoft.Scripting; |
||||
using Microsoft.Scripting.Hosting; |
||||
using Microsoft.Scripting.Hosting.Shell; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Console |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PythonConsole's command line history.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class PythonConsoleCommandLineHistoryTestFixture |
||||
{ |
||||
PythonConsole pythonConsole; |
||||
MockTextEditor textEditor; |
||||
string prompt = ">>> "; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
textEditor = new MockTextEditor(); |
||||
pythonConsole = new PythonConsole(textEditor, null); |
||||
pythonConsole.Write(prompt, Style.Prompt); |
||||
|
||||
textEditor.RaiseKeyPressEvent('a'); |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Enter); |
||||
pythonConsole.Write(prompt, Style.Prompt); |
||||
textEditor.RaiseKeyPressEvent('b'); |
||||
textEditor.RaiseKeyPressEvent('c'); |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Enter); |
||||
pythonConsole.Write(prompt, Style.Prompt); |
||||
} |
||||
|
||||
[Test] |
||||
public void UpArrowKeyPressed() |
||||
{ |
||||
Assert.IsTrue(textEditor.RaiseDialogKeyPressEvent(Keys.Up)); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurrentLineAfterUpArrowKeyPressed() |
||||
{ |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Up); |
||||
Assert.AreEqual("bc", pythonConsole.GetCurrentLine()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorCursorIsAtEndOfLineAfterUpArrowKeyPressed() |
||||
{ |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Up); |
||||
Assert.AreEqual(prompt.Length + 2, textEditor.Column); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextAfterUpArrowKeyPressedTwiceThenDownArrowKey() |
||||
{ |
||||
UpArrowKeyPressedTwiceThenDownArrowKey(); |
||||
Assert.AreEqual("bc", pythonConsole.GetCurrentLine()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorCursorAfterUpArrowKeyPressedTwice() |
||||
{ |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Up); |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Up); |
||||
Assert.AreEqual(prompt.Length + 1, textEditor.Column); |
||||
} |
||||
|
||||
[Test] |
||||
public void DownArrowKeyHandled() |
||||
{ |
||||
Assert.IsTrue(textEditor.RaiseDialogKeyPressEvent(Keys.Down)); |
||||
} |
||||
|
||||
void UpArrowKeyPressedTwiceThenDownArrowKey() |
||||
{ |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Up); |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Up); |
||||
textEditor.RaiseDialogKeyPressEvent(Keys.Down); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue