2
// ParameterCompletionTests.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using NUnit.Framework;
31
using MonoDevelop.CSharpBinding.Gui;
32
using MonoDevelop.Ide.Gui;
33
using MonoDevelop.Projects;
34
using MonoDevelop.Core;
35
using MonoDevelop.Projects.Gui.Completion;
36
using MonoDevelop.Ide.Gui.Content;
37
using MonoDevelop.Projects.Dom.Parser;
39
namespace MonoDevelop.CSharpBinding.Tests
42
public class ParameterCompletionTests : UnitTests.TestBase
44
public static IParameterDataProvider CreateProvider (string text)
46
int cursorPosition = text.IndexOf ('$');
47
string parsedText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
49
TestWorkbenchWindow tww = new TestWorkbenchWindow ();
50
TestViewContent sev = new TestViewContent ();
51
DotNetProject project = new DotNetProject ("C#");
52
project.FileName = "/tmp/a.csproj";
54
SimpleProjectDom dom = new SimpleProjectDom ();
55
dom.Project = project;
56
ProjectDomService.RegisterDom (dom, "Project:" + project.FileName);
58
sev.Project = project;
59
sev.ContentName = "a.cs";
60
sev.Text = parsedText;
61
sev.CursorPosition = cursorPosition;
63
tww.ViewContent = sev;
64
Document doc = new Document (tww);
65
doc.ParsedDocument = new NRefactoryParser ().Parse (sev.ContentName, sev.Text);
66
dom.Add (doc.CompilationUnit);
67
CSharpTextEditorCompletion textEditorCompletion = new CSharpTextEditorCompletion (doc);
69
int triggerWordLength = 1;
70
CodeCompletionContext ctx = new CodeCompletionContext ();
71
ctx.TriggerOffset = sev.CursorPosition;
73
sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column);
74
ctx.TriggerLineOffset = column;
75
ctx.TriggerLine = line;
76
IParameterDataProvider result = textEditorCompletion.HandleParameterCompletion (ctx, text[cursorPosition - 1]);
81
/// Bug 427448 - Code Completion: completion of constructor parameters not working
84
public void TestBug427448 ()
86
IParameterDataProvider provider = CreateProvider (
93
public Test (string b)
99
Test (double d, float m)
111
Assert.IsNotNull (provider, "provider was not created.");
112
Assert.AreEqual (2, provider.OverloadCount);
116
/// Bug 432437 - No completion when invoking delegates
119
public void TestBug432437 ()
121
IParameterDataProvider provider = CreateProvider (
122
@"public delegate void MyDel (int value);
133
Assert.IsNotNull (provider, "provider was not created.");
134
Assert.AreEqual (1, provider.OverloadCount);
138
/// Bug 432658 - Incorrect completion when calling an extension method from inside another extension method
141
public void TestBug432658 ()
143
IParameterDataProvider provider = CreateProvider (
144
@"static class Extensions
146
public static void Ext1 (this int start)
149
public static void Ext2 (this int end)
154
Assert.IsNotNull (provider, "provider was not created.");
155
Assert.AreEqual (1, provider.OverloadCount, "There should be one overload");
156
Assert.AreEqual (1, provider.GetParameterCount(0), "Parameter 'start' should exist");
160
/// Bug 432727 - No completion if no constructor
163
public void TestBug432727 ()
165
IParameterDataProvider provider = CreateProvider (
173
Assert.IsNotNull (provider, "provider was not created.");
174
Assert.AreEqual (1, provider.OverloadCount);
178
/// Bug 434705 - No autocomplete offered if not assigning result of 'new' to a variable
181
public void TestBug434705 ()
183
IParameterDataProvider provider = CreateProvider (
198
Assert.IsNotNull (provider, "provider was not created.");
199
Assert.AreEqual (1, provider.OverloadCount);
203
/// Bug 434705 - No autocomplete offered if not assigning result of 'new' to a variable
206
public void TestBug434705B ()
208
IParameterDataProvider provider = CreateProvider (
220
Test<int> l = new Test<int> ($
223
Assert.IsNotNull (provider, "provider was not created.");
224
Assert.AreEqual (1, provider.OverloadCount);
229
/// Bug 434701 - No autocomplete in attributes
232
public void TestBug434701 ()
234
IParameterDataProvider provider = CreateProvider (
235
@"class TestAttribute : System.Attribute
246
Assert.IsNotNull (provider, "provider was not created.");
247
Assert.AreEqual (1, provider.OverloadCount);
251
/// Bug 447985 - Exception display tip is inaccurate for derived (custom) exceptions
254
public void TestBug447985 ()
256
IParameterDataProvider provider = CreateProvider (
259
public class Exception
261
public Exception () {}
265
class MyException : System.Exception
267
public MyException (int test)
275
throw new MyException($
279
Assert.IsNotNull (provider, "provider was not created.");
280
Assert.AreEqual (1, provider.OverloadCount);
281
Assert.AreEqual (1, provider.GetParameterCount(0), "Parameter 'test' should exist");
b'\\ No newline at end of file'