Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5970 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
106 changed files with 2373 additions and 1620 deletions
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// <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; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public delegate void ConsoleTextEditorKeyEventHandler(object source, ConsoleTextEditorKeyEventArgs e); |
||||
|
||||
public abstract class ConsoleTextEditorKeyEventArgs : EventArgs |
||||
{ |
||||
Key key; |
||||
|
||||
public ConsoleTextEditorKeyEventArgs(Key key) |
||||
{ |
||||
this.key = key; |
||||
} |
||||
|
||||
public Key Key { |
||||
get { return key; } |
||||
} |
||||
|
||||
public abstract bool Handled { |
||||
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.Windows; |
||||
using System.Windows.Threading; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class ControlDispatcher : IControlDispatcher |
||||
{ |
||||
Dispatcher dispatcher; |
||||
|
||||
public ControlDispatcher(UIElement uiElement) |
||||
{ |
||||
dispatcher = uiElement.Dispatcher; |
||||
} |
||||
|
||||
public bool CheckAccess() |
||||
{ |
||||
return dispatcher.CheckAccess(); |
||||
} |
||||
|
||||
public object Invoke(Delegate method, params object[] args) |
||||
{ |
||||
return dispatcher.Invoke(method, args); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
// <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 IControlDispatcher |
||||
{ |
||||
bool CheckAccess(); |
||||
object Invoke(Delegate method, params object[] args); |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
// <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.Media; |
||||
using ICSharpCode.AvalonEdit.CodeCompletion; |
||||
using ICSharpCode.AvalonEdit.Document; |
||||
using ICSharpCode.AvalonEdit.Editing; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class RubyConsoleCompletionData : ICompletionData |
||||
{ |
||||
string text = String.Empty; |
||||
|
||||
public RubyConsoleCompletionData(string text) |
||||
{ |
||||
this.text = text; |
||||
} |
||||
|
||||
public ImageSource Image { |
||||
get { return null; } |
||||
} |
||||
|
||||
public string Text { |
||||
get { return text; } |
||||
} |
||||
|
||||
public object Content { |
||||
get { return text; } |
||||
} |
||||
|
||||
public object Description { |
||||
get { return null; } |
||||
} |
||||
|
||||
public double Priority { |
||||
get { return 0; } |
||||
} |
||||
|
||||
public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) |
||||
{ |
||||
textArea.Document.Replace(completionSegment, text); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,183 @@
@@ -0,0 +1,183 @@
|
||||
// <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.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class RubyConsoleTextEditor : IConsoleTextEditor |
||||
{ |
||||
delegate string GetLineInvoker(int index); |
||||
|
||||
TextEditor textEditor; |
||||
Color customLineColour = Color.LightGray; |
||||
BeginReadOnlySectionProvider readOnlyRegion; |
||||
IControlDispatcher dispatcher; |
||||
CompletionWindow completionWindow; |
||||
|
||||
public RubyConsoleTextEditor(TextEditor textEditor) |
||||
: this(textEditor, new ControlDispatcher(textEditor)) |
||||
{ |
||||
} |
||||
|
||||
public RubyConsoleTextEditor(TextEditor textEditor, IControlDispatcher dispatcher) |
||||
{ |
||||
this.textEditor = textEditor; |
||||
this.dispatcher = dispatcher; |
||||
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 Color CustomLineColour { |
||||
get { return customLineColour; } |
||||
} |
||||
|
||||
public void Write(string text) |
||||
{ |
||||
if (dispatcher.CheckAccess()) { |
||||
TextLocation location = GetCurrentCursorLocation(); |
||||
int offset = textEditor.Document.GetOffset(location); |
||||
textEditor.Document.Insert(offset, text); |
||||
} else { |
||||
Action<string> action = Write; |
||||
dispatcher.Invoke(action, new object[] {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; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current cursor line.
|
||||
/// </summary>
|
||||
public int Line { |
||||
get { return textEditor.TextArea.Caret.Line - 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) |
||||
{ |
||||
if (dispatcher.CheckAccess()) { |
||||
DocumentLine line = textEditor.Document.GetLineByNumber(index + 1); |
||||
return textEditor.Document.GetText(line); |
||||
} else { |
||||
GetLineInvoker invoker = new GetLineInvoker(GetLine); |
||||
return (string)dispatcher.Invoke(invoker, new object[] {index}); |
||||
} |
||||
} |
||||
|
||||
/// <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) |
||||
{ |
||||
if (dispatcher.CheckAccess()) { |
||||
DocumentLine line = textEditor.Document.GetLineByNumber(textEditor.TextArea.Caret.Line); |
||||
int offset = line.Offset + index; |
||||
textEditor.Document.Replace(offset, length, text); |
||||
} else { |
||||
Action<int, int, string> action = Replace; |
||||
dispatcher.Invoke(action, new object[] {index, length, text}); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Makes the current text read only. Text can still be entered at the end.
|
||||
/// </summary>
|
||||
public void MakeCurrentContentReadOnly() |
||||
{ |
||||
if (dispatcher.CheckAccess()) { |
||||
readOnlyRegion.EndOffset = textEditor.Document.TextLength; |
||||
} else { |
||||
Action action = MakeCurrentContentReadOnly; |
||||
dispatcher.Invoke(action); |
||||
} |
||||
} |
||||
|
||||
public void ShowCompletionWindow(RubyConsoleCompletionDataProvider 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(); |
||||
Action<CompletionWindow> action = ShowCompletionWindow; |
||||
completionWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, action, completionWindow); |
||||
} |
||||
|
||||
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; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// <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; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class RubyConsoleTextEditorKeyEventArgs : ConsoleTextEditorKeyEventArgs |
||||
{ |
||||
KeyEventArgs e; |
||||
|
||||
public RubyConsoleTextEditorKeyEventArgs(KeyEventArgs e) |
||||
: base(e.Key) |
||||
{ |
||||
this.e = e; |
||||
} |
||||
|
||||
public override bool Handled { |
||||
get { return e.Handled; } |
||||
set { e.Handled = value; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <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 RubyTextEditorViewContent |
||||
{ |
||||
IViewContent view; |
||||
IEditable editable; |
||||
ITextEditorProvider textEditorProvider; |
||||
ITextEditor textEditor; |
||||
ITextEditorOptions textEditorOptions; |
||||
|
||||
public RubyTextEditorViewContent(IWorkbench workbench) |
||||
{ |
||||
Init(workbench.ActiveWorkbenchWindow.ActiveViewContent); |
||||
} |
||||
|
||||
public RubyTextEditorViewContent(IViewContent view) |
||||
{ |
||||
Init(view); |
||||
} |
||||
|
||||
void Init(IViewContent view) |
||||
{ |
||||
this.view = view; |
||||
editable = view as IEditable; |
||||
textEditorProvider = view as ITextEditorProvider; |
||||
textEditor = textEditorProvider.TextEditor; |
||||
textEditorOptions = textEditor.Options; |
||||
} |
||||
|
||||
public FileName PrimaryFileName { |
||||
get { return view.PrimaryFileName; } |
||||
} |
||||
|
||||
public IEditable EditableView { |
||||
get { return editable; } |
||||
} |
||||
|
||||
public ITextEditor TextEditor { |
||||
get { return textEditor; } |
||||
} |
||||
|
||||
public ITextEditorOptions TextEditorOptions { |
||||
get { return textEditorOptions; } |
||||
} |
||||
} |
||||
} |
||||
@ -1,192 +0,0 @@
@@ -1,192 +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 ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Document; |
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
|
||||
namespace ICSharpCode.RubyBinding |
||||
{ |
||||
public class TextEditor : ITextEditor |
||||
{ |
||||
delegate string GetLineInvoker(int index); |
||||
delegate void WriteInvoker(string text, Color color); |
||||
|
||||
TextEditorControl textEditorControl; |
||||
TextArea textArea; |
||||
Color customLineColour = Color.LightGray; |
||||
TextMarker readOnlyMarker; |
||||
|
||||
CodeCompletionWindow completionWindow; |
||||
|
||||
public TextEditor(TextEditorControl textEditorControl) |
||||
{ |
||||
this.textEditorControl = textEditorControl; |
||||
this.textArea = textEditorControl.ActiveTextAreaControl.TextArea; |
||||
textEditorControl.TextEditorProperties.SupportReadOnlySegments = true; |
||||
} |
||||
|
||||
public IndentStyle IndentStyle { |
||||
get { return textEditorControl.IndentStyle; } |
||||
set { SetIndentStyle(value); } |
||||
} |
||||
|
||||
public event KeyEventHandler KeyPress { |
||||
add { textArea.KeyEventHandler += value; } |
||||
remove { textArea.KeyEventHandler -= value; } |
||||
} |
||||
|
||||
public event DialogKeyProcessor DialogKeyPress { |
||||
add { textArea.DoProcessDialogKey += value; } |
||||
remove { textArea.DoProcessDialogKey -= value; } |
||||
} |
||||
|
||||
public Color CustomLineColour { |
||||
get { return customLineColour; } |
||||
} |
||||
|
||||
public void Write(string text) |
||||
{ |
||||
Write(text, Color.Empty); |
||||
} |
||||
|
||||
public void Write(string text, Color backgroundColour) |
||||
{ |
||||
if (textEditorControl.InvokeRequired) { |
||||
WriteInvoker invoker = new WriteInvoker(Write); |
||||
textEditorControl.Invoke(invoker, new object[] {text, backgroundColour}); |
||||
} else { |
||||
int offset = textEditorControl.Document.PositionToOffset(new TextLocation(Column, Line)); |
||||
textEditorControl.ActiveTextAreaControl.TextArea.InsertString(text); |
||||
|
||||
if (!backgroundColour.IsEmpty) { |
||||
TextMarker marker = new TextMarker(offset, text.Length, TextMarkerType.SolidBlock, backgroundColour); |
||||
textEditorControl.Document.MarkerStrategy.AddMarker(marker); |
||||
textEditorControl.Refresh(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public int Column { |
||||
get { return textEditorControl.ActiveTextAreaControl.Caret.Column; } |
||||
set { textEditorControl.ActiveTextAreaControl.Caret.Column = value; } |
||||
} |
||||
|
||||
public int SelectionStart { |
||||
get { |
||||
ColumnRange range = GetSelectionRange(); |
||||
if (range != ColumnRange.NoColumn) { |
||||
return range.StartColumn; |
||||
} |
||||
return Column; |
||||
} |
||||
} |
||||
|
||||
public int SelectionLength { |
||||
get { |
||||
ColumnRange range = GetSelectionRange(); |
||||
return range.EndColumn - range.StartColumn; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current cursor line.
|
||||
/// </summary>
|
||||
public int Line { |
||||
get { return textArea.Caret.Line; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of lines in the text editor.
|
||||
/// </summary>
|
||||
public int TotalLines { |
||||
get { return textEditorControl.Document.TotalNumberOfLines; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the text for the specified line.
|
||||
/// </summary>
|
||||
public string GetLine(int index) |
||||
{ |
||||
if (textEditorControl.InvokeRequired) { |
||||
GetLineInvoker invoker = new GetLineInvoker(GetLine); |
||||
return (string)textEditorControl.Invoke(invoker, new object[] {index}); |
||||
} else { |
||||
LineSegment lineSegment = textEditorControl.Document.GetLineSegment(index); |
||||
return textEditorControl.Document.GetText(lineSegment); |
||||
} |
||||
} |
||||
|
||||
/// <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) |
||||
{ |
||||
int currentLine = textEditorControl.ActiveTextAreaControl.Caret.Line; |
||||
LineSegment lineSegment = textEditorControl.Document.GetLineSegment(currentLine); |
||||
textEditorControl.Document.Replace(lineSegment.Offset + index, length, text); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Makes the current text read only. Text can still be entered at the end.
|
||||
/// </summary>
|
||||
public void MakeCurrentContentReadOnly() |
||||
{ |
||||
IDocument doc = textEditorControl.Document; |
||||
if (readOnlyMarker == null) { |
||||
readOnlyMarker = new TextMarker(0, doc.TextLength, TextMarkerType.Invisible); |
||||
readOnlyMarker.IsReadOnly = true; |
||||
doc.MarkerStrategy.AddMarker(readOnlyMarker); |
||||
} |
||||
readOnlyMarker.Offset = 0; |
||||
readOnlyMarker.Length = doc.TextLength; |
||||
doc.UndoStack.ClearAll(); |
||||
} |
||||
|
||||
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider) |
||||
{ |
||||
completionWindow = CodeCompletionWindow.ShowCompletionWindow(textEditorControl.ParentForm, textEditorControl, String.Empty, completionDataProvider, ' '); |
||||
if (completionWindow != null) { |
||||
completionWindow.Closed += CompletionWindowClosed; |
||||
} |
||||
} |
||||
|
||||
public bool IsCompletionWindowDisplayed { |
||||
get { return completionWindow != null; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the range of the currently selected text.
|
||||
/// </summary>
|
||||
ColumnRange GetSelectionRange() |
||||
{ |
||||
return textArea.SelectionManager.GetSelectionAtLine(textArea.Caret.Line); |
||||
} |
||||
|
||||
void SetIndentStyle(IndentStyle style) |
||||
{ |
||||
if (textEditorControl.InvokeRequired) { |
||||
Action <IndentStyle> action = SetIndentStyle; |
||||
textEditorControl.Invoke(action, new object[] {style}); |
||||
} else { |
||||
textEditorControl.IndentStyle = style; |
||||
} |
||||
} |
||||
|
||||
void CompletionWindowClosed(object source, EventArgs e) |
||||
{ |
||||
if (completionWindow != null) { |
||||
completionWindow.Closed -= CompletionWindowClosed; |
||||
completionWindow.Dispose(); |
||||
completionWindow = null; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,71 +0,0 @@
@@ -1,71 +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.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
using RubyBinding.Tests.Utils; |
||||
|
||||
namespace RubyBinding.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the AddInOptions class.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AddInOptionsTestFixture |
||||
{ |
||||
[Test] |
||||
public void DefaultRubyConsoleFileName() |
||||
{ |
||||
Properties p = new Properties(); |
||||
DerivedAddInOptions options = new DerivedAddInOptions(p); |
||||
options.AddInPath = @"C:\Projects\SD\AddIns\Ruby"; |
||||
|
||||
string expectedFileName = Path.Combine(options.AddInPath, "ir.exe"); |
||||
Assert.AreEqual(expectedFileName, options.RubyFileName); |
||||
Assert.AreEqual("${addinpath:ICSharpCode.RubyBinding}", options.AddInPathRequested); |
||||
} |
||||
|
||||
[Test] |
||||
public void SetRubyConsoleFileNameToNull() |
||||
{ |
||||
Properties p = new Properties(); |
||||
DerivedAddInOptions options = new DerivedAddInOptions(p); |
||||
options.AddInPath = @"C:\Projects\SD\AddIns\Ruby"; |
||||
options.RubyFileName = null; |
||||
|
||||
string expectedFileName = Path.Combine(options.AddInPath, "ir.exe"); |
||||
Assert.AreEqual(expectedFileName, options.RubyFileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void SetRubyConsoleFileNameToEmptyString() |
||||
{ |
||||
Properties p = new Properties(); |
||||
DerivedAddInOptions options = new DerivedAddInOptions(p); |
||||
options.AddInPath = @"C:\Projects\SD\AddIns\Ruby"; |
||||
options.RubyFileName = String.Empty; |
||||
|
||||
string expectedFileName = Path.Combine(options.AddInPath, "ir.exe"); |
||||
Assert.AreEqual(expectedFileName, options.RubyFileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void SetRubyConsoleFileName() |
||||
{ |
||||
Properties p = new Properties(); |
||||
AddInOptions options = new AddInOptions(p); |
||||
string fileName = @"C:\IronRuby\ir.exe"; |
||||
options.RubyFileName = fileName; |
||||
|
||||
Assert.AreEqual(fileName, options.RubyFileName); |
||||
Assert.AreEqual(fileName, p["RubyFileName"]); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,145 @@
@@ -0,0 +1,145 @@
|
||||
// <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 NUnit.Framework; |
||||
using RubyBinding.Tests.Utils; |
||||
|
||||
namespace RubyBinding.Tests.Console |
||||
{ |
||||
[TestFixture] |
||||
public class ConsoleTextEditorTestFixture |
||||
{ |
||||
RubyConsoleTextEditor consoleTextEditor; |
||||
TextEditor avalonEditTextEditor; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
avalonEditTextEditor = new TextEditor(); |
||||
consoleTextEditor = new RubyConsoleTextEditor(avalonEditTextEditor); |
||||
} |
||||
|
||||
[Test] |
||||
public void RubyConsoleTextEditorImplementsIConsoleTextEditorInterface() |
||||
{ |
||||
Assert.IsNotNull(consoleTextEditor as IConsoleTextEditor); |
||||
} |
||||
|
||||
[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, IConsoleTextEditor 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); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
// <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 NUnit.Framework; |
||||
using RubyBinding.Tests.Utils; |
||||
using RubyBinding.Tests.Utils.Tests; |
||||
|
||||
namespace RubyBinding.Tests.Console |
||||
{ |
||||
[TestFixture] |
||||
public class ConsoleTextEditorThreadSafetyTestFixture |
||||
{ |
||||
RubyConsoleTextEditor consoleTextEditor; |
||||
TextEditor avalonEditTextEditor; |
||||
MockControlDispatcher dispatcher; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
avalonEditTextEditor = new TextEditor(); |
||||
dispatcher = new MockControlDispatcher(); |
||||
consoleTextEditor = new RubyConsoleTextEditor(avalonEditTextEditor, 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; |
||||
avalonEditTextEditor.Text = "abcd"; |
||||
|
||||
consoleTextEditor.Replace(0, 2, "12"); |
||||
Assert.IsNotNull(dispatcher.MethodInvoked); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfDispatcherCheckAccessReturnsFalseReplaceethodIsInvokedWithThreeArgs() |
||||
{ |
||||
dispatcher.CheckAccessReturnValue = false; |
||||
dispatcher.MethodInvokedArgs = null; |
||||
avalonEditTextEditor.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); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// <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.AvalonEdit.Editing; |
||||
using ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests.Console |
||||
{ |
||||
[TestFixture] |
||||
public class InsertConsoleCompletionDataTestFixture |
||||
{ |
||||
RubyConsoleCompletionData completionData; |
||||
TextEditor textEditor; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
textEditor = new TextEditor(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextInsertedAtCursor() |
||||
{ |
||||
textEditor.Text = "abc.n"; |
||||
textEditor.CaretOffset = 4; |
||||
|
||||
int startOffset = 4; |
||||
int endOffset = 5; |
||||
SimpleSelection selection = new SimpleSelection(startOffset, endOffset); |
||||
|
||||
completionData = new RubyConsoleCompletionData("new"); |
||||
completionData.Complete(textEditor.TextArea, selection, null); |
||||
|
||||
string expectedText = |
||||
"abc.new"; |
||||
|
||||
Assert.AreEqual(expectedText, textEditor.Text); |
||||
} |
||||
} |
||||
} |
||||
@ -1,402 +0,0 @@
@@ -1,402 +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.Threading; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Document; |
||||
using ICSharpCode.RubyBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests.Console |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the TextEditor class.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class TextEditorTestFixture |
||||
{ |
||||
TextEditorControl textEditorControl; |
||||
TextEditor textEditor; |
||||
IndentStyle defaultTextEditorControlIndentStyle; |
||||
IndentStyle defaultTextEditorIndentStyle; |
||||
char keyPressed = ' '; |
||||
Keys dialogKeyPressed; |
||||
Exception indentException; |
||||
Exception getLineException; |
||||
string lineReadOnDifferentThread = null; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
textEditorControl = new TextEditorControl(); |
||||
|
||||
// Force creation of handle otherwise InvokeRequired always returns false.
|
||||
textEditorControl.CreateControl(); |
||||
|
||||
textEditorControl.IndentStyle = IndentStyle.Smart; |
||||
defaultTextEditorControlIndentStyle = textEditorControl.IndentStyle; |
||||
|
||||
textEditor = new TextEditor(textEditorControl); |
||||
defaultTextEditorIndentStyle = textEditor.IndentStyle; |
||||
} |
||||
|
||||
[TestFixtureTearDown] |
||||
public void TearDownFixture() |
||||
{ |
||||
textEditorControl.Dispose(); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultTextEditorIndentStyleSameAsTextEditorControl() |
||||
{ |
||||
Assert.AreEqual(defaultTextEditorControlIndentStyle, defaultTextEditorIndentStyle); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorImplementsITextEditorInterface() |
||||
{ |
||||
Assert.IsNotNull(textEditor as ITextEditor); |
||||
} |
||||
|
||||
[Test] |
||||
public void IndentStyleUpdatesTextEditor() |
||||
{ |
||||
textEditor.IndentStyle = IndentStyle.None; |
||||
Assert.AreEqual(IndentStyle.None, textEditorControl.IndentStyle); |
||||
} |
||||
|
||||
[Test] |
||||
public void KeyPressEventHandlerImplemented() |
||||
{ |
||||
textEditor.KeyPress += ProcessKeyPress; |
||||
try { |
||||
textEditorControl.ActiveTextAreaControl.TextArea.SimulateKeyPress('a'); |
||||
Assert.AreEqual('a', keyPressed); |
||||
} finally { |
||||
textEditor.KeyPress -= ProcessKeyPress; |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void KeyPressEventHandlerRemoved() |
||||
{ |
||||
keyPressed = ' '; |
||||
textEditor.KeyPress += ProcessKeyPress; |
||||
textEditor.KeyPress -= ProcessKeyPress; |
||||
textEditorControl.ActiveTextAreaControl.TextArea.SimulateKeyPress('b'); |
||||
|
||||
Assert.AreEqual(' ', keyPressed); |
||||
} |
||||
|
||||
[Test] |
||||
public void DialogKeyPressEventHandlerImplemented() |
||||
{ |
||||
textEditor.DialogKeyPress += ProcessDialogKeyPress; |
||||
try { |
||||
textEditorControl.ActiveTextAreaControl.TextArea.ExecuteDialogKey(Keys.B); |
||||
Assert.AreEqual(dialogKeyPressed, Keys.B); |
||||
} finally { |
||||
textEditor.DialogKeyPress -= ProcessDialogKeyPress; |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void DialogKeyPressEventHandlerRemoved() |
||||
{ |
||||
dialogKeyPressed = Keys.Enter; |
||||
textEditor.DialogKeyPress += ProcessDialogKeyPress; |
||||
textEditor.DialogKeyPress -= ProcessDialogKeyPress; |
||||
textEditorControl.ActiveTextAreaControl.TextArea.ExecuteDialogKey(Keys.Alt); |
||||
|
||||
Assert.AreEqual(Keys.Enter, dialogKeyPressed); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeCurrentTextEditorContent() |
||||
{ |
||||
textEditorControl.Text = String.Empty; |
||||
textEditor.Write("abc" + Environment.NewLine); |
||||
textEditor.MakeCurrentContentReadOnly(); |
||||
|
||||
TextMarker readOnlyTextMarker = GetReadOnlyTextMarker(textEditorControl); |
||||
Assert.IsNotNull(readOnlyTextMarker); |
||||
Assert.AreEqual(0, readOnlyTextMarker.Offset); |
||||
Assert.AreEqual(textEditorControl.Text.Length, readOnlyTextMarker.Length); |
||||
Assert.IsFalse(textEditorControl.Document.UndoStack.CanUndo); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteMethodUpdatesTextEditor() |
||||
{ |
||||
textEditorControl.Document.TextContent = String.Empty; |
||||
textEditor.Write("abc"); |
||||
Assert.AreEqual("abc", textEditorControl.Document.TextContent); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteOnDifferentThread() |
||||
{ |
||||
textEditorControl.Document.TextContent = String.Empty; |
||||
Thread t = new Thread(WriteText); |
||||
t.Start(); |
||||
|
||||
// Make sure the GUI events are processed otherwise the
|
||||
// unit test will never complete.
|
||||
int maxWait = 2000; |
||||
int currentWait = 0; |
||||
int sleepInterval = 50; |
||||
Application.DoEvents(); |
||||
while (textEditorControl.Text.Length == 0 && (currentWait < maxWait)) { |
||||
Application.DoEvents(); |
||||
Thread.Sleep(sleepInterval); |
||||
currentWait += sleepInterval; |
||||
} |
||||
|
||||
// Wait for thread to finish.
|
||||
t.Join(); |
||||
|
||||
Assert.AreEqual("test", textEditorControl.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void SetIndentStyleOnDifferentThread() |
||||
{ |
||||
textEditorControl.IndentStyle = IndentStyle.Auto; |
||||
Thread t = new Thread(SetIndentStyle); |
||||
t.Start(); |
||||
|
||||
// Make sure the GUI events are processed otherwise the
|
||||
// unit test will never complete.
|
||||
int maxWait = 2000; |
||||
int currentWait = 0; |
||||
int sleepInterval = 50; |
||||
Application.DoEvents(); |
||||
while (textEditorControl.IndentStyle == IndentStyle.Auto && (currentWait < maxWait)) { |
||||
Application.DoEvents(); |
||||
Thread.Sleep(sleepInterval); |
||||
currentWait += sleepInterval; |
||||
} |
||||
|
||||
// Wait for thread to finish.
|
||||
t.Join(); |
||||
|
||||
string message = String.Empty; |
||||
if (indentException != null) { |
||||
message = indentException.ToString(); |
||||
} |
||||
Assert.IsNull(indentException, message); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetColumnPosition() |
||||
{ |
||||
textEditorControl.Document.TextContent = "test"; |
||||
textEditorControl.ActiveTextAreaControl.TextArea.Caret.Column = 2; |
||||
|
||||
Assert.AreEqual(2, textEditor.Column); |
||||
} |
||||
|
||||
[Test] |
||||
public void SetColumnPosition() |
||||
{ |
||||
textEditorControl.Document.TextContent = "test"; |
||||
textEditorControl.ActiveTextAreaControl.TextArea.Caret.Column = 2; |
||||
|
||||
textEditor.Column = 1; |
||||
Assert.AreEqual(1, textEditorControl.ActiveTextAreaControl.TextArea.Caret.Column); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetSelectionStartAndLength() |
||||
{ |
||||
textEditorControl.Document.TextContent = "te000xt"; |
||||
TextLocation start = new TextLocation(2, 0); |
||||
TextLocation end = new TextLocation(5, 0); |
||||
textEditorControl.ActiveTextAreaControl.SelectionManager.SetSelection(start, end); |
||||
|
||||
// Sanity check.
|
||||
Assert.AreEqual("000", textEditorControl.ActiveTextAreaControl.SelectionManager.SelectedText); |
||||
|
||||
Assert.AreEqual(2, textEditor.SelectionStart); |
||||
Assert.AreEqual(3, textEditor.SelectionLength); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetSelectionStartAndLengthWhenNothingSelected() |
||||
{ |
||||
textEditorControl.Document.TextContent = "text"; |
||||
textEditorControl.ActiveTextAreaControl.SelectionManager.ClearSelection(); |
||||
textEditorControl.ActiveTextAreaControl.Caret.Column = 1; |
||||
|
||||
Assert.AreEqual(1, textEditor.SelectionStart); |
||||
Assert.AreEqual(0, textEditor.SelectionLength); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorLineEqualsCaretLine() |
||||
{ |
||||
textEditorControl.Document.TextContent = "abc\r\ndef"; |
||||
textEditorControl.ActiveTextAreaControl.Caret.Line = 0; |
||||
|
||||
Assert.AreEqual(0, textEditor.Line); |
||||
|
||||
textEditorControl.ActiveTextAreaControl.Caret.Line = 1; |
||||
Assert.AreEqual(1, textEditor.Line); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorTotalLines() |
||||
{ |
||||
textEditorControl.Document.TextContent = "abc\r\ndef\r\nghi"; |
||||
Assert.AreEqual(3, textEditor.TotalLines); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetFirstLine() |
||||
{ |
||||
textEditorControl.Document.TextContent = "abc\r\ndef\r\nghi"; |
||||
Assert.AreEqual("abc", textEditor.GetLine(0)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetLineOnDifferentThread() |
||||
{ |
||||
textEditorControl.IndentStyle = IndentStyle.Auto; |
||||
Thread t = new Thread(GetLine); |
||||
t.Start(); |
||||
|
||||
// Make sure the GUI events are processed otherwise the
|
||||
// unit test will never complete.
|
||||
int maxWait = 2000; |
||||
int currentWait = 0; |
||||
int sleepInterval = 50; |
||||
Application.DoEvents(); |
||||
while (lineReadOnDifferentThread == null && (currentWait < maxWait)) { |
||||
Application.DoEvents(); |
||||
Thread.Sleep(sleepInterval); |
||||
currentWait += sleepInterval; |
||||
} |
||||
|
||||
// Wait for thread to finish.
|
||||
t.Join(); |
||||
|
||||
string message = String.Empty; |
||||
if (getLineException != null) { |
||||
message = getLineException.ToString(); |
||||
} |
||||
Assert.IsNull(getLineException, message); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteTextWithBackgroundColour() |
||||
{ |
||||
textEditorControl.Document.TextContent = "abc\r\n>>>"; |
||||
textEditorControl.ActiveTextAreaControl.Caret.Line = 1; |
||||
textEditor.Write(">>> ", Color.Blue); |
||||
|
||||
int offset = textEditorControl.Document.PositionToOffset(new TextLocation(0, 1)); |
||||
List<TextMarker> markers = textEditorControl.Document.MarkerStrategy.GetMarkers(offset); |
||||
TextMarker marker = markers[0]; |
||||
Assert.AreEqual(Color.Blue, marker.Color); |
||||
Assert.AreEqual(TextMarkerType.SolidBlock, marker.TextMarkerType); |
||||
Assert.AreEqual(4, marker.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void SupportReadOnlySegmentsIsTrue() |
||||
{ |
||||
Assert.IsTrue(textEditorControl.TextEditorProperties.SupportReadOnlySegments); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReplaceText() |
||||
{ |
||||
textEditorControl.Document.TextContent = "abc\r\ndef"; |
||||
textEditorControl.ActiveTextAreaControl.Caret.Line = 1; |
||||
|
||||
textEditor.Replace(1, 1, "test"); |
||||
Assert.AreEqual("abc\r\ndtestf", textEditorControl.Document.TextContent); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Run on different thread to set the text editor's indent style.
|
||||
/// </summary>
|
||||
void SetIndentStyle() |
||||
{ |
||||
try { |
||||
textEditor.IndentStyle = IndentStyle.None; |
||||
} catch (Exception ex) { |
||||
indentException = ex; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Run on different thread to set the text editor's indent style.
|
||||
/// </summary>
|
||||
void GetLine() |
||||
{ |
||||
try { |
||||
lineReadOnDifferentThread = textEditor.GetLine(0); |
||||
} catch (Exception ex) { |
||||
getLineException = ex; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Run on different thread to write text to the text editor.
|
||||
/// </summary>
|
||||
void WriteText() |
||||
{ |
||||
try { |
||||
textEditor.Write("test"); |
||||
} catch (Exception ex) { |
||||
System.Console.WriteLine("WriteText error: " + ex.ToString()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Event handler for the text editor's DialogKeyPress event.
|
||||
/// </summary>
|
||||
bool ProcessDialogKeyPress(Keys keysData) |
||||
{ |
||||
dialogKeyPressed = keysData; |
||||
return true; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Event handler for the text editor's KeyPress event.
|
||||
/// </summary>
|
||||
bool ProcessKeyPress(char ch) |
||||
{ |
||||
keyPressed = ch; |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Used to remove all text markers from the text editor.
|
||||
/// </summary>
|
||||
bool AllMarkersMatch(TextMarker marker) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
TextMarker GetReadOnlyTextMarker(TextEditorControl textEditorControl) |
||||
{ |
||||
foreach (TextMarker marker in textEditorControl.Document.MarkerStrategy.TextMarker) { |
||||
if (marker.IsReadOnly) { |
||||
return marker; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// <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; |
||||
using NUnit.Framework; |
||||
|
||||
namespace RubyBinding.Tests.RubyLanguage |
||||
{ |
||||
[TestFixture] |
||||
public class RubyLanguageBindingTestFixture |
||||
{ |
||||
RubyLanguageBinding languageBinding; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
languageBinding = new RubyLanguageBinding(); |
||||
} |
||||
|
||||
[Test] |
||||
public void FormattingStrategyIsRubyFormattingStrategy() |
||||
{ |
||||
Assert.IsInstanceOf(typeof(RubyFormattingStrategy), languageBinding.FormattingStrategy); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplementsILanguageBinding() |
||||
{ |
||||
Assert.IsNotNull(languageBinding as ILanguageBinding); |
||||
} |
||||
|
||||
[Test] |
||||
public void LanguagePropertiesIsRubyLanguageProperties() |
||||
{ |
||||
Assert.IsInstanceOf(typeof(RubyLanguageProperties), languageBinding.Properties); |
||||
} |
||||
} |
||||
} |
||||
@ -1,52 +0,0 @@
@@ -1,52 +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.Core; |
||||
using ICSharpCode.RubyBinding; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Overrides the AddInOptions GetAddInPath method to return
|
||||
/// some dummy data used for testing.
|
||||
/// </summary>
|
||||
public class DerivedAddInOptions : AddInOptions |
||||
{ |
||||
string addInPath = String.Empty; |
||||
string addInPathRequested = String.Empty; |
||||
|
||||
public DerivedAddInOptions(Properties properties) : base(properties) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the addin path string passed to the GetAddInPath method.
|
||||
/// </summary>
|
||||
public string AddInPathRequested { |
||||
get { return addInPathRequested; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the addin path that should be returned from the
|
||||
/// GetAddInPath method.
|
||||
/// </summary>
|
||||
public string AddInPath { |
||||
get { return addInPath; } |
||||
set { addInPath = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns our dummy AddInPath.
|
||||
/// </summary>
|
||||
protected override string GetAddInPath(string addIn) |
||||
{ |
||||
addInPathRequested = addIn; |
||||
return addInPath; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// <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.RubyBinding; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockConsoleTextEditorKeyEventArgs : ConsoleTextEditorKeyEventArgs |
||||
{ |
||||
bool handled; |
||||
|
||||
public MockConsoleTextEditorKeyEventArgs(Key key) |
||||
: base(key) |
||||
{ |
||||
} |
||||
|
||||
public override bool Handled { |
||||
get { return handled; } |
||||
set { handled = value; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
// <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.Tests |
||||
{ |
||||
public class MockControlDispatcher : IControlDispatcher |
||||
{ |
||||
Delegate methodInvoked; |
||||
object[] methodInvokedArgs; |
||||
bool checkAccessReturnValue; |
||||
|
||||
public MockControlDispatcher() |
||||
{ |
||||
} |
||||
|
||||
public bool CheckAccess() |
||||
{ |
||||
return checkAccessReturnValue; |
||||
} |
||||
|
||||
public bool CheckAccessReturnValue { |
||||
get { return checkAccessReturnValue; } |
||||
set { checkAccessReturnValue = value; } |
||||
} |
||||
|
||||
public object Invoke(Delegate method, params object[] args) |
||||
{ |
||||
methodInvoked = method; |
||||
methodInvokedArgs = args; |
||||
return null; |
||||
} |
||||
|
||||
public Delegate MethodInvoked { |
||||
get { return methodInvoked; } |
||||
set { methodInvoked = null; } |
||||
} |
||||
|
||||
public object[] MethodInvokedArgs { |
||||
get { return methodInvokedArgs; } |
||||
set { methodInvokedArgs = value; } |
||||
} |
||||
} |
||||
} |
||||
@ -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 System.Windows.Input; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockKeyboardDevice : KeyboardDevice |
||||
{ |
||||
public MockKeyboardDevice() |
||||
: base(InputManager.Current) |
||||
{ |
||||
} |
||||
|
||||
protected override KeyStates GetKeyStatesFromSystem(Key key) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
// <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; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockPresentationSource : PresentationSource |
||||
{ |
||||
public MockPresentationSource() |
||||
{ |
||||
} |
||||
|
||||
public override Visual RootVisual { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public override bool IsDisposed { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
protected override CompositionTarget GetCompositionTargetCore() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,138 @@
@@ -0,0 +1,138 @@
|
||||
// <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.SharpDevelop.Editor; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockTextEditor : ITextEditor |
||||
{ |
||||
ITextEditorOptions options; |
||||
|
||||
public MockTextEditor() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler SelectionChanged; |
||||
|
||||
protected virtual void OnSelectionChanged(EventArgs e) |
||||
{ |
||||
if (SelectionChanged != null) { |
||||
SelectionChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event KeyEventHandler KeyPress; |
||||
|
||||
protected virtual void OnKeyPress(KeyEventArgs e) |
||||
{ |
||||
if (KeyPress != null) { |
||||
KeyPress(this, e); |
||||
} |
||||
} |
||||
|
||||
public ITextEditor PrimaryView { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IDocument Document { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ITextEditorCaret Caret { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ITextEditorOptions Options { |
||||
get { return options; } |
||||
set { options = value; } |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.ILanguageBinding Language { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int SelectionStart { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int SelectionLength { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string SelectedText { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICSharpCode.Core.FileName FileName { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.Editor.CodeCompletion.ICompletionListWindow ActiveCompletionWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.Editor.CodeCompletion.IInsightWindow ActiveInsightWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public void Select(int selectionStart, int selectionLength) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void JumpTo(int line, int column) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.Editor.CodeCompletion.ICompletionListWindow ShowCompletionWindow(ICSharpCode.SharpDevelop.Editor.CodeCompletion.ICompletionItemList data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.Editor.CodeCompletion.IInsightWindow ShowInsightWindow(System.Collections.Generic.IEnumerable<ICSharpCode.SharpDevelop.Editor.CodeCompletion.IInsightItem> items) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public System.Collections.Generic.IEnumerable<ICSharpCode.SharpDevelop.Editor.CodeCompletion.ICompletionItem> GetSnippets() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object GetService(Type serviceType) |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// <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.SharpDevelop.Editor; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockTextEditorOptions : TextEditorOptions, ITextEditorOptions |
||||
{ |
||||
public MockTextEditorOptions() |
||||
{ |
||||
} |
||||
|
||||
public bool AutoInsertBlockEnd { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int VerticalRulerColumn { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool UnderlineErrors { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -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.Drawing; |
||||
using System.Drawing.Text; |
||||
using System.Text; |
||||
using ICSharpCode.TextEditor.Document; |
||||
|
||||
namespace RubyBinding.Tests.Utils |
||||
{ |
||||
public class MockTextEditorProperties : ITextEditorProperties |
||||
{ |
||||
public MockTextEditorProperties() |
||||
{ |
||||
FontContainer = new FontContainer(SystemFonts.MenuFont); |
||||
} |
||||
|
||||
public bool CaretLine { get; set; } |
||||
|
||||
public bool AutoInsertCurlyBracket { get; set; } |
||||
|
||||
public bool HideMouseCursor { get; set; } |
||||
|
||||
public bool IsIconBarVisible { get; set; } |
||||
|
||||
public bool AllowCaretBeyondEOL { get; set; } |
||||
|
||||
public bool ShowMatchingBracket { get; set; } |
||||
|
||||
public bool CutCopyWholeLine { get; set; } |
||||
|
||||
public TextRenderingHint TextRenderingHint { get; set; } |
||||
|
||||
public bool MouseWheelScrollDown { get; set; } |
||||
|
||||
public bool MouseWheelTextZoom { get; set; } |
||||
|
||||
public string LineTerminator { get; set; } |
||||
|
||||
public LineViewerStyle LineViewerStyle { get; set; } |
||||
|
||||
public bool ShowInvalidLines { get; set; } |
||||
|
||||
public int VerticalRulerRow { get; set; } |
||||
|
||||
public bool ShowSpaces { get; set; } |
||||
|
||||
public bool ShowTabs { get; set; } |
||||
|
||||
public bool ShowEOLMarker { get; set; } |
||||
|
||||
public bool ConvertTabsToSpaces { get; set; } |
||||
|
||||
public bool ShowHorizontalRuler { get; set; } |
||||
|
||||
public bool ShowVerticalRuler { get; set; } |
||||
|
||||
public Encoding Encoding { get; set; } |
||||
|
||||
public bool EnableFolding{ get; set; } |
||||
|
||||
public bool ShowLineNumbers { get; set; } |
||||
|
||||
public int TabIndent { get; set; } |
||||
|
||||
public int IndentationSize { get; set; } |
||||
|
||||
public IndentStyle IndentStyle{ get; set; } |
||||
|
||||
public DocumentSelectionMode DocumentSelectionMode { get; set; } |
||||
|
||||
public Font Font { get; set; } |
||||
|
||||
public FontContainer FontContainer { get; set; } |
||||
|
||||
public BracketMatchingStyle BracketMatchingStyle { get; set; } |
||||
|
||||
public bool SupportReadOnlySegments { get; set; } |
||||
} |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue