Browse Source

Merge remote branch 'remotes/origin/4.0'

pull/15/head
mrward 15 years ago
parent
commit
5048f0302f
  1. 4
      src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsoleTextEditor.cs
  2. 4
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs
  3. 2
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleOutputStream.cs
  4. 11
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs
  5. 4
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleOutputStreamTests.cs
  6. 6
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.cs
  7. 27
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs
  8. 32
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs
  9. 19
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTextEditorTests.cs
  10. 12
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeConsoleTextEditor.cs
  11. 26
      src/AddIns/BackendBindings/Scripting/Test/Utils/Tests/MockConsoleTextEditorTests.cs

4
src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsoleTextEditor.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.Scripting
event ConsoleTextEditorKeyEventHandler PreviewKeyDown; event ConsoleTextEditorKeyEventHandler PreviewKeyDown;
/// <summary> /// <summary>
/// Inserts text at the current cursor location. /// Appends text to the end of the text editor.
/// </summary> /// </summary>
void Write(string text); void Append(string text);
/// <summary> /// <summary>
/// Replaces the text at the specified index on the current line with the specified text. /// Replaces the text at the specified index on the current line with the specified text.

4
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.Scripting
/// </summary> /// </summary>
public void Write(string text, ScriptingStyle style) public void Write(string text, ScriptingStyle style)
{ {
textEditor.Write(text); textEditor.Append(text);
if (style == ScriptingStyle.Prompt) { if (style == ScriptingStyle.Prompt) {
firstPromptDisplayed = true; firstPromptDisplayed = true;
promptLength = text.Length; promptLength = text.Length;
@ -84,7 +84,7 @@ namespace ICSharpCode.Scripting
{ {
if (textSent.HasLine) { if (textSent.HasLine) {
string line = textSent.RemoveFirstLine(); string line = textSent.RemoveFirstLine();
textEditor.Write(line); textEditor.Append(line);
} }
} }

2
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleOutputStream.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.Scripting
void ThreadSafeTextEditorWrite(string text) void ThreadSafeTextEditorWrite(string text)
{ {
if (dispatcher.CheckAccess()) { if (dispatcher.CheckAccess()) {
textEditor.Write(text); textEditor.Append(text);
} else { } else {
Action<string> action = ThreadSafeTextEditorWrite; Action<string> action = ThreadSafeTextEditorWrite;
dispatcher.Invoke(action, text); dispatcher.Invoke(action, text);

11
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs

@ -46,16 +46,9 @@ namespace ICSharpCode.Scripting
get { return customLineColour; } get { return customLineColour; }
} }
public void Write(string text) public void Append(string text)
{ {
TextLocation location = GetCurrentCursorLocation(); textEditor.AppendText(text);
int offset = textEditor.Document.GetOffset(location);
textEditor.Document.Insert(offset, text);
}
TextLocation GetCurrentCursorLocation()
{
return new TextLocation(Line + 1, Column + 1);
} }
public int Column { public int Column {

4
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleOutputStreamTests.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.Scripting.Tests.Console
byte[] bytes = UTF8Encoding.UTF8.GetBytes("test"); byte[] bytes = UTF8Encoding.UTF8.GetBytes("test");
stream.Write(bytes, 0, bytes.Length); stream.Write(bytes, 0, bytes.Length);
string text = textEditor.TextPassedToWrite; string text = textEditor.TextPassedToAppend;
string expectedText = "test"; string expectedText = "test";
Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedText, text);
@ -65,7 +65,7 @@ namespace ICSharpCode.Scripting.Tests.Console
byte[] bytes = UTF8Encoding.UTF8.GetBytes("0output1"); byte[] bytes = UTF8Encoding.UTF8.GetBytes("0output1");
stream.Write(bytes, 1, bytes.Length - 2); stream.Write(bytes, 1, bytes.Length - 2);
string text = textEditor.TextPassedToWrite; string text = textEditor.TextPassedToAppend;
string expectedText = "output"; string expectedText = "output";
Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedText, text);

6
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.ReadLine(indent); TestableScriptingConsole.ReadLine(indent);
string expectedText = " "; string expectedText = " ";
Assert.AreEqual(expectedText, FakeConsoleTextEditor.TextPassedToWrite); Assert.AreEqual(expectedText, FakeConsoleTextEditor.TextPassedToAppend);
} }
[Test] [Test]
@ -38,11 +38,11 @@ namespace ICSharpCode.Scripting.Tests.Console
FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A); FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter); FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
FakeConsoleTextEditor.IsWriteCalled = false; FakeConsoleTextEditor.IsAppendCalled = false;
TestableScriptingConsole.ReadLine(0); TestableScriptingConsole.ReadLine(0);
Assert.IsFalse(FakeConsoleTextEditor.IsWriteCalled); Assert.IsFalse(FakeConsoleTextEditor.IsAppendCalled);
} }
[Test] [Test]

