Browse Source

Added initial code completion support for the Python Console window.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3561 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
01571affa4
  1. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 22
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IMemberProvider.cs
  3. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs
  4. 39
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs
  5. 75
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleCompletionDataProvider.cs
  6. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleHost.cs
  7. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs
  8. 94
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/BuiltinCodeCompletionTestFixture.cs
  9. 74
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CodeCompletionTests.cs
  10. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DerivedPythonConsoleHost.cs
  11. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs
  12. 80
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockMemberProvider.cs
  13. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs
  14. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs
  15. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCurrentLineTestFixture.cs
  16. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleEnterKeyTestFixture.cs
  17. 11
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleHostTests.cs
  18. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs
  19. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs
  20. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleUnreadLinesTestFixture.cs
  21. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleWriteTestFixture.cs
  22. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TwoPythonConsoleLinesWaitingTestFixture.cs
  23. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -69,6 +69,7 @@ @@ -69,6 +69,7 @@
<Compile Include="Src\CompilingOptionsPanel.cs" />
<Compile Include="Src\CSharpToPythonConverter.cs" />
<Compile Include="Src\GeneratedInitializeComponentMethod.cs" />
<Compile Include="Src\IMemberProvider.cs" />
<Compile Include="Src\IPadDescriptor.cs" />
<Compile Include="Src\IProcessRunner.cs" />
<Compile Include="Src\IsPythonRunningCondition.cs" />
@ -79,6 +80,7 @@ @@ -79,6 +80,7 @@
<Compile Include="Src\PythonCompilerError.cs" />
<Compile Include="Src\PythonCompilerSink.cs" />
<Compile Include="Src\PythonConsole.cs" />
<Compile Include="Src\PythonConsoleCompletionDataProvider.cs" />
<Compile Include="Src\PythonConsoleHost.cs" />
<Compile Include="Src\PythonConsolePad.cs" />
<Compile Include="Src\PythonDesignerCodeDomGenerator.cs" />

22
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IMemberProvider.cs

@ -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 System.Collections.Generic;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Returns member names or global names for the python console command line.
/// </summary>
public interface IMemberProvider
{
IList<string> GetMemberNames(string name);
IList<string> GetGlobals(string name);
}
}

3
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs

@ -10,6 +10,7 @@ using System.Drawing; @@ -10,6 +10,7 @@ using System.Drawing;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
namespace ICSharpCode.PythonBinding
{
@ -86,7 +87,7 @@ namespace ICSharpCode.PythonBinding @@ -86,7 +87,7 @@ namespace ICSharpCode.PythonBinding
/// <summary>
/// Shows the code completion window.
/// </summary>
void ShowCompletionWindow();
void ShowCompletionWindow(ICompletionDataProvider completionDataProvider);
/// <summary>
/// Makes the current text content read only. Text can be entered at the end.

39
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs

@ -19,7 +19,7 @@ using Microsoft.Scripting.Hosting.Shell; @@ -19,7 +19,7 @@ using Microsoft.Scripting.Hosting.Shell;
namespace ICSharpCode.PythonBinding
{
public class PythonConsole : IConsole, IDisposable
public class PythonConsole : IConsole, IDisposable, IMemberProvider
{
ITextEditor textEditor;
int lineReceivedEventIndex = 0; // The index into the waitHandles array where the lineReceivedEvent is stored.
@ -28,11 +28,14 @@ namespace ICSharpCode.PythonBinding @@ -28,11 +28,14 @@ namespace ICSharpCode.PythonBinding
WaitHandle[] waitHandles;
int promptLength;
List<string> previousLines = new List<string>();
CommandLine commandLine;
public PythonConsole(ITextEditor textEditor)
public PythonConsole(ITextEditor textEditor, CommandLine commandLine)
{
waitHandles = new WaitHandle[] {lineReceivedEvent, disposedEvent};
this.commandLine = commandLine;
this.textEditor = textEditor;
textEditor.KeyPress += ProcessKeyPress;
textEditor.DialogKeyPress += ProcessDialogKeyPress;
@ -67,6 +70,19 @@ namespace ICSharpCode.PythonBinding @@ -67,6 +70,19 @@ namespace ICSharpCode.PythonBinding
}
}
/// <summary>
/// Gets the member names of the specified item.
/// </summary>
public IList<string> GetMemberNames(string name)
{
return commandLine.GetMemberNames(name);
}
public IList<string> GetGlobals(string name)
{
return commandLine.GetGlobals(name);
}
/// <summary>
/// Returns the next line typed in by the console user. If no line is available this method
/// will block.
@ -89,6 +105,9 @@ namespace ICSharpCode.PythonBinding @@ -89,6 +105,9 @@ namespace ICSharpCode.PythonBinding
return null;
}
/// <summary>
/// Writes text to the console.
/// </summary>
public void Write(string text, Style style)
{
Console.WriteLine("PythonConsole.Write(text, style): " + text);
@ -101,11 +120,17 @@ namespace ICSharpCode.PythonBinding @@ -101,11 +120,17 @@ namespace ICSharpCode.PythonBinding
}
}
/// <summary>
/// Writes text followed by a newline to the console.
/// </summary>
public void WriteLine(string text, Style style)
{
Write(text + Environment.NewLine, style);
}
/// <summary>
/// Writes an empty line to the console.
/// </summary>
public void WriteLine()
{
Write(Environment.NewLine, Style.Out);
@ -174,6 +199,10 @@ namespace ICSharpCode.PythonBinding @@ -174,6 +199,10 @@ namespace ICSharpCode.PythonBinding
if (ch == '\n') {
OnEnterKeyPressed();
}
if (ch == '.') {
ShowCompletionWindow();
}
return false;
}
@ -248,5 +277,11 @@ namespace ICSharpCode.PythonBinding @@ -248,5 +277,11 @@ namespace ICSharpCode.PythonBinding
return cursorIndex > 0 && selectionStartIndex > 0;
}
}
void ShowCompletionWindow()
{
PythonConsoleCompletionDataProvider completionProvider = new PythonConsoleCompletionDataProvider(this);
textEditor.ShowCompletionWindow(completionProvider);
}
}
}

75
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleCompletionDataProvider.cs

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
// <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.Windows.Forms;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Provides code completion for the Python Console window.
/// </summary>
public class PythonConsoleCompletionDataProvider : AbstractCompletionDataProvider
{
IMemberProvider memberProvider;
public PythonConsoleCompletionDataProvider(IMemberProvider memberProvider)
{
this.memberProvider = memberProvider;
DefaultIndex = 0;
}
public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
{
return GenerateCompletionData(GetLineText(textArea));
}
/// <summary>
/// Generates completion data for the specified text. The text should be everything before
/// the dot character that triggered the completion. The text can contain the command line prompt
/// '>>>' as this will be ignored.
/// </summary>
public ICompletionData[] GenerateCompletionData(string line)
{
List<DefaultCompletionData> items = new List<DefaultCompletionData>();
string name = GetName(line);
if (!String.IsNullOrEmpty(name)) {
try {
foreach (string member in memberProvider.GetMemberNames(name)) {
items.Add(new DefaultCompletionData(member, String.Empty, ClassBrowserIconService.MethodIndex));
}
} catch {
// Do nothing.
}
}
return items.ToArray();
}
string GetName(string text)
{
int startIndex = text.LastIndexOf(' ');
return text.Substring(startIndex + 1);
}
/// <summary>
/// Gets the line of text up to the cursor position.
/// </summary>
string GetLineText(TextArea textArea)
{
LineSegment lineSegment = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
return textArea.Document.GetText(lineSegment);
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleHost.cs

@ -73,7 +73,7 @@ namespace ICSharpCode.PythonBinding @@ -73,7 +73,7 @@ namespace ICSharpCode.PythonBinding
protected override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options)
{
SetOutput(new PythonOutputStream(textEditor));
pythonConsole = new PythonConsole(textEditor);
pythonConsole = new PythonConsole(textEditor, commandLine);
return pythonConsole;
}

18
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs

@ -10,6 +10,7 @@ using System.Drawing; @@ -10,6 +10,7 @@ using System.Drawing;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
namespace ICSharpCode.PythonBinding
{
@ -22,6 +23,8 @@ namespace ICSharpCode.PythonBinding @@ -22,6 +23,8 @@ namespace ICSharpCode.PythonBinding
TextArea textArea;
Color customLineColour = Color.LightGray;
TextMarker readOnlyMarker;
CodeCompletionWindow completionWindow;
public TextEditor(TextEditorControl textEditorControl)
{
@ -137,8 +140,12 @@ namespace ICSharpCode.PythonBinding @@ -137,8 +140,12 @@ namespace ICSharpCode.PythonBinding
doc.UndoStack.ClearAll();
}
public void ShowCompletionWindow()
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider)
{
completionWindow = CodeCompletionWindow.ShowCompletionWindow(textEditorControl.ParentForm, textEditorControl, String.Empty, completionDataProvider, ' ');
if (completionWindow != null) {
completionWindow.Closed += CompletionWindowClosed;
}
}
/// <summary>
@ -158,5 +165,14 @@ namespace ICSharpCode.PythonBinding @@ -158,5 +165,14 @@ namespace ICSharpCode.PythonBinding
textEditorControl.IndentStyle = style;
}
}
void CompletionWindowClosed(object source, EventArgs e)
{
if (completionWindow != null) {
completionWindow.Closed -= CompletionWindowClosed;
completionWindow.Dispose();
completionWindow = null;
}
}
}
}

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

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
// <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 Microsoft.Scripting.Hosting;
using ICSharpCode.PythonBinding;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using NUnit.Framework;
namespace PythonBinding.Tests.Console
{
/// <summary>
/// Tests the code completion when the user has typed in __builtins__.
/// </summary>
[TestFixture]
public class BuiltinCodeCompletionTestFixture
{
ICompletionData[] completionItems;
ICompletionData[] expectedCompletionItems;
PythonConsoleCompletionDataProvider provider;
MockMemberProvider memberProvider;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (TextEditorControl textEditorControl = new TextEditorControl()) {
textEditorControl.Text = ">>> __builtins__";
TextEditor textEditor = new TextEditor(textEditorControl);
memberProvider = new MockMemberProvider();
memberProvider.SetMemberNames(new string[] {"a", "b", "c"});
expectedCompletionItems = CreateCompletionItems(memberProvider.GetMemberNames("__builtins__"));
provider = new PythonConsoleCompletionDataProvider(memberProvider);
completionItems = provider.GenerateCompletionData(String.Empty, textEditorControl.ActiveTextAreaControl.TextArea, '.');
}
}
[Test]
public void MoreThanOneCompletionItem()
{
Assert.IsTrue(completionItems.Length > 0);
}
[Test]
public void ExpectedCompletionItems()
{
for (int i = 0; i < expectedCompletionItems.Length; ++i) {
Assert.AreEqual(expectedCompletionItems[i].Text, completionItems[i].Text);
}
}
[Test]
public void ExpectedCompletionItemsCountEqualsActualCompletionItemsCount()
{
Assert.AreEqual(expectedCompletionItems.Length, completionItems.Length);
}
[Test]
public void PreSelectionIsNull()
{
Assert.IsNull(provider.PreSelection);
}
[Test]
public void DefaultIndexIsZero()
{
Assert.AreEqual(0, provider.DefaultIndex);
}
[Test]
public void BuiltinsPassedToMemberProvider()
{
Assert.AreEqual("__builtins__", memberProvider.GetMemberNamesParameter);
}
ICompletionData[] CreateCompletionItems(IList<string> memberNames)
{
List<DefaultCompletionData> items = new List<DefaultCompletionData>();
foreach (string memberName in memberNames) {
items.Add(new DefaultCompletionData(memberName, String.Empty, 0));
}
return items.ToArray();
}
}
}

