Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mkrueger@novell.com>2009-09-12 14:43:56 +0400
committerMike Krüger <mkrueger@novell.com>2009-09-12 14:43:56 +0400
commita628dd1a0897004cfa9ed63a9616f57b9c8bd848 (patch)
tree601232c41a40f41962b6411ffe902e84c71f266f /main/tests
parentc8e4d8563d5f82f2e751c45b6cdcc3ec3f222f65 (diff)
* Makefile.am:
* UnitTests.csproj: * MonoDevelop.Projects.Gui: * MonoDevelop.Projects.Gui/CompletionListWindowTests.cs: Added code completion window unit tests. svn path=/trunk/monodevelop/; revision=141826
Diffstat (limited to 'main/tests')
-rw-r--r--main/tests/UnitTests/ChangeLog9
-rw-r--r--main/tests/UnitTests/Makefile.am1
-rw-r--r--main/tests/UnitTests/MonoDevelop.Projects.Gui/CompletionListWindowTests.cs294
-rw-r--r--main/tests/UnitTests/UnitTests.csproj2
4 files changed, 306 insertions, 0 deletions
diff --git a/main/tests/UnitTests/ChangeLog b/main/tests/UnitTests/ChangeLog
index db9d3703fa..ee8ba67ada 100644
--- a/main/tests/UnitTests/ChangeLog
+++ b/main/tests/UnitTests/ChangeLog
@@ -1,3 +1,12 @@
+2009-09-12 Mike Krüger <mkrueger@novell.com>
+
+ * Makefile.am:
+ * UnitTests.csproj:
+ * MonoDevelop.Projects.Gui:
+
+ * MonoDevelop.Projects.Gui/CompletionListWindowTests.cs: Added
+ code completion window unit tests.
+
2009-09-11 Mike Krüger <mkrueger@novell.com>
* MonoDevelop.CSharpBinding/CodeCompletionBugTests.cs: Added
diff --git a/main/tests/UnitTests/Makefile.am b/main/tests/UnitTests/Makefile.am
index 78ad51c98f..04a88d4011 100644
--- a/main/tests/UnitTests/Makefile.am
+++ b/main/tests/UnitTests/Makefile.am
@@ -59,6 +59,7 @@ FILES = \
MonoDevelop.CSharpBinding/TestViewContent.cs \
MonoDevelop.CSharpBinding/TestWorkbenchWindow.cs \
MonoDevelop.CSharpBinding/TopLevelTests.cs \
+ MonoDevelop.Projects.Gui/CompletionListWindowTests.cs \
MonoDevelop.Projects/CompletionDatabaseTests.cs \
MonoDevelop.Projects/DomCompilationUnitTests.cs \
MonoDevelop.Projects/DomPersistenceTests.cs \
diff --git a/main/tests/UnitTests/MonoDevelop.Projects.Gui/CompletionListWindowTests.cs b/main/tests/UnitTests/MonoDevelop.Projects.Gui/CompletionListWindowTests.cs
new file mode 100644
index 0000000000..12ce106c54
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Projects.Gui/CompletionListWindowTests.cs
@@ -0,0 +1,294 @@
+//
+// CompletionListWindowTests.cs
+//
+// Author:
+// Mike Krüger <mkrueger@novell.com>
+//
+// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NUnit.Framework;
+using MonoDevelop.CSharpBinding.Gui;
+using MonoDevelop.Ide.Gui;
+using MonoDevelop.Projects;
+using MonoDevelop.Core;
+using MonoDevelop.Projects.Gui.Completion;
+using MonoDevelop.Ide.Gui.Content;
+using MonoDevelop.Projects.Dom.Parser;
+using MonoDevelop.Projects.Gui.Completion;
+
+namespace MonoDevelop.Projects.Gui
+{
+ [TestFixture()]
+ public class CompletionListWindowTests
+ {
+ class TestCompletionWidget : ICompletionWidget
+ {
+ public string CompletedWord {
+ get;
+ set;
+ }
+ #region ICompletionWidget implementation
+ public event EventHandler CompletionContextChanged {
+ add { /* TODO */ }
+ remove { /* TODO */ }
+ }
+
+ public string GetText (int startOffset, int endOffset)
+ {
+ return "";
+ }
+
+ public char GetChar (int offset)
+ {
+ return '\0';
+ }
+
+ public CodeCompletionContext CreateCodeCompletionContext (int triggerOffset)
+ {
+ return null;
+ }
+
+ public string GetCompletionText (ICodeCompletionContext ctx)
+ {
+ return "";
+ }
+
+ public void SetCompletionText (ICodeCompletionContext ctx, string partial_word, string complete_word)
+ {
+ this.CompletedWord = complete_word;
+ }
+
+ public int TextLength {
+ get {
+ return 0;
+ }
+ }
+
+ public int SelectedLength {
+ get {
+ return 0;
+ }
+ }
+
+ public Gtk.Style GtkStyle {
+ get {
+ return null;
+ }
+ }
+ #endregion
+
+ }
+
+ static void SimulateInput (CompletionListWindow listWindow, string input)
+ {
+ foreach (char ch in input) {
+ KeyActions ka;
+ switch (ch) {
+ case '8':
+ listWindow.PreProcessKeyEvent (Gdk.Key.Up, '\0', Gdk.ModifierType.None, out ka);
+ break;
+ case '2':
+ listWindow.PreProcessKeyEvent (Gdk.Key.Down, '\0', Gdk.ModifierType.None, out ka);
+ break;
+ case '\t':
+ listWindow.PreProcessKeyEvent (Gdk.Key.Tab, '\t', Gdk.ModifierType.None, out ka);
+ break;
+ case '\b':
+ listWindow.PreProcessKeyEvent (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None, out ka);
+ break;
+ case '\n':
+ listWindow.PreProcessKeyEvent (Gdk.Key.Return, '\n', Gdk.ModifierType.None, out ka);
+ break;
+ default:
+ listWindow.PreProcessKeyEvent ((Gdk.Key)ch, ch, Gdk.ModifierType.None, out ka);
+ break;
+
+ }
+ }
+ }
+
+ static string RunSimulation (string partialWord, string simulatedInput, bool autoSelect, bool completeWithSpaceOrPunctuation, params string[] completionData)
+ {
+ CompletionDataList dataList = new CompletionDataList ();
+ dataList.AutoSelect = autoSelect;
+ dataList.AddRange (completionData);
+
+ TestCompletionWidget result = new TestCompletionWidget ();
+ dataList.AutoSelect = true;
+ CompletionListWindow listWindow = new CompletionListWindow () {
+ CompletionDataList = dataList,
+ AutoSelect = autoSelect,
+ CodeCompletionContext = new CodeCompletionContext (),
+ PartialWord = partialWord,
+ CompleteWithSpaceOrPunctuation = completeWithSpaceOrPunctuation,
+ CompletionWidget = result
+ };
+ SimulateInput (listWindow, simulatedInput);
+ return result.CompletedWord;
+ }
+
+ [Test()]
+ public void TestPunctuationCompletion ()
+ {
+ string output = RunSimulation ("", "aaa ", true, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAb", output);
+
+ output = RunSimulation ("", "aa.", true, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAb", output);
+
+ output = RunSimulation ("", "AbAbAb.", true, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAb", output);
+ }
+
+ [Test()]
+ public void TestPunctuationCompletionShouldNotComplete ()
+ {
+ string output = RunSimulation ("", "aaa ", true, false,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual (null, output);
+ }
+
+ [Test()]
+ public void TestTabCompletion ()
+ {
+ string output = RunSimulation ("", "aaa\t", true, false,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAb", output);
+ }
+
+ [Test()]
+ public void TestTabCompletionWithAutoSelectOff ()
+ {
+ string output = RunSimulation ("", "aaa\t", false, false,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAb", output);
+ }
+
+ [Test()]
+ public void TestReturnCompletion ()
+ {
+ string output = RunSimulation ("", "aaa\n", true, false,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAb", output);
+ }
+
+ [Test()]
+ public void TestReturnCompletionWithAutoSelectOff ()
+ {
+ string output = RunSimulation ("", "aaa\n", false, false,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual (null, output);
+ }
+
+ [Test()]
+ public void TestAutoSelectionOff ()
+ {
+ // shouldn't select anything since auto select is disabled.
+ string output = RunSimulation ("", "aaa ", false, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.IsNull (output);
+
+ // now with cursor down (shouldn't change selection)
+ output = RunSimulation ("", "aaa2 ", false, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAb", output);
+
+ // now with 2x cursor down - shold select next item.
+ output = RunSimulation ("", "aaa22 ", false, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb",
+ "AbAbAbAbAb");
+
+ Assert.AreEqual ("AbAbAbAb", output);
+ }
+
+ [Test()]
+ public void TestBackspace ()
+ {
+ string output = RunSimulation ("", "aaaa\b\t", true, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAb", output);
+
+ output = RunSimulation ("", "aaaa\b\b\b\t", true, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAb", output);
+
+ output = RunSimulation ("", "aaaa\b\b\baaa\t", true, true,
+ "AbAb",
+ "AbAbAb",
+ "AbAbAbAb");
+
+ Assert.AreEqual ("AbAbAbAb", output);
+ }
+
+ [Test()]
+ public void TestBackspacePreserveAutoSelect ()
+ {
+ string output = RunSimulation ("", "c\bc ", false, true,
+ "a",
+ "b",
+ "c");
+
+ Assert.AreEqual (null, output);
+ }
+ }
+}
diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj
index 43a64cf495..3ad2c79dec 100644
--- a/main/tests/UnitTests/UnitTests.csproj
+++ b/main/tests/UnitTests/UnitTests.csproj
@@ -200,6 +200,7 @@
<Compile Include="Mono.TextEditor.Tests.DefaultEditActions\CaretMoveActionTests.cs" />
<Compile Include="Mono.TextEditor.Tests.DefaultEditActions\DeleteActionTests.cs" />
<Compile Include="Mono.TextEditor.Tests.DefaultEditActions\SelectionActionTests.cs" />
+ <Compile Include="MonoDevelop.Projects.Gui\CompletionListWindowTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
@@ -222,5 +223,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="MonoDevelop.Refactoring\" />
+ <Folder Include="MonoDevelop.Projects.Gui\" />
</ItemGroup>
</Project> \ No newline at end of file