Browse Source

Refactor classes that implement IScriptingConsoleTextEditor and move them to the Scripting Tests project.

pull/1/head
mrward 16 years ago
parent
commit
0c0aeebeb3
  1. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsolePad.cs
  3. 29
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleTextEditorKeyEventArgs.cs
  4. 118
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ThreadSafePythonConsoleTextEditor.cs
  5. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/BuiltinCodeCompletionTestFixture.cs
  6. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHostTests.cs
  7. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  8. 3
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.csproj
  9. 4
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsolePad.cs
  10. 157
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleTextEditor.cs
  11. 5
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleHostTests.cs
  12. 147
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleTextEditorTests.cs
  13. 114
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/ThreadSafeRubyConsoleTextEditorTests.cs
  14. 2
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj
  15. 3
      src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
  16. 9
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs
  17. 7
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditorKeyEventArgs.cs
  18. 11
      src/AddIns/BackendBindings/Scripting/Project/Src/ThreadSafeScriptingConsoleTextEditor.cs
  19. 11
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTextEditorTests.cs
  20. 12
      src/AddIns/BackendBindings/Scripting/Test/Console/ThreadSafeScriptingConsoleTextEditorTests.cs
  21. 2
      src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
  22. 2
      src/AddIns/BackendBindings/Scripting/Test/Utils/MockControlDispatcher.cs

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

@ -97,7 +97,6 @@ @@ -97,7 +97,6 @@
<Compile Include="Src\PythonBuiltInModuleMemberName.cs" />
<Compile Include="Src\PythonClassResolver.cs" />
<Compile Include="Src\PythonConsoleApplication.cs" />
<Compile Include="Src\PythonConsoleTextEditorKeyEventArgs.cs" />
<Compile Include="Src\PythonDotNetMethodResolver.cs" />
<Compile Include="Src\PythonFileService.cs" />
<Compile Include="Src\PythonFromImport.cs" />
@ -167,8 +166,6 @@ @@ -167,8 +166,6 @@
<Compile Include="Src\PythonStandardModules.cs" />
<Compile Include="Src\PythonVariableResolver.cs" />
<Compile Include="Src\StringTextContentProvider.cs" />
<Compile Include="Src\PythonConsoleTextEditor.cs" />
<Compile Include="Src\ThreadSafePythonConsoleTextEditor.cs" />
<None Include="..\..\RequiredLibraries\Chiron.exe.Config">
<Link>Chiron.exe.Config</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

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