74
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/CodeCompletionTests.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
// <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.PythonBinding;
using ICSharpCode.SharpDevelop;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using NUnit.Framework;
namespace PythonBinding.Tests.Console
{
[TestFixture]
public class EmptyStringCodeCompletionTestFixture
{
MockMemberProvider memberProvider;
PythonConsoleCompletionDataProvider completionProvider;
[SetUp]
public void Init()
{
memberProvider = new MockMemberProvider();
completionProvider = new PythonConsoleCompletionDataProvider(memberProvider);
}
/// <summary>
/// If the user presses the dot character without having any text in the command line then
/// a SyntaxException occurs if the code calls IronPython's CommandLine.GetMemberNames. So this
/// tests ensures that if the string is empty then this method is not called.
/// </summary>
[Test]
public void NoCompletionItemsGeneratedForEmptyString()
{
memberProvider.SetMemberNames(new string[] {"a"});
memberProvider.SetGlobals(new string[] {"a"});
Assert.AreEqual(0, completionProvider.GenerateCompletionData(">>> ").Length);
}
/// <summary>
/// Checks that the GenerateCompletionData method catches any exceptions thrown by the
/// IMemberProvider implementation. This can occur when an invalid name is passed to
/// IronPython's CommandLine.GetMemberNames or GetGlobals. For example, an UnboundNameException is
/// thrown if an unknown name is used.
/// </summary>
[Test]
public void NoCompletionItemsGeneratedWhenExceptionThrown()
{
memberProvider.ExceptionToThrow = new ApplicationException("Should not be thrown");
Assert.AreEqual(0, completionProvider.GenerateCompletionData(">>> a").Length);
}
[Test]
public void ImageIndexIsMethod()
{
memberProvider.SetMemberNames(new string[] {"a"});
ICompletionData[] items = completionProvider.GenerateCompletionData(">>> a");
Assert.AreEqual(ClassBrowserIconService.MethodIndex, items[0].ImageIndex);
}
[Test]
public void UnderscoresPassedToGetMemberNames()
{
completionProvider.GenerateCompletionData(">>> __builtins__");
Assert.AreEqual("__builtins__", memberProvider.GetMemberNamesParameter);
}
}
}

