~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to tests/UnitTests/MonoDevelop.CSharpBinding/ParameterCompletionTests.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ParameterCompletionTests.cs
 
3
//
 
4
// Author:
 
5
//   Mike Krüger <mkrueger@novell.com>
 
6
//
 
7
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
 
8
//
 
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:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
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.
 
27
//
 
28
 
 
29
using System;
 
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;
 
38
 
 
39
namespace MonoDevelop.CSharpBinding.Tests
 
40
{
 
41
        [TestFixture()]
 
42
        public class ParameterCompletionTests : UnitTests.TestBase
 
43
        {
 
44
                public static IParameterDataProvider CreateProvider (string text)
 
45
                {
 
46
                        int cursorPosition = text.IndexOf ('$');
 
47
                        string parsedText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
 
48
                        
 
49
                        TestWorkbenchWindow tww = new TestWorkbenchWindow ();
 
50
                        TestViewContent sev = new TestViewContent ();
 
51
                        DotNetProject project = new DotNetProject ("C#");
 
52
                        project.FileName = "/tmp/a.csproj";
 
53
                        
 
54
                        SimpleProjectDom dom = new SimpleProjectDom ();
 
55
                        dom.Project = project;
 
56
                        ProjectDomService.RegisterDom (dom, "Project:" + project.FileName);
 
57
                        
 
58
                        sev.Project = project;
 
59
                        sev.ContentName = "a.cs";
 
60
                        sev.Text = parsedText;
 
61
                        sev.CursorPosition = cursorPosition;
 
62
                        
 
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);
 
68
                        
 
69
                        int triggerWordLength = 1;
 
70
                        CodeCompletionContext ctx = new CodeCompletionContext ();
 
71
                        ctx.TriggerOffset = sev.CursorPosition;
 
72
                        int line, column;
 
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]);
 
77
                        return result;
 
78
                }
 
79
                
 
80
                /// <summary>
 
81
                /// Bug 427448 - Code Completion: completion of constructor parameters not working
 
82
                /// </summary>
 
83
                [Test()]
 
84
                public void TestBug427448 ()
 