27
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs

@ -52,41 +52,18 @@ namespace ICSharpCode.Scripting.Tests.Console
public void SendLine_NoUnreadLines_LineWrittenToConsoleTextEditor() public void SendLine_NoUnreadLines_LineWrittenToConsoleTextEditor()
{ {
SendLineToConsole("test"); SendLineToConsole("test");
string text = FakeConsoleTextEditor.TextPassedToWrite; string text = FakeConsoleTextEditor.TextPassedToAppend;
string expectedTextWritten = "test\r\n"; string expectedTextWritten = "test\r\n";
Assert.AreEqual(expectedTextWritten, text); Assert.AreEqual(expectedTextWritten, text);
} }
[Test]
public void SendLine_TwoLinesInConsoleTextEditorCursorOnFirstLine_CursorMovedToEndOfLastLineBeforeTextWritten()
{
base.CreateConsole();
WritePrompt();
FakeConsoleTextEditor.Text =
">>> first\r\n" +
">>> second\r\n" +
">>> ";
FakeConsoleTextEditor.Line = 0;
FakeConsoleTextEditor.Column = 0;
TestableScriptingConsole.SendLine("test");
int expectedLine = 2;
int expectedColumn = 4;
Location expectedLocation = new Location(expectedColumn, expectedLine);
Location location = FakeConsoleTextEditor.CursorLocationWhenWriteTextCalled;
Assert.AreEqual(expectedLocation, location);
}
[Test] [Test]
public void SendLine_NoUnreadLines_NoTextWrittenToConsoleTextEditorBeforeFirstPromptIsWritten() public void SendLine_NoUnreadLines_NoTextWrittenToConsoleTextEditorBeforeFirstPromptIsWritten()
{ {
base.CreateConsole(); base.CreateConsole();
TestableScriptingConsole.SendLine("test"); TestableScriptingConsole.SendLine("test");
string text = FakeConsoleTextEditor.TextPassedToWrite; string text = FakeConsoleTextEditor.TextPassedToAppend;
Assert.IsNull(text); Assert.IsNull(text);
} }