10
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DerivedPythonConsoleHost.cs

@ -45,15 +45,7 @@ namespace PythonBinding.Tests.Console @@ -45,15 +45,7 @@ namespace PythonBinding.Tests.Console
{
return base.CreateOptionsParser();
}
/// <summary>
/// Script engine to return from base.CreateEngine(Type context).
/// </summary>
public ScriptEngine ScriptEngineToReturn {
get { return engine; }
set { engine = value; }
}
/// <summary>
/// Context type passed to base.CreateEngine(Type context).
/// </summary>

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/DisposedPythonConsoleTestFixture.cs

@ -20,14 +20,14 @@ namespace PythonBinding.Tests.Console @@ -20,14 +20,14 @@ namespace PythonBinding.Tests.Console
[Test]
public void PythonConsoleImplementsIDisposable()
{
PythonConsole console = new PythonConsole(new MockTextEditor());
PythonConsole console = new PythonConsole(new MockTextEditor(), null);
Assert.IsNotNull(console as IDisposable);
}
[Test]
public void ReadLineReturnsNullWhenConsoleDisposed()
{
PythonConsole console = new PythonConsole(new MockTextEditor());
PythonConsole console = new PythonConsole(new MockTextEditor(), null);
console.Dispose();
Assert.IsNull(console.ReadLine(0));
}

80
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockMemberProvider.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// <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.PythonBinding;
namespace PythonBinding.Tests.Console
{
public class MockMemberProvider : IMemberProvider
{
List<string> memberNames = new List<string>();
string getMemberNamesParameter;
List<string> globals = new List<string>();
string getGlobalsParameter;
Exception exceptionToThrow;
public MockMemberProvider()
{
}
/// <summary>
/// Exception that will be thrown if the GetMemberNames method or GetGlobals method is called.
/// </summary>
public Exception ExceptionToThrow {
get { return exceptionToThrow; }
set { exceptionToThrow = value; }
}
public void SetMemberNames(string[] names)
{
memberNames.AddRange(names);
}
public IList<string> GetMemberNames(string name)
{
getMemberNamesParameter = name;
if (exceptionToThrow != null) {
throw exceptionToThrow;
}
return memberNames;
}
public void SetGlobals(string[] names)
{
globals.AddRange(names);
}
public IList<string> GetGlobals(string name)
{
getGlobalsParameter = name;
if (exceptionToThrow != null) {
throw exceptionToThrow;
}
return globals;
}
/// <summary>
/// Returns the parameter passed to the GetGlobals method.
/// </summary>
public string GetGlobalsParameter {
get { return getGlobalsParameter; }
}
/// <summary>
/// Returns the parameter passed to the GetMemberNames method.
/// </summary>
public string GetMemberNamesParameter {
get { return getMemberNamesParameter; }
}
}
}

12
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs

@ -13,6 +13,7 @@ using System.Text; @@ -13,6 +13,7 @@ using System.Text;
using ICSharpCode.PythonBinding;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.TextEditor.Document;
namespace PythonBinding.Tests.Console
@ -31,6 +32,7 @@ namespace PythonBinding.Tests.Console @@ -31,6 +32,7 @@ namespace PythonBinding.Tests.Console
List<Color> textColors = new List<Color>();
bool showCompletionWindowCalled;
bool makeReadOnlyCalled;
ICompletionDataProvider completionProvider;
public MockTextEditor()
{
@ -69,6 +71,13 @@ namespace PythonBinding.Tests.Console @@ -69,6 +71,13 @@ namespace PythonBinding.Tests.Console
public bool IsMakeCurrentContentReadOnlyCalled {
get { return makeReadOnlyCalled; }
}
/// <summary>
/// Returns the code completion data provider passed to the ShowCompletionWindow method.
/// </summary>
public ICompletionDataProvider CompletionDataProvider {
get { return completionProvider; }
}
public string Text {
get { return previousLines.ToString() + lineBuilder.ToString(); }
@ -192,9 +201,10 @@ namespace PythonBinding.Tests.Console @@ -192,9 +201,10 @@ namespace PythonBinding.Tests.Console
return "aaaa";
}
public void ShowCompletionWindow()
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider)
{
showCompletionWindowCalled = true;
this.completionProvider = completionDataProvider;
}
public void MakeCurrentContentReadOnly()

18
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleCodeCompletionTestFixture.cs

@ -19,34 +19,24 @@ namespace PythonBinding.Tests.Console @@ -19,34 +19,24 @@ namespace PythonBinding.Tests.Console
/// When the dot character is typed in after an object the code completion window should appear.
/// </summary>
[TestFixture]
[Ignore("Not implemented")]
public class PythonConsoleCodeCompletionTestFixture
{
MockTextEditor textEditor;
PythonConsole console;
string prompt = ">>> ";
IList<string> expectedMembers;
IList<string> completionItems;
bool showCompletionWindowCalledBeforeDotTypedIn;
[TestFixtureSetUp]
public void SetUpFixture()
{
textEditor = new MockTextEditor();
console = new PythonConsole(textEditor);
console = new PythonConsole(textEditor, null);
console.WriteLine(prompt, Style.Prompt);
// expectedMembers = host.GetCommandLine().GetMemberNames("__builtins__");
textEditor.RaiseKeyPressEvents("__builtins__");
showCompletionWindowCalledBeforeDotTypedIn = textEditor.IsShowCompletionWindowCalled;
textEditor.RaiseKeyPressEvent('.');
}
// [Test]
// public void MoreThanZeroExpectedMembers()
// {
// Assert.IsTrue(expectedMembers.Count > 0);
// }
[Test]
public void ShowCompletionWindowCalled()
@ -59,5 +49,11 @@ namespace PythonBinding.Tests.Console @@ -59,5 +49,11 @@ namespace PythonBinding.Tests.Console
{
Assert.IsFalse(showCompletionWindowCalledBeforeDotTypedIn);
}
[Test]
public void PythonConsoleCompletionDataProviderPassedToShowCompletionWindowMethod()
{
Assert.IsInstanceOfType(typeof(PythonConsoleCompletionDataProvider), textEditor.CompletionDataProvider);
}
}
}

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

@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console @@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console
public void Init()
{
textEditor = new MockTextEditor();
pythonConsole = new PythonConsole(textEditor);
pythonConsole = new PythonConsole(textEditor, null);
pythonConsole.Write(prompt, Style.Prompt);
}

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

@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console @@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console
public void Init()
{
textEditor = new MockTextEditor();
console = new PythonConsole(textEditor);
console = new PythonConsole(textEditor, null);
console.Write(prompt, Style.Prompt);
}

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

