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.CSharpBinding/AutomaticBracketInsertionTests.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
Diffstat (limited to 'main/tests/UnitTests/MonoDevelop.CSharpBinding/AutomaticBracketInsertionTests.cs')
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.CSharpBinding/AutomaticBracketInsertionTests.cs | 116 |
1 files changed, 73 insertions, 43 deletions
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/AutomaticBracketInsertionTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/AutomaticBracketInsertionTests.cs index 0029b2a513..044eed3e56 100644 --- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/AutomaticBracketInsertionTests.cs +++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/AutomaticBracketInsertionTests.cs @@ -26,22 +26,20 @@ using System; using NUnit.Framework; -using MonoDevelop.CSharp.Parser; -using Mono.TextEditor; -using System.Text; -using System.Collections.Generic; using System.Linq; -using ICSharpCode.NRefactory; -using ICSharpCode.NRefactory.TypeSystem; -using MonoDevelop.Ide.TypeSystem; -using MonoDevelop.Ide.Gui.Content; -using MonoDevelop.CSharp.Formatting; using UnitTests; -using MonoDevelop.Projects.Policies; using MonoDevelop.CSharpBinding.Tests; using MonoDevelop.Ide.Gui; using MonoDevelop.CSharp.Completion; using MonoDevelop.Ide.CodeCompletion; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Ide.Editor.Extension; +using Microsoft.CodeAnalysis; +using MonoDevelop.Projects; +using MonoDevelop.Core.ProgressMonitoring; +using MonoDevelop.Ide.TypeSystem; +using MonoDevelop.CSharp.Formatting; +using MonoDevelop.Projects.Policies; namespace MonoDevelop.CSharpBinding { @@ -50,11 +48,14 @@ namespace MonoDevelop.CSharpBinding { class TestCompletionWidget : ICompletionWidget { - Document doc; + MonoDevelop.Ide.Editor.TextEditor editor; + + DocumentContext documentContext; - public TestCompletionWidget (Document doc) + public TestCompletionWidget (TextEditor editor, DocumentContext document) { - this.doc = doc; + this.editor = editor; + documentContext = document; } public string CompletedWord { @@ -69,17 +70,17 @@ namespace MonoDevelop.CSharpBinding public string GetText (int startOffset, int endOffset) { - return doc.Editor.GetTextBetween (startOffset, endOffset); + return editor.GetTextBetween (startOffset, endOffset); } public char GetChar (int offset) { - return doc.Editor.GetCharAt (offset); + return editor.GetCharAt (offset); } public CodeCompletionContext CreateCodeCompletionContext (int triggerOffset) { - var line = doc.Editor.GetLineByOffset (triggerOffset); + var line = editor.GetLineByOffset (triggerOffset); return new CodeCompletionContext { TriggerOffset = triggerOffset, TriggerLine = line.LineNumber, @@ -93,7 +94,7 @@ namespace MonoDevelop.CSharpBinding public CodeCompletionContext CurrentCodeCompletionContext { get { - return CreateCodeCompletionContext (doc.Editor.Caret.Offset); + return CreateCodeCompletionContext (editor.CaretOffset); } } @@ -118,13 +119,16 @@ namespace MonoDevelop.CSharpBinding public int CaretOffset { get { - return doc.Editor.Caret.Offset; + return editor.CaretOffset; + } + set { + editor.CaretOffset = value; } } public int TextLength { get { - return doc.Editor.Document.TextLength; + return editor.Length; } } @@ -139,6 +143,17 @@ namespace MonoDevelop.CSharpBinding return null; } } + + double ICompletionWidget.ZoomLevel { + get { + return 1; + } + } + + void ICompletionWidget.AddSkipChar (int cursorPosition, char c) + { + // ignore + } #endregion } @@ -148,10 +163,10 @@ namespace MonoDevelop.CSharpBinding TestWorkbenchWindow tww = new TestWorkbenchWindow (); content = new TestViewContent (); tww.ViewContent = content; - content.ContentName = "a.cs"; - content.GetTextEditorData ().Document.MimeType = "text/x-csharp"; + content.ContentName = "/a.cs"; + content.Data.MimeType = "text/x-csharp"; - Document doc = new Document (tww); + var doc = new MonoDevelop.Ide.Gui.Document (tww); var text = input; int endPos = text.IndexOf ('$'); @@ -161,12 +176,26 @@ namespace MonoDevelop.CSharpBinding content.Text = text; content.CursorPosition = System.Math.Max (0, endPos); + var project = new DotNetAssemblyProject (Microsoft.CodeAnalysis.LanguageNames.CSharp); + project.Name = "test"; + project.FileName = "test.csproj"; + project.Files.Add (new ProjectFile (content.ContentName, BuildAction.Compile)); + project.Policies.Set (PolicyService.InvariantPolicies.Get<CSharpFormattingPolicy> (), CSharpFormatter.MimeType); + var solution = new MonoDevelop.Projects.Solution (); + solution.AddConfiguration ("", true); + solution.DefaultSolutionFolder.AddItem (project); + using (var monitor = new NullProgressMonitor ()) + TypeSystemService.Load (solution, monitor, false); + content.Project = project; + doc.SetProject (project); + var compExt = new CSharpCompletionTextEditorExtension (); - compExt.Initialize (doc); + compExt.Initialize (doc.Editor, doc); content.Contents.Add (compExt); doc.UpdateParseDocument (); + TypeSystemService.Unload (solution); return compExt; } @@ -175,18 +204,19 @@ namespace MonoDevelop.CSharpBinding TestViewContent content; var ext = Setup (input, out content); - ListWindow.ClearHistory (); var listWindow = new CompletionListWindow (); - var widget = new TestCompletionWidget (ext.Document); + var widget = new TestCompletionWidget (ext.Editor, ext.DocumentContext); listWindow.CompletionWidget = widget; listWindow.CodeCompletionContext = widget.CurrentCodeCompletionContext; + var model = ext.DocumentContext.ParsedDocument.GetAst<SemanticModel> (); - var t = ext.Document.Compilation.FindType (new FullTypeName (type)); - var method = member != null ? t.GetMembers (m => m.Name == member).First () : t.GetConstructors ().First (); - var data = new MemberCompletionData (ext, method, OutputFlags.ClassBrowserEntries); + var t = model.Compilation.GetTypeByMetadataName (type); + var method = member != null ? t.GetMembers().First (m => m.Name == member) : t.GetMembers ().OfType<IMethodSymbol> ().First (m => m.MethodKind == MethodKind.Constructor); + var data = new RoslynSymbolCompletionData (null, ext, method); data.IsDelegateExpected = isDelegateExpected; KeyActions ka = KeyActions.Process; - data.InsertCompletionText (listWindow, ref ka, key, (char)key, Gdk.ModifierType.None, true, false); + data.InsertCompletionText (listWindow, ref ka, KeyDescriptor.FromGtk (key, (char)key, Gdk.ModifierType.None)); + return widget.CompletedWord; } @@ -200,7 +230,7 @@ namespace MonoDevelop.CSharpBinding $ } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar ();|", completion); + Assert.AreEqual ("FooBar();|", completion); } [Test] @@ -226,7 +256,7 @@ namespace MonoDevelop.CSharpBinding Test($); } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar ()|", completion); + Assert.AreEqual ("FooBar()|", completion); } [Test] @@ -239,7 +269,7 @@ namespace MonoDevelop.CSharpBinding Test(foo, $ } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar ()|", completion); + Assert.AreEqual ("FooBar()|", completion); } [Test] @@ -255,7 +285,7 @@ namespace MonoDevelop.CSharpBinding $ } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar (|);", completion); + Assert.AreEqual ("FooBar(|);", completion); } [Test] @@ -269,7 +299,7 @@ namespace MonoDevelop.CSharpBinding i = $ } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar ()|", completion); + Assert.AreEqual ("FooBar()|", completion); } [Test] @@ -287,7 +317,7 @@ namespace MonoDevelop.CSharpBinding i = $ } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar (|)", completion); + Assert.AreEqual ("FooBar(|)", completion); } [Test] @@ -315,7 +345,7 @@ class MyClass $ } }", "MyClass", "FooBar", (Gdk.Key)'.'); - Assert.AreEqual ("FooBar ().|", completion); + Assert.AreEqual ("FooBar().|", completion); } @@ -332,7 +362,7 @@ class MyClass $ } }", "MyClass", null); - Assert.AreEqual ("MyClass ()|", completion); + Assert.AreEqual ("MyClass()|", completion); } [Test] @@ -348,7 +378,7 @@ class MyClass $ } }", "MyClass", null); - Assert.AreEqual ("MyClass (|)", completion); + Assert.AreEqual ("MyClass(|)", completion); } [Test] @@ -361,7 +391,7 @@ class MyClass $ } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar<|> ();", completion); + Assert.AreEqual ("FooBar<|>();", completion); } [Test] @@ -374,7 +404,7 @@ class MyClass $ } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar (|);", completion); + Assert.AreEqual ("FooBar(|);", completion); } [Test] @@ -387,7 +417,7 @@ class MyClass $ } }", "MyClass", "FooBar", (Gdk.Key)'.'); - Assert.AreEqual ("FooBar<> ().|", completion); + Assert.AreEqual ("FooBar<>().|", completion); } [Test] @@ -401,7 +431,7 @@ class MyClass if (true) { } } }", "MyClass", "FooBar"); - Assert.AreEqual ("FooBar ();|", completion); + Assert.AreEqual ("FooBar();|", completion); } @@ -417,7 +447,7 @@ class MyClass $ } }", "MyClass`1", null); - Assert.AreEqual ("MyClass<|> ()", completion); + Assert.AreEqual ("MyClass<|>()", completion); } [Test] |