32
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.Scripting.Tests.Console
{ {
SendTextToConsole("test"); SendTextToConsole("test");
string text = base.FakeConsoleTextEditor.TextPassedToWrite; string text = base.FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "test"; string expectedText = "test";
Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedText, text);
} }
@ -29,32 +29,12 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.SendText(text); TestableScriptingConsole.SendText(text);
} }
[Test]
public void SendText_TextEditorHasTextAfterPrompt_CursorMovedToEndOfLastLineBeforeTextWritten()
{
base.CreateConsole();
WritePrompt();
FakeConsoleTextEditor.Text = ">>> first";
FakeConsoleTextEditor.Line = -1;
FakeConsoleTextEditor.Column = -1;
TestableScriptingConsole.SendText("test");
int expectedLine = 0;
int expectedColumn = 9;
Location expectedLocation = new Location(expectedColumn, expectedLine);
Location location = FakeConsoleTextEditor.CursorLocationWhenWriteTextCalled;
Assert.AreEqual(expectedLocation, location);
}
[Test] [Test]
public void SendText_FirstPromptNotYetWrittenToConsole_NoTextWrittenToConsoleTextEditor() public void SendText_FirstPromptNotYetWrittenToConsole_NoTextWrittenToConsoleTextEditor()
{ {
base.CreateConsole(); base.CreateConsole();
TestableScriptingConsole.SendText("test"); TestableScriptingConsole.SendText("test");
string text = FakeConsoleTextEditor.TextPassedToWrite; string text = FakeConsoleTextEditor.TextPassedToAppend;
Assert.IsNull(text); Assert.IsNull(text);
} }
@ -66,7 +46,7 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.SendText("test"); TestableScriptingConsole.SendText("test");
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt); TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
string text = FakeConsoleTextEditor.TextPassedToWrite; string text = FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "test"; string expectedText = "test";
Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedText, text);
@ -84,7 +64,7 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt); TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt); TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
string textPassedToWrite = FakeConsoleTextEditor.TextPassedToWrite; string textPassedToWrite = FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "second"; string expectedText = "second";
Assert.AreEqual(expectedText, textPassedToWrite); Assert.AreEqual(expectedText, textPassedToWrite);
@ -99,7 +79,7 @@ namespace ICSharpCode.Scripting.Tests.Console
SendTextToConsole(selectedText); SendTextToConsole(selectedText);
string text = base.FakeConsoleTextEditor.TextPassedToWrite; string text = base.FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "first\r\n"; string expectedText = "first\r\n";
Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedText, text);
} }
@ -114,7 +94,7 @@ namespace ICSharpCode.Scripting.Tests.Console
SendTextToConsole(selectedText); SendTextToConsole(selectedText);
WritePrompt(); WritePrompt();
string text = base.FakeConsoleTextEditor.TextPassedToWrite; string text = base.FakeConsoleTextEditor.TextPassedToAppend;
string expectedText = "second"; string expectedText = "second";
Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedText, text);
} }