85
                {
 
86
                        IParameterDataProvider provider = CreateProvider (
 
87
@"class Test
 
88
{
 
89
        public Test (int a)
 
90
        {
 
91
        }
 
92
        
 
93
        public Test (string b)
 
94
        {
 
95
        }
 
96
        protected Test ()
 
97
        {
 
98
        }
 
99
        Test (double d, float m)
 
100
        {
 
101
        }
 
102
}
 
103
 
 
104
class AClass
 
105
{
 
106
        void A()
 
107
        {
 
108
                Test t = new Test ($
 
109
        }
 
110
}");
 
111
                        Assert.IsNotNull (provider, "provider was not created.");
 
112
                        Assert.AreEqual (2, provider.OverloadCount);
 
113
                }
 
114
 
 
115
                /// <summary>
 
116
                /// Bug 432437 - No completion when invoking delegates
 
117
                /// </summary>
 
118
                [Test()]
 
119
                public void TestBug432437 ()
 
120
                {
 
121
                        IParameterDataProvider provider = CreateProvider (
 
122
@"public delegate void MyDel (int value);
 
123
 
 
124
class Test
 
125
{
 
126
        MyDel d;
 
127
 
 
128
        void A()
 
129
        {
 
130
                d ($
 
131
        }
 
132
}");
 
133
                        Assert.IsNotNull (provider, "provider was not created.");
 
134
                        Assert.AreEqual (1, provider.OverloadCount);
 
135
                }
 
136
 
 
137
                /// <summary>
 
138
                /// Bug 432658 - Incorrect completion when calling an extension method from inside another extension method
 
139
                /// </summary>
 
140
                [Test()]
 
141
                public void TestBug432658 ()
 
142
                {
 
143
                        IParameterDataProvider provider = CreateProvider (
 
144
@"static class Extensions
 
145
{
 
146
        public static void Ext1 (this int start)
 
147
        {
 
148
        }
 
149
        public static void Ext2 (this int end)
 
150
        {
 
151
                Ext1($
 
152
        }
 
153
}");
 
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");
 
157
                }
 
158
 
 
159
                /// <summary>
 
160
                /// Bug 432727 - No completion if no constructor
 
161
                /// </summary>
 
162
                [Test()]
 
163
                public void TestBug432727 ()
 
164
                {
 
165
                        IParameterDataProvider provider = CreateProvider (
 
166
@"class A
 
167
{
 
168
        void Method ()
 
169
        {
 
170
                A aTest = new A ($
 
171
        }
 
172
}");
 
173
                        Assert.IsNotNull (provider, "provider was not created.");
 
174
                        Assert.AreEqual (1, provider.OverloadCount);
 
175
                }
 
176
 
 
177
                /// <summary>
 
178
                /// Bug 434705 - No autocomplete offered if not assigning result of 'new' to a variable
 
179
                /// </summary>
 
180
                [Test()]
 
181
                public void TestBug434705 ()
 
182
                {
 
183
                        IParameterDataProvider provider = CreateProvider (
 
184
@"class Test
 
185
{
 
186
        public Test (int a)
 
187
        {
 
188
        }
 
189
}
 
190
 
 
191
class AClass
 
192
{
 
193
        Test A()
 
194
        {
 
195
                return new Test ($
 
196
        }
 
197
}");
 
198
                        Assert.IsNotNull (provider, "provider was not created.");
 
199
                        Assert.AreEqual (1, provider.OverloadCount);
 
200
                }
 
201
                
 
202
                /// <summary>
 
203
                /// Bug 434705 - No autocomplete offered if not assigning result of 'new' to a variable
 
204
                /// </summary>
 
205
                [Test()]
 
206
                public void TestBug434705B ()
 
207
                {
 
208
                        IParameterDataProvider provider = CreateProvider (
 
209
@"
 
210
class Test<T>
 
211
{
 
212
        public Test (T t)
 
213
        {
 
214
        }
 
215
}
 
216
class TestClass
 
217
{
 
218
        void TestMethod ()
 
219
        {
 
220
                Test<int> l = new Test<int> ($
 
221
        }
 
222
}");
 
223
                        Assert.IsNotNull (provider, "provider was not created.");
 
224
                        Assert.AreEqual (1, provider.OverloadCount);
 
225
                }
 
226
        
 
227
                
 
228
                /// <summary>
 
229
                /// Bug 434701 - No autocomplete in attributes
 
230
                /// </summary>
 
231
                [Test()]
 
232
                public void TestBug434701 ()
 
233
                {
 
234
                        IParameterDataProvider provider = CreateProvider (
 
235
@"class TestAttribute : System.Attribute
 
236
{
 
237
        public Test (int a)
 
238
        {
 
239
        }
 
240
}
 
241
 
 
242
[Test ($
 
243
class AClass
 
244
{
 
245
}");
 
246
                        Assert.IsNotNull (provider, "provider was not created.");
 
247
                        Assert.AreEqual (1, provider.OverloadCount);
 
248
                }
 
249
                
 
250
                /// <summary>
 
251
                /// Bug 447985 - Exception display tip is inaccurate for derived (custom) exceptions
 
252
                /// </summary>
 
253
                [Test()]
 
254
                public void TestBug447985 ()
 
255
                {
 
256
                        IParameterDataProvider provider = CreateProvider (
 
257
@"
 
258
namespace System {
 
259
        public class Exception
 
260
        {
 
261
                public Exception () {}
 
262
        }
 
263
}
 
264
 
 
265
class MyException : System.Exception
 
266
{
 
267
        public MyException (int test)
 
268
        {}
 
269
}
 
270
 
 
271
class AClass
 
272
{
 
273
        public void Test ()
 
274
        {
 
275
                throw new MyException($
 
276
        }
 
277
 
 
278
}");
 
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");
 
282
                }
 
283
                
 
284
                
 
285
        }
 
286
}
 
 
b'\\ No newline at end of file'