59 changed files with 1473 additions and 917 deletions
@ -1,85 +0,0 @@
@@ -1,85 +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.IO; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
/// <summary>
|
||||
/// Holds the options for the RubyBinding AddIn
|
||||
/// </summary>
|
||||
public class AddInOptions |
||||
{ |
||||
/// <summary>
|
||||
/// The name of the options as read from the PropertyService.
|
||||
/// </summary>
|
||||
public static readonly string AddInOptionsName = "RubyBinding.Options"; |
||||
|
||||
/// <summary>
|
||||
/// The default Ruby console filename.
|
||||
/// </summary>
|
||||
public static readonly string DefaultRubyFileName = "ir.exe"; |
||||
|
||||
#region Property names
|
||||
public static readonly string RubyFileNameProperty = "RubyFileName"; |
||||
#endregion
|
||||
|
||||
Properties properties; |
||||
|
||||
public AddInOptions() |
||||
: this(PropertyService.Get(AddInOptionsName, new Properties())) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates the addin options class which will use
|
||||
/// the options from the properties class specified.
|
||||
/// </summary>
|
||||
public AddInOptions(Properties properties) |
||||
{ |
||||
this.properties = properties; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Ruby console filename.
|
||||
/// </summary>
|
||||
public string RubyFileName { |
||||
get { |
||||
return properties.Get<string>(RubyFileNameProperty, GetDefaultRubyFileName()); |
||||
} |
||||
set { |
||||
if (String.IsNullOrEmpty(value)) { |
||||
properties.Set(RubyFileNameProperty, GetDefaultRubyFileName()); |
||||
} else { |
||||
properties.Set(RubyFileNameProperty, value); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the path to the specified addin.
|
||||
/// </summary>
|
||||
/// <param name="addIn">The addin name: "${addin:ICSharpCode.RubyBinding}"</param>
|
||||
protected virtual string GetAddInPath(string addIn) |
||||
{ |
||||
return StringParser.Parse(addIn); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the full path to ir.exe which is installed in the
|
||||
/// Ruby addin folder.
|
||||
/// </summary>
|
||||
string GetDefaultRubyFileName() |
||||
{ |
||||
string path = GetAddInPath("${addinpath:ICSharpCode.RubyBinding}"); |
||||
return Path.Combine(path, DefaultRubyFileName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
// <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.RubyBinding |
||||
{ |
||||
public interface ILock : IDisposable |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
// <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.RubyBinding |
||||
{ |
||||
public interface IRubyConsole |
||||
{ |
||||
void SendLine(string text); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// <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.RubyBinding |
||||
{ |
||||
public interface IRubyConsolePad |
||||
{ |
||||
void BringToFront(); |
||||
IConsoleTextEditor ConsoleTextEditor { get; } |
||||
IRubyConsole RubyConsole { get; } |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// <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.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public interface IRubyWorkbench |
||||
{ |
||||
IRubyConsolePad GetRubyConsolePad(); |
||||
IViewContent ActiveViewContent { get; } |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// <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.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class RubyWorkbench : IRubyWorkbench |
||||
{ |
||||
IWorkbench workbench; |
||||
|
||||
public RubyWorkbench() |
||||
{ |
||||
workbench = WorkbenchSingleton.Workbench; |
||||
} |
||||
|
||||
public IViewContent ActiveViewContent { |
||||
get { return workbench.ActiveViewContent; } |
||||
} |
||||
|
||||
public IRubyConsolePad GetRubyConsolePad() |
||||
{ |
||||
PadDescriptor padDescriptor = workbench.GetPad(typeof(RubyConsolePad)); |
||||
return padDescriptor.PadContent as IRubyConsolePad; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// <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.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class SendLineToRubyConsoleCommand : AbstractCommand |
||||
{ |
||||
IRubyWorkbench workbench; |
||||
IRubyConsolePad consolePad; |
||||
RubyTextEditorViewContent textEditorView; |
||||
ITextEditor activeTextEditor; |
||||
IRubyConsole RubyConsole; |
||||
string lineFromActiveTextEditor; |
||||
|
||||
public SendLineToRubyConsoleCommand() |
||||
: this(new RubyWorkbench()) |
||||
{ |
||||
} |
||||
|
||||
public SendLineToRubyConsoleCommand(IRubyWorkbench workbench) |
||||
{ |
||||
this.workbench = workbench; |
||||
|
||||
textEditorView = new RubyTextEditorViewContent(workbench); |
||||
activeTextEditor = textEditorView.TextEditor; |
||||
} |
||||
|
||||
public override void Run() |
||||
{ |
||||
GetLineFromActiveTextEditor(); |
||||
GetRubyConsolePad(); |
||||
ShowRubyConsolePad(); |
||||
AppendLineToRubyConsole(); |
||||
} |
||||
|
||||
void GetLineFromActiveTextEditor() |
||||
{ |
||||
int lineNumber = activeTextEditor.Caret.Line; |
||||
IDocumentLine documentLine = activeTextEditor.Document.GetLine(lineNumber); |
||||
lineFromActiveTextEditor = documentLine.Text; |
||||
} |
||||
|
||||
void GetRubyConsolePad() |
||||
{ |
||||
consolePad = workbench.GetRubyConsolePad(); |
||||
} |
||||
|
||||
void ShowRubyConsolePad() |
||||
{ |
||||
consolePad.BringToFront(); |
||||
} |
||||
|
||||
void AppendLineToRubyConsole() |
||||
{ |
||||
GetRubyConsole(); |
||||
RubyConsole.SendLine(lineFromActiveTextEditor); |
||||
} |
||||
|
||||
void GetRubyConsole() |
||||
{ |
||||
RubyConsole = consolePad.RubyConsole; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// <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; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class StringListLock : ILock |
||||
{ |
||||
List<string> lines; |
||||
|
||||
public StringListLock(List<string> lines) |
||||
{ |
||||
this.lines = lines; |
||||
Lock(); |
||||
} |
||||
|
||||
void Lock() |
||||
{ |
||||
Monitor.Enter(lines); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
Unlock(); |
||||
} |
||||
|
||||
void Unlock() |
||||
{ |
||||
Monitor.Exit(lines); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// <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; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class ThreadSafeRubyConsoleTextEditor : IConsoleTextEditor |
||||
{ |
||||
delegate string GetLineInvoker(int index); |
||||
|
||||
IConsoleTextEditor consoleTextEditor; |
||||
IControlDispatcher dispatcher; |
||||
|
||||
public ThreadSafeRubyConsoleTextEditor(TextEditor textEditor) |
||||
: this(new RubyConsoleTextEditor(textEditor), new ControlDispatcher(textEditor)) |
||||
{ |
||||
} |
||||
|
||||
public ThreadSafeRubyConsoleTextEditor(IConsoleTextEditor 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(RubyConsoleCompletionDataProvider completionDataProvider) |
||||
{ |
||||
if (dispatcher.CheckAccess()) { |
||||
consoleTextEditor.ShowCompletionWindow(completionDataProvider); |
||||
} else { |
||||
Action<RubyConsoleCompletionDataProvider> action = ShowCompletionWindow; |
||||
dispatcher.Invoke(action, completionDataProvider); |
||||
} |
||||
} |
||||
|
||||
public void MakeCurrentContentReadOnly() |
||||
{ |
||||
if (dispatcher.CheckAccess()) { |
||||
consoleTextEditor.MakeCurrentContentReadOnly(); |
||||
} else { |
||||
Action action = MakeCurrentContentReadOnly; |
||||
dispatcher.Invoke(action); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,174 @@
@@ -0,0 +1,174 @@
|
||||
// <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 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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
// <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.RubyBinding; |
||||
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; |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
using RubyBinding.Tests.Utils; |
||||
|
||||
namespace RubyBinding.Tests.Gui |
||||
{ |
||||
[TestFixture] |
||||
public class SendLineToRubyConsoleCommandTests |
||||
{ |
||||
SendLineToRubyConsoleCommand sendLineToConsoleCommand; |
||||
MockConsoleTextEditor fakeConsoleTextEditor; |
||||
MockTextEditor fakeTextEditor; |
||||
MockWorkbench workbench; |
||||
MockRubyConsole 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.MockRubyConsolePad.MockConsoleTextEditor; |
||||
fakeConsole = workbench.MockRubyConsolePad.MockRubyConsole; |
||||
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.MockRubyConsolePad.BringToFrontCalled; |
||||
Assert.IsTrue(broughtToFront); |
||||
} |
||||
} |
||||
} |
@ -1,54 +0,0 @@
@@ -1,54 +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.RubyBinding; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Internal.Templates; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the RubyLanguageBinding class.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class LanguageBindingTestFixture |
||||
{ |
||||
RubyLanguageBinding languageBinding; |
||||
RubyProject project; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
languageBinding = new RubyLanguageBinding(); |
||||
ProjectCreateInformation createInfo = new ProjectCreateInformation(); |
||||
createInfo.ProjectName = "Ruby"; |
||||
createInfo.OutputProjectFileName = @"C:\Projects\Ruby.rbproj"; |
||||
createInfo.Solution = new Solution(); |
||||
project = languageBinding.CreateProject(createInfo) as RubyProject; |
||||
} |
||||
|
||||
[Test] |
||||
public void Language() |
||||
{ |
||||
Assert.AreEqual("Ruby", languageBinding.Language); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsRubyProject() |
||||
{ |
||||
Assert.IsNotNull(project); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectName() |
||||
{ |
||||
Assert.AreEqual("Ruby", project.Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// <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.SharpDevelop.Editor; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class FakeCaret : ITextEditorCaret |
||||
{ |
||||
public event EventHandler PositionChanged; |
||||
|
||||
protected virtual void OnPositionChanged(EventArgs e) |
||||
{ |
||||
if (PositionChanged != null) { |
||||
PositionChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public int Offset { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int Line { get; set; } |
||||
|
||||
public int Column { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICSharpCode.NRefactory.Location Position { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,139 @@
@@ -0,0 +1,139 @@
|
||||
// <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.IO; |
||||
using System.Text; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class FakeDocument : IDocument |
||||
{ |
||||
#pragma warning disable 0067
|
||||
public event EventHandler<TextChangeEventArgs> Changing; |
||||
public event EventHandler<TextChangeEventArgs> Changed; |
||||
public event EventHandler TextChanged; |
||||
#pragma warning restore 0067
|
||||
|
||||
public FakeDocumentLine DocumentLineToReturnFromGetLine; |
||||
public int LineNumberPassedToGetLine; |
||||
|
||||
public string Text { get; set; } |
||||
|
||||
public int TotalNumberOfLines { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ITextBufferVersion Version { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int TextLength { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IDocumentLine GetLine(int lineNumber) |
||||
{ |
||||
LineNumberPassedToGetLine = lineNumber; |
||||
return DocumentLineToReturnFromGetLine; |
||||
} |
||||
|
||||
public IDocumentLine GetLineForOffset(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public int PositionToOffset(int line, int column) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public Location OffsetToPosition(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Insert(int offset, string text) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Remove(int offset, int length) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Replace(int offset, int length, string newText) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void StartUndoableAction() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void EndUndoableAction() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IDisposable OpenUndoGroup() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ITextAnchor CreateAnchor(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ITextBuffer CreateSnapshot() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ITextBuffer CreateSnapshot(int offset, int length) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public TextReader CreateReader() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public TextReader CreateReader(int offset, int length) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public char GetCharAt(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public string GetText(int offset, int length) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object GetService(Type serviceType) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
// <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.SharpDevelop.Editor; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class FakeDocumentLine : IDocumentLine |
||||
{ |
||||
public int Offset { get; set; } |
||||
public int Length { get; set; } |
||||
public int EndOffset { get; set; } |
||||
public int TotalLength { get; set; } |
||||
public int DelimiterLength { get; set; } |
||||
public int LineNumber { get; set; } |
||||
public string Text { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// <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 ICSharpCode.RubyBinding; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class FakeLock : ILock |
||||
{ |
||||
public List<string> Lines; |
||||
public bool IsDisposed; |
||||
public int UnreadLineCountWhenLockCreated = -1; |
||||
public int UnreadLineCountWhenLockDisposed = -1; |
||||
|
||||
public FakeLock(List<string> lines) |
||||
{ |
||||
this.Lines = lines; |
||||
UnreadLineCountWhenLockCreated = lines.Count; |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
UnreadLineCountWhenLockDisposed = Lines.Count; |
||||
IsDisposed = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// <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.RubyBinding; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockRubyConsole : IRubyConsole |
||||
{ |
||||
public string TextPassedToSendLine; |
||||
|
||||
public void SendLine(string text) |
||||
{ |
||||
TextPassedToSendLine = text; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// <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.RubyBinding; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockRubyConsolePad : IRubyConsolePad |
||||
{ |
||||
public MockConsoleTextEditor MockConsoleTextEditor = new MockConsoleTextEditor(); |
||||
public MockRubyConsole MockRubyConsole = new MockRubyConsole(); |
||||
|
||||
public bool BringToFrontCalled; |
||||
|
||||
public void BringToFront() |
||||
{ |
||||
BringToFrontCalled = true; |
||||
} |
||||
|
||||
public IConsoleTextEditor ConsoleTextEditor { |
||||
get { return MockConsoleTextEditor; } |
||||
} |
||||
|
||||
public IRubyConsole RubyConsole { |
||||
get { return MockRubyConsole; } |
||||
} |
||||
} |
||||
} |
@ -1,129 +0,0 @@
@@ -1,129 +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.Drawing; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Dummy IWorkbenchWindow class.
|
||||
/// </summary>
|
||||
public class MockWorkbenchWindow : IWorkbenchWindow |
||||
{ |
||||
IViewContent viewContent; |
||||
|
||||
public MockWorkbenchWindow() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler WindowSelected; |
||||
public event EventHandler WindowDeselected; |
||||
public event EventHandler TitleChanged; |
||||
public event EventHandler CloseEvent; |
||||
public event EventHandler ActiveViewContentChanged; |
||||
|
||||
public string Title { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsDisposed { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IViewContent ActiveViewContent { |
||||
get { |
||||
return viewContent; |
||||
} |
||||
set { |
||||
viewContent = value; |
||||
} |
||||
} |
||||
|
||||
public bool CloseWindow(bool force) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void SelectWindow() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void RedrawContent() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void SwitchView(int viewNumber) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void OnWindowDeselected(EventArgs e) |
||||
{ |
||||
if (WindowDeselected != null) { |
||||
WindowDeselected(this, e); |
||||
} |
||||
} |
||||
|
||||
public void OnWindowSelected(EventArgs e) |
||||
{ |
||||
if (WindowSelected != null) { |
||||
WindowSelected(this, e); |
||||
} |
||||
} |
||||
|
||||
public System.Windows.Media.ImageSource Icon { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<IViewContent> ViewContents { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnTitleChanged(EventArgs e) |
||||
{ |
||||
if (TitleChanged != null) { |
||||
TitleChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnCloseEvent(EventArgs e) |
||||
{ |
||||
if (CloseEvent != null) { |
||||
CloseEvent(this, e); |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnActiveViewContentChanged(EventArgs e) |
||||
{ |
||||
if (ActiveViewContentChanged != null) { |
||||
ActiveViewContentChanged(this, e); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
// <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 ICSharpCode.RubyBinding; |
||||
using IronRuby.Hosting; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class TestableRubyConsole : RubyConsole |
||||
{ |
||||
public MockConsoleTextEditor MockConsoleTextEditor; |
||||
public FakeLock LockCreated; |
||||
public bool IsLineReceivedEventFired; |
||||
public int UnreadLineCountWhenLineReceivedEventFired = -1; |
||||
|
||||
public TestableRubyConsole() |
||||
: this(new MockConsoleTextEditor(), new RubyCommandLine()) |
||||
{ |
||||
} |
||||
|
||||
TestableRubyConsole(IConsoleTextEditor consoleTextEditor, RubyCommandLine commandLine) |
||||
: base(consoleTextEditor) |
||||
{ |
||||
CommandLine = commandLine; |
||||
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