19
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTextEditorTests.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.Scripting.Tests.Console
public void MakeCurrentContentReadOnly_OneLineOfTextInTextEditor_ExtendsReadOnlyRegionToEntireDocument() public void MakeCurrentContentReadOnly_OneLineOfTextInTextEditor_ExtendsReadOnlyRegionToEntireDocument()
{ {
avalonEditTextEditor.Text = String.Empty; avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc" + Environment.NewLine); consoleTextEditor.Append("abc" + Environment.NewLine);
consoleTextEditor.MakeCurrentContentReadOnly(); consoleTextEditor.MakeCurrentContentReadOnly();
IReadOnlySectionProvider readOnlySection = avalonEditTextEditor.TextArea.ReadOnlySectionProvider; IReadOnlySectionProvider readOnlySection = avalonEditTextEditor.TextArea.ReadOnlySectionProvider;
@ -47,10 +47,10 @@ namespace ICSharpCode.Scripting.Tests.Console
} }
[Test] [Test]
public void Write_TextEditorHasNoText_UpdatesTextEditor() public void Append_TextEditorHasNoText_UpdatesTextEditor()
{ {
avalonEditTextEditor.Text = String.Empty; avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc"); consoleTextEditor.Append("abc");
string text = avalonEditTextEditor.Text; string text = avalonEditTextEditor.Text;
string expectedText = "abc"; string expectedText = "abc";
@ -58,6 +58,19 @@ namespace ICSharpCode.Scripting.Tests.Console
Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedText, text);
} }
[Test]
public void Append_CursorNotAtEndOfText_TextIsWrittenAtEnd()
{
avalonEditTextEditor.Text = "abc";
avalonEditTextEditor.CaretOffset = 0;
consoleTextEditor.Append("d");
string text = avalonEditTextEditor.Text;
string expectedText = "abcd";
Assert.AreEqual(expectedText, text);
}
[Test] [Test]
public void Column_TextEditorColumnSetToThree_ZeroBasedConsoleTextEditorColumnPositionReturnsTwoWhichIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased() public void Column_TextEditorColumnSetToThree_ZeroBasedConsoleTextEditorColumnPositionReturnsTwoWhichIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased()
{ {

12
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeConsoleTextEditor.cs

@ -15,16 +15,15 @@ namespace ICSharpCode.Scripting.Tests.Utils
public class FakeConsoleTextEditor : IScriptingConsoleTextEditor public class FakeConsoleTextEditor : IScriptingConsoleTextEditor
{ {
public bool IsDisposed; public bool IsDisposed;
public bool IsWriteCalled; public bool IsAppendCalled;
public bool IsShowCompletionWindowCalled; public bool IsShowCompletionWindowCalled;
public bool IsMakeCurrentContentReadOnlyCalled; public bool IsMakeCurrentContentReadOnlyCalled;
public ScriptingConsoleCompletionDataProvider CompletionProviderPassedToShowCompletionWindow; public ScriptingConsoleCompletionDataProvider CompletionProviderPassedToShowCompletionWindow;
public string TextPassedToWrite; public string TextPassedToAppend;
public string TextPassedToReplace; public string TextPassedToReplace;
public int LengthPassedToReplace = -1; public int LengthPassedToReplace = -1;
public int IndexPassedToReplace = -1; public int IndexPassedToReplace = -1;
public Location CursorLocationWhenWriteTextCalled;
public bool IsColumnChangedBeforeTextWritten; public bool IsColumnChangedBeforeTextWritten;
public StringBuilder PreviousLines = new StringBuilder(); public StringBuilder PreviousLines = new StringBuilder();
@ -42,11 +41,10 @@ namespace ICSharpCode.Scripting.Tests.Utils
IsDisposed = true; IsDisposed = true;
} }
public void Write(string text) public void Append(string text)
{ {
TextPassedToWrite = text; TextPassedToAppend = text;
CursorLocationWhenWriteTextCalled = new Location(Column, Line); IsAppendCalled = true;
IsWriteCalled = true;
LineBuilder.Append(text); LineBuilder.Append(text);
Column += text.Length; Column += text.Length;
} }

26
src/AddIns/BackendBindings/Scripting/Test/Utils/Tests/MockConsoleTextEditorTests.cs

@ -26,40 +26,40 @@ namespace ICSharpCode.Scripting.Tests.Utils.Tests
} }
[Test] [Test]
public void TextReturnsTextWritten() public void TextReturnsTextAppended()
{ {
textEditor.Write("abc"); textEditor.Append("abc");
Assert.AreEqual("abc", textEditor.Text); Assert.AreEqual("abc", textEditor.Text);
} }
[Test] [Test]
public void ColumnReturnsPositionAfterTextWritten() public void ColumnReturnsPositionAfterTextAppended()
{ {
textEditor.Write("ab"); textEditor.Append("ab");
Assert.AreEqual(2, textEditor.Column); Assert.AreEqual(2, textEditor.Column);
} }
[Test] [Test]
public void TextReturnsAllTextWritten() public void TextReturnsAllTextAppended()
{ {
textEditor.Write("a"); textEditor.Append("a");
textEditor.Write("b"); textEditor.Append("b");
Assert.AreEqual("ab", textEditor.Text); Assert.AreEqual("ab", textEditor.Text);
} }
[Test] [Test]
public void ColumnReturnsPositionAfterTextWhenWriteCalledTwice() public void ColumnReturnsPositionAfterTextWhenAppendCalledTwice()
{ {
textEditor.Write("a"); textEditor.Append("a");
textEditor.Write("bb"); textEditor.Append("bb");
Assert.AreEqual(3, textEditor.Column); Assert.AreEqual(3, textEditor.Column);
} }
[Test] [Test]
public void IsWriteCalledReturnsTrueAfterWriteMethodCalled() public void IsAppendCalledReturnsTrueAfterAppendMethodCalled()
{ {
textEditor.Write("a"); textEditor.Append("a");
Assert.IsTrue(textEditor.IsWriteCalled); Assert.IsTrue(textEditor.IsAppendCalled);
} }
[Test] [Test]

Loading…
Cancel
Save