10.2.2
by Mirco Bauer
Import upstream version 2.1.1+dfsg |
1 |
//
|
2 |
// AspNetTesting.cs
|
|
3 |
//
|
|
4 |
// Author:
|
|
5 |
// Michael Hutchinson <mhutchinson@novell.com>
|
|
6 |
//
|
|
7 |
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
|
8 |
//
|
|
9 |
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10 |
// of this software and associated documentation files (the "Software"), to deal
|
|
11 |
// in the Software without restriction, including without limitation the rights
|
|
12 |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13 |
// copies of the Software, and to permit persons to whom the Software is
|
|
14 |
// furnished to do so, subject to the following conditions:
|
|
15 |
//
|
|
16 |
// The above copyright notice and this permission notice shall be included in
|
|
17 |
// all copies or substantial portions of the Software.
|
|
18 |
//
|
|
19 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25 |
// THE SOFTWARE.
|
|
26 |
||
27 |
using System; |
|
10.2.6
by Jo Shields
Import upstream version 2.4+dfsg |
28 |
using MonoDevelop.Ide.CodeCompletion; |
10.2.2
by Mirco Bauer
Import upstream version 2.1.1+dfsg |
29 |
using MonoDevelop.Projects; |
30 |
using MonoDevelop.Projects.Dom.Parser; |
|
31 |
||
32 |
namespace MonoDevelop.AspNet.Tests |
|
33 |
{
|
|
34 |
||
35 |
//largely copied from MonoDevelop.CSharpBinding.Tests.CodeCompletionBugTests
|
|
36 |
public static class AspNetTesting |
|
37 |
{
|
|
38 |
static int pcount = 0; |
|
39 |
||
40 |
public static CompletionDataList CreateAspxCtrlSpaceProvider (string text) |
|
41 |
{
|
|
42 |
return CreateProvider (text, ".aspx", true); |
|
43 |
}
|
|
44 |
||
45 |
public static CompletionDataList CreateProvider (string text, string extension, bool isCtrlSpace) |
|
46 |
{
|
|
47 |
string parsedText; |
|
48 |
string editorText; |
|
49 |
int cursorPosition = text.IndexOf ('$'); |
|
50 |
int endPos = text.IndexOf ('$', cursorPosition + 1); |
|
51 |
if (endPos == -1) |
|
52 |
parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); |
|
53 |
else { |
|
54 |
parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); |
|
55 |
editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); |
|
56 |
cursorPosition = endPos - 1; |
|
57 |
}
|
|
58 |
var tww = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow (); |
|
59 |
var sev = new MonoDevelop.CSharpBinding.Tests.TestViewContent (); |
|
60 |
var project = new AspNetAppProject ("C#"); |
|
10.2.6
by Jo Shields
Import upstream version 2.4+dfsg |
61 |
project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); |
10.2.2
by Mirco Bauer
Import upstream version 2.1.1+dfsg |
62 |
|
10.2.6
by Jo Shields
Import upstream version 2.4+dfsg |
63 |
string file = UnitTests.TestBase.GetTempFile (extension); |
10.2.2
by Mirco Bauer
Import upstream version 2.1.1+dfsg |
64 |
project.AddFile (file); |
65 |
||
66 |
ProjectDomService.Load (project); |
|
67 |
ProjectDom dom = ProjectDomService.GetProjectDom (project); |
|
68 |
dom.ForceUpdate (true); |
|
69 |
ProjectDomService.Parse (project, file, null, delegate { return parsedText; }); |
|
70 |
ProjectDomService.Parse (project, file, null, delegate { return parsedText; }); |
|
71 |
||
72 |
sev.Project = project; |
|
73 |
sev.ContentName = file; |
|
74 |
sev.Text = editorText; |
|
75 |
sev.CursorPosition = cursorPosition; |
|
76 |
tww.ViewContent = sev; |
|
77 |
var doc = new MonoDevelop.Ide.Gui.Document (tww); |
|
78 |
doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser ().Parse (null, sev.ContentName, parsedText); |
|
79 |
foreach (var e in doc.ParsedDocument.Errors) |
|
80 |
Console.WriteLine (e); |
|
81 |
||
82 |
var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension (); |
|
83 |
Initialize (textEditorCompletion, doc); |
|
84 |
||
85 |
int triggerWordLength = 1; |
|
86 |
CodeCompletionContext ctx = new CodeCompletionContext (); |
|
87 |
ctx.TriggerOffset = sev.CursorPosition; |
|
88 |
int line, column; |
|
89 |
sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column); |
|
90 |
ctx.TriggerLine = line; |
|
91 |
ctx.TriggerLineOffset = column; |
|
92 |
||
93 |
if (isCtrlSpace) |
|
94 |
return textEditorCompletion.CodeCompletionCommand (ctx) as CompletionDataList; |
|
95 |
else
|
|
96 |
return textEditorCompletion.HandleCodeCompletion (ctx, editorText[cursorPosition - 1] , ref triggerWordLength) as CompletionDataList; |
|
97 |
}
|
|
98 |
||
99 |
static void Initialize (MonoDevelop.Ide.Gui.Content.TextEditorExtension extension, MonoDevelop.Ide.Gui.Document doc) |
|
100 |
{
|
|
101 |
var meth = typeof (MonoDevelop.Ide.Gui.Content.TextEditorExtension) |
|
102 |
.GetMethod ("Initialize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, |
|
103 |
null, new Type [] { typeof (MonoDevelop.Ide.Gui.Document) }, null); |
|
104 |
meth.Invoke (extension, new object [] { doc }); |
|
105 |
}
|
|
106 |
}
|
|
107 |
}
|