@ -14,14 +14,14 @@ namespace ICSharpCode.PythonBinding @@ -14,14 +14,14 @@ namespace ICSharpCode.PythonBinding
{
public class PythonConsolePad : AbstractPadContent, IPythonConsolePad
{
ThreadSafePythonConsoleTextEditor consoleTextEditor;
ThreadSafeScriptingConsoleTextEditor consoleTextEditor;
AvalonEdit.TextEditor textEditor;
PythonConsoleHost host;
public PythonConsolePad()
{
textEditor = new AvalonEdit.TextEditor();
consoleTextEditor = new ThreadSafePythonConsoleTextEditor(textEditor);
consoleTextEditor = new ThreadSafeScriptingConsoleTextEditor(textEditor);
host = new PythonConsoleHost(consoleTextEditor);
host.Run();
}

29
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleTextEditorKeyEventArgs.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Input;
using ICSharpCode.Scripting;
namespace ICSharpCode.PythonBinding
{
public class PythonConsoleTextEditorKeyEventArgs : ConsoleTextEditorKeyEventArgs
{
KeyEventArgs e;
public PythonConsoleTextEditorKeyEventArgs(KeyEventArgs e)
: base(e.Key)
{
this.e = e;
}
public override bool Handled {
get { return e.Handled; }
set { e.Handled = value; }
}
}
}

118
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ThreadSafePythonConsoleTextEditor.cs

@ -1,118 +0,0 @@ @@ -1,118 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.AvalonEdit;
using ICSharpCode.Scripting;
namespace ICSharpCode.PythonBinding
{
public class ThreadSafePythonConsoleTextEditor : IScriptingConsoleTextEditor
{
delegate string GetLineInvoker(int index);
IScriptingConsoleTextEditor consoleTextEditor;
IControlDispatcher dispatcher;
public ThreadSafePythonConsoleTextEditor(TextEditor textEditor)
: this(new PythonConsoleTextEditor(textEditor), new ControlDispatcher(textEditor))
{
}
public ThreadSafePythonConsoleTextEditor(IScriptingConsoleTextEditor consoleTextEditor, IControlDispatcher dispatcher)
{
this.consoleTextEditor = consoleTextEditor;
this.dispatcher = dispatcher;
}
public event ConsoleTextEditorKeyEventHandler PreviewKeyDown {
add { consoleTextEditor.PreviewKeyDown += value; }
remove { consoleTextEditor.PreviewKeyDown -= value; }
}
public void Dispose()
{
consoleTextEditor.Dispose();
}
public int Column {
get { return consoleTextEditor.Column; }
set { consoleTextEditor.Column = value; }
}
public int SelectionLength {
get { return consoleTextEditor.SelectionLength; }
}
public int SelectionStart {
get { return consoleTextEditor.SelectionStart; }
}
public int Line {
get { return consoleTextEditor.Line; }
set { consoleTextEditor.Line = value; }
}
public int TotalLines {
get { return consoleTextEditor.TotalLines; }
}
public bool IsCompletionWindowDisplayed {
get { return consoleTextEditor.IsCompletionWindowDisplayed; }
}
public void Write(string text)
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.Write(text);
} else {
Action<string> action = Write;
dispatcher.Invoke(action, text);
}
}
public void Replace(int index, int length, string text)
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.Replace(index, length, text);
} else {
Action<int, int, string> action = Replace;
dispatcher.Invoke(action, index, length, text);
}
}
public string GetLine(int index)
{
if (dispatcher.CheckAccess()) {
return consoleTextEditor.GetLine(index);
} else {
GetLineInvoker invoker = new GetLineInvoker(GetLine);
return (string)dispatcher.Invoke(invoker, index);
}
}
public void ShowCompletionWindow(ScriptingConsoleCompletionDataProvider completionDataProvider)
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.ShowCompletionWindow(completionDataProvider);
} else {
Action<ScriptingConsoleCompletionDataProvider> action = ShowCompletionWindow;
dispatcher.Invoke(action, completionDataProvider);
}
}
public void MakeCurrentContentReadOnly()
{
if (dispatcher.CheckAccess()) {
consoleTextEditor.MakeCurrentContentReadOnly();
} else {
Action action = MakeCurrentContentReadOnly;
dispatcher.Invoke(action);
}
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/BuiltinCodeCompletionTestFixture.cs

@ -33,7 +33,7 @@ namespace PythonBinding.Tests.Console @@ -33,7 +33,7 @@ namespace PythonBinding.Tests.Console
{
TextEditor textEditorControl = new TextEditor();
textEditorControl.Text = ">>> __builtins__";
PythonConsoleTextEditor textEditor = new PythonConsoleTextEditor(textEditorControl);
ScriptingConsoleTextEditor textEditor = new ScriptingConsoleTextEditor(textEditorControl);
memberProvider = new MockMemberProvider();
memberProvider.SetMemberNames(new string[] {"a", "b", "c"});

5
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHostTests.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using ICSharpCode.AvalonEdit;
using ICSharpCode.PythonBinding;
using ICSharpCode.Scripting;
using ICSharpCode.Scripting.Tests.Utils;
using IronPython.Hosting;
using IronPython.Runtime;
@ -27,13 +28,13 @@ namespace PythonBinding.Tests.Console @@ -27,13 +28,13 @@ namespace PythonBinding.Tests.Console
{
DerivedPythonConsoleHost host;
TextEditor textEditorControl;
PythonConsoleTextEditor textEditor;
ScriptingConsoleTextEditor textEditor;
[TestFixtureSetUp]
public void Init()
{
textEditorControl = new TextEditor();
textEditor = new PythonConsoleTextEditor(textEditorControl);
textEditor = new ScriptingConsoleTextEditor(textEditorControl);
host = new DerivedPythonConsoleHost(textEditor);
ScriptRuntime runtime = IronPython.Hosting.Python.CreateRuntime();

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -104,7 +104,6 @@ @@ -104,7 +104,6 @@
<Compile Include="Console\BuiltinCodeCompletionTestFixture.cs" />
<Compile Include="Console\PythonConsoleSendLineTests.cs" />
<Compile Include="Console\PythonConsoleTestsBase.cs" />
<Compile Include="Console\ThreadSafePythonConsoleTextEditorTests.cs" />
<Compile Include="Console\KeysPressedWhenCompletionWindowOpenTestFixture.cs" />
<Compile Include="Console\DisposedPythonConsoleTestFixture.cs" />
<Compile Include="Console\PythonConsoleCommandLineHistoryTestFixture.cs" />
@ -118,7 +117,6 @@ @@ -118,7 +117,6 @@
<Compile Include="Console\PythonConsoleUnreadLinesTestFixture.cs" />
<Compile Include="Console\PythonConsoleWriteTestFixture.cs" />
<Compile Include="Console\PythonOutputStreamTestFixture.cs" />
<Compile Include="Console\PythonConsoleTextEditorTests.cs" />
<Compile Include="Console\TwoPythonConsoleLinesWaitingTestFixture.cs" />
<Compile Include="Converter\AddHandlerConversionTestFixture.cs" />
<Compile Include="Converter\ArrayCastConversionTestFixture.cs" />

3
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.csproj

@ -105,7 +105,6 @@ @@ -105,7 +105,6 @@
<Compile Include="Src\RubyConsole.cs" />
<Compile Include="Src\RubyConsoleHost.cs" />
<Compile Include="Src\RubyConsolePad.cs" />
<Compile Include="Src\RubyConsoleTextEditorKeyEventArgs.cs" />
<Compile Include="Src\RubyConstructorInfo.cs" />
<Compile Include="Src\RubyControlFieldExpression.cs" />
<Compile Include="Src\RubyDesignerGenerator.cs" />
@ -134,9 +133,7 @@ @@ -134,9 +133,7 @@
<Compile Include="Src\RubyWorkbench.cs" />
<Compile Include="Src\RunDebugRubyCommand.cs" />
<Compile Include="Src\RunRubyCommand.cs" />
<Compile Include="Src\RubyConsoleTextEditor.cs" />
<Compile Include="Src\SendLineToRubyConsoleCommand.cs" />
<Compile Include="Src\ThreadSafeRubyConsoleTextEditor.cs" />
<EmbeddedResource Include="Resources\Ruby.xshd" />
<EmbeddedResource Include="Resources\RubyOptionsPanel.xfrm" />
<None Include="..\..\IronRuby\bin\Chiron.exe.config">

4
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsolePad.cs

@ -14,14 +14,14 @@ namespace ICSharpCode.RubyBinding @@ -14,14 +14,14 @@ namespace ICSharpCode.RubyBinding
{
public class RubyConsolePad : AbstractPadContent, IRubyConsolePad
{
ThreadSafeRubyConsoleTextEditor consoleTextEditor;
ThreadSafeScriptingConsoleTextEditor consoleTextEditor;
AvalonEdit.TextEditor textEditor;
RubyConsoleHost host;
public RubyConsolePad()
{
textEditor = new AvalonEdit.TextEditor();
consoleTextEditor = new ThreadSafeRubyConsoleTextEditor(textEditor);
consoleTextEditor = new ThreadSafeScriptingConsoleTextEditor(textEditor);
host = new RubyConsoleHost(consoleTextEditor);
host.Run();
}

157
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleTextEditor.cs

@ -1,157 +0,0 @@ @@ -1,157 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.Scripting;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.RubyBinding
{
public class RubyConsoleTextEditor : IScriptingConsoleTextEditor
{
TextEditor textEditor;
Color customLineColour = Color.LightGray;
BeginReadOnlySectionProvider readOnlyRegion;
CompletionWindow completionWindow;
public RubyConsoleTextEditor(TextEditor textEditor)
{
this.textEditor = textEditor;
readOnlyRegion = new BeginReadOnlySectionProvider();
textEditor.TextArea.ReadOnlySectionProvider = readOnlyRegion;
textEditor.PreviewKeyDown += OnTextEditorPreviewKeyDown;
}
void OnTextEditorPreviewKeyDown(object source, KeyEventArgs e)
{
if (PreviewKeyDown != null) {
PreviewKeyDown(this, new RubyConsoleTextEditorKeyEventArgs(e));
}
}
public event ConsoleTextEditorKeyEventHandler PreviewKeyDown;
public void Dispose()
{
textEditor.PreviewKeyDown -= OnTextEditorPreviewKeyDown;
}
public Color CustomLineColour {
get { return customLineColour; }
}
public void Write(string text)
{
TextLocation location = GetCurrentCursorLocation();
int offset = textEditor.Document.GetOffset(location);
textEditor.Document.Insert(offset, text);
}
TextLocation GetCurrentCursorLocation()
{
return new TextLocation(Line + 1, Column + 1);
}
public int Column {
get { return textEditor.TextArea.Caret.Column - 1; }
set { textEditor.TextArea.Caret.Column = value + 1; }
}
public int SelectionStart {
get { return textEditor.SelectionStart; }
}
public int SelectionLength {
get { return textEditor.SelectionLength; }
}
public int Line {
get { return textEditor.TextArea.Caret.Line - 1; }
set { textEditor.TextArea.Caret.Line = value + 1; }
}
/// <summary>
/// Gets the total number of lines in the text editor.
/// </summary>
public int TotalLines {
get { return textEditor.Document.LineCount; }
}
/// <summary>
/// Gets the text for the specified line.
/// </summary>
public string GetLine(int index)
{
DocumentLine line = textEditor.Document.GetLineByNumber(index + 1);
return textEditor.Document.GetText(line);
}
/// <summary>
/// Replaces the text at the specified index on the current line with the specified text.
/// </summary>
public void Replace(int index, int length, string text)
{
DocumentLine line = textEditor.Document.GetLineByNumber(textEditor.TextArea.Caret.Line);
int offset = line.Offset + index;
textEditor.Document.Replace(offset, length, text);
}
/// <summary>
/// Makes the current text read only. Text can still be entered at the end.
/// </summary>
public void MakeCurrentContentReadOnly()
{
readOnlyRegion.EndOffset = textEditor.Document.TextLength;
}
public void ShowCompletionWindow(ScriptingConsoleCompletionDataProvider completionDataProvider)
{
ICompletionData[] items = completionDataProvider.GenerateCompletionData(this);
if (items.Length > 0) {
ShowCompletionWindow(items);
}
}
void ShowCompletionWindow(ICompletionData[] items)
{
completionWindow = new CompletionWindow(textEditor.TextArea);
completionWindow.Closed += CompletionWindowClosed;
foreach (ICompletionData item in items) {
completionWindow.CompletionList.CompletionData.Add(item);
}
completionWindow.ExpectInsertionBeforeStart = true;
completionWindow.Show();
}
void ShowCompletionWindow(CompletionWindow window)
{
if (completionWindow == window) {
window.Show();
}
}
public bool IsCompletionWindowDisplayed {
get { return completionWindow != null; }
}
void CompletionWindowClosed(object source, EventArgs e)
{
if (completionWindow != null) {
completionWindow.Closed -= CompletionWindowClosed;
completionWindow = null;
}
}
}
}

5
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleHostTests.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using ICSharpCode.AvalonEdit;
using ICSharpCode.RubyBinding;
using ICSharpCode.Scripting;
using ICSharpCode.Scripting.Tests.Utils;
using IronRuby.Hosting;
using IronRuby.Runtime;
@ -27,13 +28,13 @@ namespace RubyBinding.Tests.Console @@ -27,13 +28,13 @@ namespace RubyBinding.Tests.Console
{
DerivedRubyConsoleHost host;
TextEditor textEditorControl;
RubyConsoleTextEditor textEditor;
ScriptingConsoleTextEditor textEditor;
[TestFixtureSetUp]
public void Init()
{
textEditorControl = new TextEditor();
textEditor = new RubyConsoleTextEditor(textEditorControl);
textEditor = new ScriptingConsoleTextEditor(textEditorControl);
host = new DerivedRubyConsoleHost(textEditor);
}

147
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/RubyConsoleTextEditorTests.cs

@ -1,147 +0,0 @@ @@ -1,147 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Input;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.RubyBinding;
using ICSharpCode.Scripting;
using NUnit.Framework;
using RubyBinding.Tests.Utils;
namespace RubyBinding.Tests.Console
{
[TestFixture]
public class RubyConsoleTextEditorTests
{
RubyConsoleTextEditor consoleTextEditor;
TextEditor avalonEditTextEditor;
[TestFixtureSetUp]
public void SetUpFixture()
{
avalonEditTextEditor = new TextEditor();
consoleTextEditor = new RubyConsoleTextEditor(avalonEditTextEditor);
}
[Test]
public void RubyConsoleTextEditorImplementsIScriptingConsoleTextEditorInterface()
{
Assert.IsNotNull(consoleTextEditor as IScriptingConsoleTextEditor);
}
[Test]
public void MakeCurrentTextEditorContentReadOnlyExtendsReadOnlyRegionToEntireDocument()
{
avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc" + Environment.NewLine);
consoleTextEditor.MakeCurrentContentReadOnly();
IReadOnlySectionProvider readOnlySection = avalonEditTextEditor.TextArea.ReadOnlySectionProvider;
Assert.IsFalse(readOnlySection.CanInsert(2));
}
[Test]
public void WriteMethodUpdatesTextEditor()
{
avalonEditTextEditor.Text = String.Empty;
consoleTextEditor.Write("abc");
Assert.AreEqual("abc", avalonEditTextEditor.Text);
}
[Test]
public void ZeroBasedConsoleTextEditorColumnPositionIsOneLessThanAvalonTextEditorColumnPositionWhichIsOneBased()
{
avalonEditTextEditor.Text = "test";
avalonEditTextEditor.TextArea.Caret.Column = 3;
Assert.AreEqual(2, consoleTextEditor.Column);
}
[Test]
public void SettingConsoleTextEditorColumnPositionUpdatesAvalonTextEditorColumnPosition()
{
avalonEditTextEditor.Text = "test";
avalonEditTextEditor.TextArea.Caret.Column = 0;
consoleTextEditor.Column = 1;
Assert.AreEqual(2, avalonEditTextEditor.TextArea.Caret.Column);
}
[Test]
public void GetSelectionStartAndLengthWhenThreeCharactersSelected()
{
avalonEditTextEditor.Text = "te000xt";
int startOffset = 2;
int endOffset = 5;
SimpleSelection expectedSelection = new SimpleSelection(startOffset, endOffset);
avalonEditTextEditor.SelectionStart = expectedSelection.StartOffset;
avalonEditTextEditor.SelectionLength = expectedSelection.Length;
// Sanity check.
Assert.AreEqual("000", avalonEditTextEditor.SelectedText);
AssertSelectionsAreEqual(expectedSelection, consoleTextEditor);
}
void AssertSelectionsAreEqual(SimpleSelection expectedSelection, IScriptingConsoleTextEditor consoleTextEditor)
{
int selectionLength = consoleTextEditor.SelectionStart + consoleTextEditor.SelectionLength;
SimpleSelection actualSelection = new SimpleSelection(consoleTextEditor.SelectionStart, selectionLength);
Assert.AreEqual(expectedSelection, actualSelection);
}
[Test]
public void GetSelectionStartAndLengthWhenNothingSelected()
{
avalonEditTextEditor.Text = "text";
avalonEditTextEditor.TextArea.Caret.Column = 1;
avalonEditTextEditor.SelectionLength = 0;
SimpleSelection expectedSelection = new SimpleSelection(1, 1);
AssertSelectionsAreEqual(expectedSelection, consoleTextEditor);
}
[Test]
public void ConsoleTextEditorLineEqualsOneLessThanAvalonTextEditorCaretLine()
{
avalonEditTextEditor.Text = "abc\r\ndef";
avalonEditTextEditor.TextArea.Caret.Line = 2;
Assert.AreEqual(1, consoleTextEditor.Line);
}
[Test]
public void ConsoleTextEditorTotalLinesEqualsAvalonTextEditorTotalLines()
{
avalonEditTextEditor.Text = "abc\r\ndef\r\nghi";
Assert.AreEqual(3, consoleTextEditor.TotalLines);
}
[Test]
public void GetLineForZerothLineReturnsFirstLineInAvalonTextEditor()
{
avalonEditTextEditor.Text = "abc\r\ndef\r\nghi";
Assert.AreEqual("abc", consoleTextEditor.GetLine(0));
}
[Test]
public void ReplaceTextReplacesTextInAvalonEditTextEditor()
{
avalonEditTextEditor.Text = "abc\r\ndef";
avalonEditTextEditor.TextArea.Caret.Line = 2;
int lineOffset = 1;
int length = 1;
consoleTextEditor.Replace(lineOffset, length, "test");
Assert.AreEqual("abc\r\ndtestf", avalonEditTextEditor.Text);
}
}
}

114
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Console/ThreadSafeRubyConsoleTextEditorTests.cs

@ -1,114 +0,0 @@ @@ -1,114 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Input;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.RubyBinding;
using ICSharpCode.Scripting.Tests.Utils;
using ICSharpCode.Scripting.Tests.Utils.Tests;
using NUnit.Framework;
using RubyBinding.Tests.Utils;
using RubyBinding.Tests.Utils.Tests;
namespace RubyBinding.Tests.Console
{
[TestFixture]
public class ThreadSafeRubyConsoleTextEditorTests
{
ThreadSafeRubyConsoleTextEditor consoleTextEditor;
MockConsoleTextEditor textEditor;
MockControlDispatcher dispatcher;
[TestFixtureSetUp]
public void SetUpFixture()
{
textEditor = new MockConsoleTextEditor();
dispatcher = new MockControlDispatcher();
consoleTextEditor = new ThreadSafeRubyConsoleTextEditor(textEditor, dispatcher);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseWriteMethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
consoleTextEditor.Write("abc");
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseWriteMethodIsInvokedWithTextAsArg()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
consoleTextEditor.Write("abc");
object[] expectedArgs = new object[] { "abc" };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseGetLineMethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
consoleTextEditor.GetLine(0);
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseGetLineMethodIsInvokedWithLineNumberAsArg()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
consoleTextEditor.GetLine(0);
object[] expectedArgs = new object[] { 0 };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseReplaceMethodIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
textEditor.Text = "abcd";
consoleTextEditor.Replace(0, 2, "12");
Assert.IsNotNull(dispatcher.MethodInvoked);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseReplaceethodIsInvokedWithThreeArgs()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvokedArgs = null;
textEditor.Text = "abcd";
consoleTextEditor.Replace(0, 2, "12");
object[] expectedArgs = new object[] { 0, 2, "12" };
Assert.AreEqual(expectedArgs, dispatcher.MethodInvokedArgs);
}
[Test]
public void IfDispatcherCheckAccessReturnsFalseMakeCurrentContentReadOnlyIsInvoked()
{
dispatcher.CheckAccessReturnValue = false;
dispatcher.MethodInvoked = null;
consoleTextEditor.MakeCurrentContentReadOnly();
Assert.IsNotNull(dispatcher.MethodInvoked);
}
}
}

2
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj

@ -84,11 +84,9 @@ @@ -84,11 +84,9 @@
<Compile Include="Console\RubyConsoleReadTestFixture.cs" />
<Compile Include="Console\RubyConsoleSendLineTests.cs" />
<Compile Include="Console\RubyConsoleTestsBase.cs" />
<Compile Include="Console\RubyConsoleTextEditorTests.cs" />
<Compile Include="Console\RubyConsoleUnreadLinesTestFixture.cs" />
<Compile Include="Console\RubyConsoleWriteTestFixture.cs" />
<Compile Include="Console\RubyOutputStreamTestFixture.cs" />
<Compile Include="Console\ThreadSafeRubyConsoleTextEditorTests.cs" />
<Compile Include="Console\TwoRubyConsoleLinesWaitingTestFixture.cs" />
<Compile Include="Converter\AddHandlerConversionTestFixture.cs" />
<Compile Include="Converter\ArrayCastConversionTestFixture.cs" />

3
src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj

@ -72,7 +72,10 @@ @@ -72,7 +72,10 @@
<Compile Include="Src\IScriptingConsoleTextEditor.cs" />
<Compile Include="Src\ScriptingConsoleCompletionData.cs" />
<Compile Include="Src\ScriptingConsoleCompletionDataProvider.cs" />
<Compile Include="Src\ScriptingConsoleTextEditor.cs" />
<Compile Include="Src\ScriptingConsoleTextEditorKeyEventArgs.cs" />
<Compile Include="Src\StringListLock.cs" />
<Compile Include="Src\ThreadSafeScriptingConsoleTextEditor.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">

9
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleTextEditor.cs → src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditor.cs

@ -13,19 +13,18 @@ using System.Windows.Threading; @@ -13,19 +13,18 @@ using System.Windows.Threading;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.Scripting;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PythonBinding
namespace ICSharpCode.Scripting
{
public class PythonConsoleTextEditor : IScriptingConsoleTextEditor
public class ScriptingConsoleTextEditor : IScriptingConsoleTextEditor
{
TextEditor textEditor;
Color customLineColour = Color.LightGray;
BeginReadOnlySectionProvider readOnlyRegion;
CompletionWindow completionWindow;
public PythonConsoleTextEditor(TextEditor textEditor)
public ScriptingConsoleTextEditor(TextEditor textEditor)
{
this.textEditor = textEditor;
readOnlyRegion = new BeginReadOnlySectionProvider();
@ -36,7 +35,7 @@ namespace ICSharpCode.PythonBinding @@ -36,7 +35,7 @@ namespace ICSharpCode.PythonBinding
void OnTextEditorPreviewKeyDown(object source, KeyEventArgs e)
{
if (PreviewKeyDown != null) {
PreviewKeyDown(this, new PythonConsoleTextEditorKeyEventArgs(e));
PreviewKeyDown(this, new ScriptingConsoleTextEditorKeyEventArgs(e));
}
}

7
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleTextEditorKeyEventArgs.cs → src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleTextEditorKeyEventArgs.cs

@ -7,15 +7,14 @@ @@ -7,15 +7,14 @@
using System;
using System.Windows.Input;
using ICSharpCode.Scripting;
namespace ICSharpCode.RubyBinding
namespace ICSharpCode.Scripting
{
public class RubyConsoleTextEditorKeyEventArgs : ConsoleTextEditorKeyEventArgs
public class ScriptingConsoleTextEditorKeyEventArgs : ConsoleTextEditorKeyEventArgs
{
KeyEventArgs e;
public RubyConsoleTextEditorKeyEventArgs(KeyEventArgs e)
public ScriptingConsoleTextEditorKeyEventArgs(KeyEventArgs e)
: base(e.Key)
{
this.e = e;

11
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/ThreadSafeRubyConsoleTextEditor.cs → src/AddIns/BackendBindings/Scripting/Project/Src/ThreadSafeScriptingConsoleTextEditor.cs

@ -7,23 +7,22 @@ @@ -7,23 +7,22 @@
using System;
using ICSharpCode.AvalonEdit;
using ICSharpCode.Scripting;
namespace ICSharpCode.RubyBinding
namespace ICSharpCode.Scripting
{
public class ThreadSafeRubyConsoleTextEditor : IScriptingConsoleTextEditor
public class ThreadSafeScriptingConsoleTextEditor : IScriptingConsoleTextEditor
{
delegate string GetLineInvoker(int index);
IScriptingConsoleTextEditor consoleTextEditor;
IControlDispatcher dispatcher;
public ThreadSafeRubyConsoleTextEditor(TextEditor textEditor)
: this(new RubyConsoleTextEditor(textEditor), new ControlDispatcher(textEditor))
public ThreadSafeScriptingConsoleTextEditor(TextEditor textEditor)
: this(new ScriptingConsoleTextEditor(textEditor), new ControlDispatcher(textEditor))
{
}
public ThreadSafeRubyConsoleTextEditor(IScriptingConsoleTextEditor consoleTextEditor, IControlDispatcher dispatcher)
public ThreadSafeScriptingConsoleTextEditor(IScriptingConsoleTextEditor consoleTextEditor, IControlDispatcher dispatcher)
{
this.consoleTextEditor = consoleTextEditor;
this.dispatcher = dispatcher;

11
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleTextEditorTests.cs → src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTextEditorTests.cs

@ -12,24 +12,23 @@ using System.Windows.Input; @@ -12,24 +12,23 @@ using System.Windows.Input;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.PythonBinding;
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 PythonConsoleTextEditorTests
public class ScriptingConsoleTextEditorTests
{
PythonConsoleTextEditor consoleTextEditor;
ScriptingConsoleTextEditor consoleTextEditor;
TextEditor avalonEditTextEditor;
[TestFixtureSetUp]
public void SetUpFixture()
{
avalonEditTextEditor = new TextEditor();
consoleTextEditor = new PythonConsoleTextEditor(avalonEditTextEditor);
consoleTextEditor = new ScriptingConsoleTextEditor(avalonEditTextEditor);
}
[Test]

12
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/ThreadSafePythonConsoleTextEditorTests.cs → src/AddIns/BackendBindings/Scripting/Test/Console/ThreadSafeScriptingConsoleTextEditorTests.cs

@ -12,20 +12,16 @@ using System.Windows.Input; @@ -12,20 +12,16 @@ using System.Windows.Input;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.PythonBinding;
using ICSharpCode.Scripting;
using ICSharpCode.Scripting.Tests.Utils;
using ICSharpCode.Scripting.Tests.Utils.Tests;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
using PythonBinding.Tests.Utils.Tests;
namespace PythonBinding.Tests.Console
namespace ICSharpCode.Scripting.Tests.Console
{
[TestFixture]
public class ThreadSafePythonConsoleTextEditorTests
public class ThreadSafeScriptingConsoleTextEditorTests
{
ThreadSafePythonConsoleTextEditor threadSafeConsoleTextEditor;
ThreadSafeScriptingConsoleTextEditor threadSafeConsoleTextEditor;
TextEditor avalonEditTextEditor;
MockControlDispatcher dispatcher;
MockConsoleTextEditor fakeConsoleTextEditor;
@ -39,7 +35,7 @@ namespace PythonBinding.Tests.Console @@ -39,7 +35,7 @@ namespace PythonBinding.Tests.Console
dispatcher.CheckAccessReturnValue = true;
fakeConsoleTextEditor = new MockConsoleTextEditor();
threadSafeConsoleTextEditor = new ThreadSafePythonConsoleTextEditor(fakeConsoleTextEditor, dispatcher);
threadSafeConsoleTextEditor = new ThreadSafeScriptingConsoleTextEditor(fakeConsoleTextEditor, dispatcher);
}
[Test]

2
src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj

@ -72,6 +72,8 @@ @@ -72,6 +72,8 @@
<Compile Include="Console\EmptyStringCodeCompletionTests.cs" />
<Compile Include="Console\InsertConsoleCompletionDataTestFixture.cs" />
<Compile Include="Console\OneItemCommandLineHistoryTestFixture.cs" />
<Compile Include="Console\ScriptingConsoleTextEditorTests.cs" />
<Compile Include="Console\ThreadSafeScriptingConsoleTextEditorTests.cs" />
<Compile Include="Testing\CreateTextWriterFromCreateTextWriterInfoTestFixture.cs" />
<Compile Include="Testing\CreateTextWriterInfoEqualsTestFixture.cs" />
<Compile Include="Utils\AddedComponent.cs" />

2
src/AddIns/BackendBindings/Scripting/Test/Utils/MockControlDispatcher.cs

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
using System;
using ICSharpCode.Scripting;
namespace ICSharpCode.Scripting.Tests.Utils.Tests
namespace ICSharpCode.Scripting.Tests.Utils
{
public class MockControlDispatcher : IControlDispatcher
{

Loading…
Cancel
Save