9 changed files with 83 additions and 211 deletions
@ -1,90 +0,0 @@
@@ -1,90 +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 NUnit.Framework; |
||||
using RubyBinding.Tests.Utils; |
||||
|
||||
namespace RubyBinding.Tests.Gui |
||||
{ |
||||
[TestFixture] |
||||
public class SendLineToRubyConsoleCommandTests |
||||
{ |
||||
SendLineToRubyConsoleCommand sendLineToConsoleCommand; |
||||
MockConsoleTextEditor fakeConsoleTextEditor; |
||||
MockTextEditor fakeTextEditor; |
||||
MockWorkbench workbench; |
||||
MockScriptingConsole fakeConsole; |
||||
|
||||
[Test] |
||||
public void Run_SingleLineInTextEditor_FirstLineSentToRubyConsole() |
||||
{ |
||||
CreateSendLineToConsoleCommand(); |
||||
AddSingleLineToTextEditor("print 'hello'"); |
||||
sendLineToConsoleCommand.Run(); |
||||
|
||||
string text = fakeConsole.TextPassedToSendLine; |
||||
|
||||
string expectedText = "print 'hello'"; |
||||
Assert.AreEqual(expectedText, text); |
||||
} |
||||
|
||||
void CreateSendLineToConsoleCommand() |
||||
{ |
||||
workbench = MockWorkbench.CreateWorkbenchWithOneViewContent("test.rb"); |
||||
fakeConsoleTextEditor = workbench.MockScriptingConsolePad.MockConsoleTextEditor; |
||||
fakeConsole = workbench.MockScriptingConsolePad.MockScriptingConsole; |
||||
fakeTextEditor = workbench.ActiveMockEditableViewContent.MockTextEditor; |
||||
sendLineToConsoleCommand = new SendLineToRubyConsoleCommand(workbench); |
||||
} |
||||
|
||||
void AddSingleLineToTextEditor(string line) |
||||
{ |
||||
fakeTextEditor.Document.Text = line; |
||||
fakeTextEditor.Caret.Line = 1; |
||||
|
||||
SetTextToReturnFromTextEditorGetLine(line); |
||||
} |
||||
|
||||
void SetTextToReturnFromTextEditorGetLine(string line) |
||||
{ |
||||
FakeDocumentLine documentLine = new FakeDocumentLine(); |
||||
documentLine.Text = line; |
||||
fakeTextEditor.FakeDocument.DocumentLineToReturnFromGetLine = documentLine; |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_TwoLinesInTextEditorCursorOnFirstLine_FirstLineSentToRubyConsole() |
||||
{ |
||||
CreateSendLineToConsoleCommand(); |
||||
|
||||
fakeTextEditor.Document.Text = |
||||
"print 'hello'\r\n" + |
||||
"print 'world'\r\n"; |
||||
|
||||
fakeTextEditor.Caret.Line = 1; |
||||
|
||||
SetTextToReturnFromTextEditorGetLine("print 'hello'"); |
||||
|
||||
sendLineToConsoleCommand.Run(); |
||||
string text = fakeConsole.TextPassedToSendLine; |
||||
|
||||
string expectedText = "print 'hello'"; |
||||
Assert.AreEqual(expectedText, text); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_SingleLineInTextEditor_RubyConsolePadBroughtToFront() |
||||
{ |
||||
CreateSendLineToConsoleCommand(); |
||||
AddSingleLineToTextEditor("print 'hello'"); |
||||
|
||||
sendLineToConsoleCommand.Run(); |
||||
|
||||
bool broughtToFront = workbench.MockScriptingConsolePad.BringToFrontCalled; |
||||
Assert.IsTrue(broughtToFront); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
// <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.Core; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.Scripting |
||||
{ |
||||
public class SendLineToScriptingConsoleCommand : AbstractCommand |
||||
{ |
||||
IScriptingWorkbench workbench; |
||||
|
||||
IScriptingConsolePad consolePad; |
||||
ScriptingTextEditorViewContent textEditorView; |
||||
ITextEditor activeTextEditor; |
||||
IScriptingConsole pythonConsole; |
||||
string lineFromActiveTextEditor; |
||||
|
||||
public SendLineToScriptingConsoleCommand(IScriptingWorkbench workbench) |
||||
{ |
||||
this.workbench = workbench; |
||||
|
||||
textEditorView = new ScriptingTextEditorViewContent(workbench); |
||||
activeTextEditor = textEditorView.TextEditor; |
||||
} |
||||
|
||||
public override void Run() |
||||
{ |
||||
GetLineFromActiveTextEditor(); |
||||
GetScriptingConsolePad(); |
||||
ShowScriptingConsolePad(); |
||||
AppendLineToScriptingConsole(); |
||||
} |
||||
|
||||
void GetLineFromActiveTextEditor() |
||||
{ |
||||
int lineNumber = activeTextEditor.Caret.Line; |
||||
IDocumentLine documentLine = activeTextEditor.Document.GetLine(lineNumber); |
||||
lineFromActiveTextEditor = documentLine.Text; |
||||
} |
||||
|
||||
void GetScriptingConsolePad() |
||||
{ |
||||
consolePad = workbench.GetScriptingConsolePad(); |
||||
} |
||||
|
||||
void ShowScriptingConsolePad() |
||||
{ |
||||
consolePad.BringToFront(); |
||||
} |
||||
|
||||
void AppendLineToScriptingConsole() |
||||
{ |
||||
GetScriptingConsole(); |
||||
pythonConsole.SendLine(lineFromActiveTextEditor); |
||||
} |
||||
|
||||
void GetScriptingConsole() |
||||
{ |
||||
pythonConsole = consolePad.ScriptingConsole; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue