diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
commit | 95408b1a41b31b645f3a8c3323ab7d3ca4bff26b (patch) | |
tree | f8f137cddcb9a40499d303be95722fd2c6081bce /main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
Diffstat (limited to 'main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs')
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs | 162 |
1 files changed, 139 insertions, 23 deletions
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs index 61647513d5..ad079d75f4 100644 --- a/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs +++ b/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs @@ -32,6 +32,7 @@ using MonoDevelop.Projects; using MonoDevelop.Core; using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.Ide.Gui.Content; +using MonoDevelop.Ide.Editor.Extension; namespace MonoDevelop.Ide.Gui { @@ -92,6 +93,9 @@ namespace MonoDevelop.Ide.Gui get { return sb.Length; } + set { + throw new NotSupportedException (); + } } public int TextLength { @@ -111,6 +115,17 @@ namespace MonoDevelop.Ide.Gui return null; } } + + double ICompletionWidget.ZoomLevel { + get { + return 1; + } + } + + void ICompletionWidget.AddSkipChar (int cursorPosition, char c) + { + // ignore + } #endregion public void AddChar (char ch) { @@ -125,43 +140,51 @@ namespace MonoDevelop.Ide.Gui static void SimulateInput (CompletionListWindow listWindow, string input) { + var testCompletionWidget = ((TestCompletionWidget)listWindow.CompletionWidget); + bool isClosed = false; + listWindow.WindowClosed += delegate { + isClosed = true; + }; foreach (char ch in input) { switch (ch) { case '8': - listWindow.PreProcessKeyEvent (Gdk.Key.Up, '\0', Gdk.ModifierType.None); - listWindow.PostProcessKeyEvent (Gdk.Key.Up, '\0', Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Up, '\0', Gdk.ModifierType.None)); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Up, '\0', Gdk.ModifierType.None)); break; case '2': - listWindow.PreProcessKeyEvent (Gdk.Key.Down, '\0', Gdk.ModifierType.None); - listWindow.PostProcessKeyEvent (Gdk.Key.Down, '\0', Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Down, '\0', Gdk.ModifierType.None)); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Down, '\0', Gdk.ModifierType.None)); break; case '4': - listWindow.PreProcessKeyEvent (Gdk.Key.Left, '\0', Gdk.ModifierType.None); - listWindow.PostProcessKeyEvent (Gdk.Key.Left, '\0', Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Left, '\0', Gdk.ModifierType.None)); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Left, '\0', Gdk.ModifierType.None)); break; case '6': - listWindow.PreProcessKeyEvent (Gdk.Key.Right, '\0', Gdk.ModifierType.None); - listWindow.PostProcessKeyEvent (Gdk.Key.Right, '\0', Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Right, '\0', Gdk.ModifierType.None)); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Right, '\0', Gdk.ModifierType.None)); break; case '\t': - listWindow.PreProcessKeyEvent (Gdk.Key.Tab, '\t', Gdk.ModifierType.None); - listWindow.PostProcessKeyEvent (Gdk.Key.Tab, '\t', Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Tab, '\t', Gdk.ModifierType.None)); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Tab, '\t', Gdk.ModifierType.None)); break; case '\b': - listWindow.PreProcessKeyEvent (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None); - ((TestCompletionWidget)listWindow.CompletionWidget).Backspace (); - listWindow.PostProcessKeyEvent (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None)); + testCompletionWidget.Backspace (); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None)); break; case '\n': - listWindow.PreProcessKeyEvent (Gdk.Key.Return, '\n', Gdk.ModifierType.None); - listWindow.PostProcessKeyEvent (Gdk.Key.Return, '\n', Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Return, '\n', Gdk.ModifierType.None)); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Return, '\n', Gdk.ModifierType.None)); break; default: - listWindow.PreProcessKeyEvent ((Gdk.Key)ch, ch, Gdk.ModifierType.None); - ((TestCompletionWidget)listWindow.CompletionWidget).AddChar (ch); - listWindow.PostProcessKeyEvent ((Gdk.Key)ch, ch, Gdk.ModifierType.None); + listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk ((Gdk.Key)ch, ch, Gdk.ModifierType.None)); + testCompletionWidget.AddChar (ch); + listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk ((Gdk.Key)ch, ch, Gdk.ModifierType.None)); break; } + // window closed. + if (isClosed) + break; } } @@ -194,8 +217,9 @@ namespace MonoDevelop.Ide.Gui static string RunSimulation (SimulationSettings settings) { CompletionListWindow listWindow = CreateListWindow (settings); + var testCompletionWidget = (TestCompletionWidget)listWindow.CompletionWidget; SimulateInput (listWindow, settings.SimulatedInput); - return ((TestCompletionWidget)listWindow.CompletionWidget).CompletedWord; + return testCompletionWidget.CompletedWord; } static CompletionListWindow CreateListWindow (CompletionListWindowTests.SimulationSettings settings) @@ -204,7 +228,6 @@ namespace MonoDevelop.Ide.Gui dataList.AutoSelect = settings.AutoSelect; dataList.AddRange (settings.CompletionData); dataList.DefaultCompletionString = settings.DefaultCompletionString; - ListWindow.ClearHistory (); CompletionListWindow listWindow = new CompletionListWindow () { CompletionDataList = dataList, CompletionWidget = new TestCompletionWidget (), @@ -480,7 +503,6 @@ namespace MonoDevelop.Ide.Gui Assert.AreEqual ("/AbAb", output); } - [Ignore("Behavior was changed - commit with '.' now works everytime")] [Test] public void TestMatchPunctuationCommitOnSpaceAndPunctuation3 () { @@ -591,8 +613,8 @@ namespace MonoDevelop.Ide.Gui [Test] public void TestBug543984 () { - string output = RunSimulation ("", "foo b\n", true, true, false, "foo bar", "foo bar baz"); - Assert.AreEqual ("foo bar", output); + string output = RunSimulation ("", "foo#b\n", true, true, false, "foo#bar", "foo#bar#baz"); + Assert.AreEqual ("foo#bar", output); } [Test] @@ -817,6 +839,100 @@ namespace MonoDevelop.Ide.Gui Assert.AreEqual ("d", output); } + [Test] + public void TestSpaceCommits () + { + string output = RunSimulation ("", "over ", true, true, + "override", + "override foo"); + + Assert.AreEqual ("override", output); + } + + + + [Test] + public void TestNumberInput () + { + string output = RunSimulation ("", "1.", true, true, false, "foo1"); + Assert.IsTrue (string.IsNullOrEmpty (output), "output was " + output); + } + + static void ContinueSimulation (CompletionListWindow listWindow, ICompletionDataList list, ref TestCompletionWidget testCompletionWidget, string simulatedInput) + { + listWindow.ResetState (); + listWindow.CodeCompletionContext = new CodeCompletionContext (); + listWindow.CompletionDataList = list; + listWindow.CompletionWidget = testCompletionWidget = new TestCompletionWidget (); + listWindow.List.FilterWords (); + listWindow.ResetSizes (); + listWindow.UpdateWordSelection (); + SimulateInput (listWindow, simulatedInput); + listWindow.CompleteWord (); + } + + [Test] + public void TestMruSimpleLastItem () + { + var settings = new SimulationSettings () { + AutoSelect = true, + CompleteWithSpaceOrPunctuation = true, + AutoCompleteEmptyMatch = true, + CompletionData = new[] { "FooBar1", "Bar", "FooFoo2"} + }; + + var listWindow = CreateListWindow (settings); + var list = listWindow.CompletionDataList; + var testCompletionWidget = (TestCompletionWidget)listWindow.CompletionWidget; + + SimulateInput (listWindow, "FooBar\t"); + Assert.AreEqual ("FooBar1", testCompletionWidget.CompletedWord); + + ContinueSimulation (listWindow, list, ref testCompletionWidget, "FooFoo\t"); + Assert.AreEqual ("FooFoo2", testCompletionWidget.CompletedWord); + + ContinueSimulation (listWindow, list, ref testCompletionWidget, "F\t"); + Assert.AreEqual ("FooFoo2", testCompletionWidget.CompletedWord); + } + + [Test] + public void TestMruEmptyMatch () + { + var settings = new SimulationSettings () { + AutoSelect = true, + CompleteWithSpaceOrPunctuation = true, + AutoCompleteEmptyMatch = true, + CompletionData = new[] { "Foo", "Bar", "Test"} + }; + + var listWindow = CreateListWindow (settings); + var list = listWindow.CompletionDataList; + var testCompletionWidget = (TestCompletionWidget)listWindow.CompletionWidget; + SimulateInput (listWindow, "Foo\t"); + ContinueSimulation (listWindow, list, ref testCompletionWidget, "F\t"); + Assert.AreEqual ("Foo", testCompletionWidget.CompletedWord); + + ContinueSimulation (listWindow, list, ref testCompletionWidget, "Bar\t"); + Assert.AreEqual ("Bar", testCompletionWidget.CompletedWord); + + ContinueSimulation (listWindow, list, ref testCompletionWidget, "\t"); + Assert.AreEqual ("Bar", testCompletionWidget.CompletedWord); + } + + [Test] + public void TestCloseWithPunctiation () + { + var output = RunSimulation ("", "\"\t", true, true, false, punctuationData); + Assert.AreEqual (null, output); + } + + [Test] + public void TestPreference () + { + string output = RunSimulation ("", "expr\t", true, true, false, "expression", "PostfixExpressionStatementSyntax"); + Assert.AreEqual ("expression", output); + } + [TestFixtureSetUp] public void SetUp() |