@ -26,8 +26,6 @@ namespace PythonBinding.Tests.Console @@ -26,8 +26,6 @@ namespace PythonBinding.Tests.Console
{
DerivedPythonConsoleHost host;
TextEditorControl textEditorControl;
ScriptEngine engine;
ScriptEngine expectedEngine;
TextEditor textEditor;
[TestFixtureSetUp]
@ -38,9 +36,6 @@ namespace PythonBinding.Tests.Console @@ -38,9 +36,6 @@ namespace PythonBinding.Tests.Console
host = new DerivedPythonConsoleHost(textEditor);
ScriptRuntime runtime = IronPython.Hosting.Python.CreateRuntime();
// expectedEngine = runtime.GetEngine(typeof(PythonContext));
// host.ScriptEngineToReturn = expectedEngine;
// engine = host.CallCreateEngine();
}
[TestFixtureTearDown]
@ -82,12 +77,6 @@ namespace PythonBinding.Tests.Console @@ -82,12 +77,6 @@ namespace PythonBinding.Tests.Console
{
Assert.AreEqual(typeof(PythonContext), host.GetProvider());
}
[Test]
public void ScriptEngineReturnedFromCreateEngine()
{
Assert.AreEqual(expectedEngine, engine);
}
[Test]
public void ConsoleHostImplementsIDisposable()

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

@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console @@ -29,7 +29,7 @@ namespace PythonBinding.Tests.Console
public void Init()
{
textEditor = new MockTextEditor();
console = new PythonConsole(textEditor);
console = new PythonConsole(textEditor, null);
console.Write(prompt, Style.Prompt);
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadTestFixture.cs

@ -33,7 +33,7 @@ namespace PythonBinding.Tests.Console @@ -33,7 +33,7 @@ namespace PythonBinding.Tests.Console
public void Init()
{
mockTextEditor = new MockTextEditor();
pythonConsole = new PythonConsole(mockTextEditor);
pythonConsole = new PythonConsole(mockTextEditor, null);
autoIndentSize = initialAutoIndentSize;
Thread thread = new Thread(ReadLineFromConsoleOnDifferentThread);
@ -88,7 +88,7 @@ namespace PythonBinding.Tests.Console @@ -88,7 +88,7 @@ namespace PythonBinding.Tests.Console
public void NoTextWrittenWhenAutoIndentSizeIsZero()
{
MockTextEditor textEditor = new MockTextEditor();
PythonConsole console = new PythonConsole(textEditor);
PythonConsole console = new PythonConsole(textEditor, null);
textEditor.RaiseKeyPressEvent('a');
textEditor.RaiseDialogKeyPressEvent(Keys.Enter);

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

@ -33,7 +33,7 @@ namespace PythonBinding.Tests.Console @@ -33,7 +33,7 @@ namespace PythonBinding.Tests.Console
public void Init()
{
textEditor = new MockTextEditor();
pythonConsole = new PythonConsole(textEditor);
pythonConsole = new PythonConsole(textEditor, null);
}
[Test]

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

@ -27,7 +27,7 @@ namespace PythonBinding.Tests.Console @@ -27,7 +27,7 @@ namespace PythonBinding.Tests.Console
{
mockTextEditor = new MockTextEditor();
mockTextEditor.Text = String.Empty;
pythonConsole = new PythonConsole(mockTextEditor);
pythonConsole = new PythonConsole(mockTextEditor, null);
}
[Test]

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

@ -39,7 +39,7 @@ namespace PythonBinding.Tests.Console @@ -39,7 +39,7 @@ namespace PythonBinding.Tests.Console
public void SetUpFixture()
{
MockTextEditor textEditor = new MockTextEditor();
using (pythonConsole = new PythonConsole(textEditor)) {
using (pythonConsole = new PythonConsole(textEditor, null)) {
textEditor.RaiseKeyPressEvent('a');
textEditor.RaiseKeyPressEvent('=');

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

@ -69,8 +69,11 @@ @@ -69,8 +69,11 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="AddInFileTestFixture.cs" />
<Compile Include="CompilingOptionsPanelTestFixture.cs" />
<Compile Include="Console\BuiltinCodeCompletionTestFixture.cs" />
<Compile Include="Console\DerivedPythonConsoleHost.cs" />
<Compile Include="Console\DisposedPythonConsoleTestFixture.cs" />
<Compile Include="Console\CodeCompletionTests.cs" />
<Compile Include="Console\MockMemberProvider.cs" />
<Compile Include="Console\MockTextEditor.cs" />
<Compile Include="Console\PythonConsoleCodeCompletionTestFixture.cs" />
<Compile Include="Console\PythonConsoleCurrentLineTestFixture.cs" />

Loading…
Cancel
Save