Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'main/tests/UnitTests/MonoDevelop.CSharpBinding')
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/AutomaticBracketInsertionTests.cs116
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs11
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/FoldingParserTests.cs30
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/MemberTests.cs209
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/NamedArgumentCompletionTests.cs91
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs354
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/ProjectDomTests.cs174
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/TestDocument.cs12
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs68
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/UnitTesteditorIntegrationTests.cs81
10 files changed, 489 insertions, 657 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]
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs
index 09e4259738..aeacf06c41 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpTextEditorIndentationTests.cs
@@ -1,3 +1,4 @@
+/*
//
// CSharpTextEditorIndentationTests.cs
//
@@ -38,7 +39,8 @@ using MonoDevelop.Ide.TypeSystem;
using MonoDevelop.Ide.Gui.Content;
using MonoDevelop.CSharp.Formatting;
using UnitTests;
-using MonoDevelop.Projects.Policies;
+using MonoDevelop.Projects.Policies;
+
using ICSharpCode.NRefactory.CSharp;
using MonoDevelop.CSharpBinding.Tests;
using MonoDevelop.Ide.Gui;
@@ -141,8 +143,10 @@ namespace MonoDevelop.CSharpBinding
IStateMachineIndentEngine CreateTracker (TextEditorData data)
{
- var policy = PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> ("text/x-csharp").CreateOptions();
- var textStylePolicy = data.CreateNRefactoryTextEditorOptions();
+ var policy = PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> ("text/x-csharp").CreateOptions();
+
+ var textStylePolicy = data.CreateNRefactoryTextEditorOptions();
+
textStylePolicy.IndentBlankLines = true;
var result = new CacheIndentEngine(new ICSharpCode.NRefactory.CSharp.CSharpIndentEngine(data.Document, textStylePolicy, policy));
result.Update (data.Caret.Offset);
@@ -452,3 +456,4 @@ $void Bar ()
}
}
+*/ \ No newline at end of file
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/FoldingParserTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/FoldingParserTests.cs
index 39798271e4..831cd61baf 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/FoldingParserTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/FoldingParserTests.cs
@@ -29,12 +29,10 @@ using System.Linq;
using NUnit.Framework;
using MonoDevelop.CSharp.Parser;
-using Mono.TextEditor;
using System.Text;
using System.Collections.Generic;
-using ICSharpCode.NRefactory;
-using ICSharpCode.NRefactory.TypeSystem;
using MonoDevelop.Ide.TypeSystem;
+using MonoDevelop.Ide.Editor;
namespace MonoDevelop.CSharpBinding
{
@@ -45,21 +43,21 @@ namespace MonoDevelop.CSharpBinding
{
var parser = new CSharpFoldingParser ();
var sb = new StringBuilder ();
- var openStack = new Stack<TextLocation>();
+ var openStack = new Stack<DocumentLocation>();
int line = 1;
int col = 1;
- var foldingList = new List<DomRegion> ();
+ var foldingList = new List<DocumentRegion> ();
for (int i = 0; i < code.Length; i++) {
char ch = code [i];
switch (ch) {
case '[':
- openStack.Push (new TextLocation (line, col));
+ openStack.Push (new DocumentLocation (line, col));
break;
case ']':
- foldingList.Add (new DomRegion (openStack.Pop (), new TextLocation (line, col)));
+ foldingList.Add (new DocumentRegion (openStack.Pop (), new DocumentLocation (line, col)));
break;
default:
if (ch =='\n') {
@@ -74,7 +72,7 @@ namespace MonoDevelop.CSharpBinding
}
var doc = parser.Parse ("a.cs", sb.ToString ());
- var generatedFoldings = new List<FoldingRegion> (doc.Foldings);
+ var generatedFoldings = doc.GetFoldingsAsync().Result;
Assert.AreEqual (foldingList.Count, generatedFoldings.Count, "Folding count differs.");
foreach (var generated in generatedFoldings) {
Assert.IsTrue (foldingList.Any (f => f == generated.Region), "fold not found:" + generated.Region);
@@ -140,7 +138,7 @@ class SomeNew {
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.]
using System;");
- foreach (var cmt in doc.Comments) {
+ foreach (var cmt in doc.GetCommentsAsync().Result) {
Assert.IsFalse (cmt.Text.StartsWith ("//"));
}
@@ -157,8 +155,8 @@ using System;");
}
#endregion]
}");
- Assert.AreEqual (1, doc.Foldings.Count ());
- Assert.AreEqual ("TestRegion", doc.Foldings.First ().Name);
+ Assert.AreEqual (1, doc.GetFoldingsAsync().Result.Count ());
+ Assert.AreEqual ("TestRegion", doc.GetFoldingsAsync().Result.First ().Name);
}
[Test]
@@ -178,9 +176,9 @@ using System;");
}
#endregion]
}");
- Assert.AreEqual (2, doc.Foldings.Count ());
- Assert.AreEqual ("TestRegion", doc.Foldings.First ().Name);
- Assert.AreEqual ("TestRegion2", doc.Foldings.Skip (1).First ().Name);
+ Assert.AreEqual (2, doc.GetFoldingsAsync().Result.Count ());
+ Assert.AreEqual ("TestRegion", doc.GetFoldingsAsync().Result.First ().Name);
+ Assert.AreEqual ("TestRegion2", doc.GetFoldingsAsync().Result.Skip (1).First ().Name);
}
@@ -196,7 +194,7 @@ using System;");
{
}
}");
- foreach (var cmt in doc.Comments) {
+ foreach (var cmt in doc.GetCommentsAsync().Result) {
Assert.IsFalse (cmt.Text.StartsWith ("///"));
Assert.IsTrue (cmt.IsDocumentation);
}
@@ -235,7 +233,7 @@ using System;");
{ // not be
} // folded
}");
- Assert.AreEqual (0, doc.Foldings.Count ());
+ Assert.AreEqual (0, doc.GetFoldingsAsync().Result.Count ());
}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/MemberTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/MemberTests.cs
deleted file mode 100644
index 5db91c48e7..0000000000
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/MemberTests.cs
+++ /dev/null
@@ -1,209 +0,0 @@
-////
-//// MemberTests.cs
-////
-//// Author:
-//// Mike Krüger <mkrueger@novell.com>
-////
-//// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
-////
-//// Permission is hereby granted, free of charge, to any person obtaining
-//// a copy of this software and associated documentation files (the
-//// "Software"), to deal in the Software without restriction, including
-//// without limitation the rights to use, copy, modify, merge, publish,
-//// distribute, sublicense, and/or sell copies of the Software, and to
-//// permit persons to whom the Software is furnished to do so, subject to
-//// the following conditions:
-////
-//// The above copyright notice and this permission notice shall be
-//// included in all copies or substantial portions of the Software.
-////
-//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-//// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-//// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-//// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-//// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-//// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-//// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-////
-//
-//using System;
-//using System.Collections.Generic;
-//
-//using NUnit.Framework;
-//using MonoDevelop.CSharpBinding;
-//using MonoDevelop.CSharp.Parser;
-//
-//namespace MonoDevelop.CSharpBinding.Tests
-//{
-// [TestFixture]
-// public class MemberTests
-// {
-// void DoTestFields (IParser parser)
-// {
-// ICompilationUnit unit = parser.Parse (null, "a.cs", @"class AClass { int x, y; }").CompilationUnit;
-// Assert.AreEqual (1, unit.Types.Count);
-// IType type = unit.Types[0];
-//
-// Assert.AreEqual (2, type.FieldCount);
-// List<IField> fields = new List<IField> (type.Fields);
-// Assert.AreEqual ("x", fields[0].Name);
-// Assert.AreEqual ("System.Int32", fields[0].ReturnType.FullName);
-// Assert.AreEqual ("y", fields[1].Name);
-// Assert.AreEqual ("System.Int32", fields[1].ReturnType.FullName);
-// }
-//
-// [Test]
-// public void TestFields ()
-// {
-// DoTestFields (new McsParser ());
-//// DoTestFields (new DomParser ());
-// }
-//
-// void DoTestMethods (IParser parser)
-// {
-// ICompilationUnit unit = parser.Parse (null, "a.cs",
-//@"class AClass {
-// void TestMethod<T> (string a, int b) {}
-// public static void ExtensionMethod (this int a) {};
-//}").CompilationUnit;
-// Assert.AreEqual (1, unit.Types.Count);
-// IType type = unit.Types[0];
-//
-// Assert.AreEqual (2, type.MethodCount);
-// List<IMethod> methods = new List<IMethod> (type.Methods);
-// Assert.AreEqual ("TestMethod", methods[0].Name);
-// Assert.AreEqual (2, methods[0].Parameters.Count);
-// Assert.AreEqual ("a", methods[0].Parameters[0].Name);
-// Assert.AreEqual ("b", methods[0].Parameters[1].Name);
-//
-// Assert.IsFalse (methods[1].IsConstructor);
-// Assert.IsTrue (methods[1].IsExtension);
-// Assert.AreEqual (1, methods[1].Parameters.Count);
-// Assert.AreEqual ("a", methods[1].Parameters[0].Name);
-// }
-//
-// [Test]
-// public void TestMethods ()
-// {
-// DoTestMethods (new McsParser ());
-//// DoTestMethods (new DomParser ());
-// }
-//
-// void DoTestConstructor (IParser parser)
-// {
-// ICompilationUnit unit = parser.Parse (null, "a.cs",
-//@"public abstract class BaseClass {
-// BaseClass () {}
-// protected BaseClass(int id)
-// {
-// }
-//}").CompilationUnit;
-// Assert.AreEqual (1, unit.Types.Count);
-// IType type = unit.Types[0];
-//
-// Assert.AreEqual (2, type.ConstructorCount);
-// List<IMethod> methods = new List<IMethod> (type.Methods);
-// Assert.IsTrue (methods[0].IsConstructor);
-// Assert.IsTrue (methods[1].IsConstructor);
-// }
-//
-// [Test]
-// public void TestConstructor ()
-// {
-// DoTestConstructor (new McsParser ());
-//// DoTestConstructor (new DomParser ());
-// }
-//
-// void DoTestProperties (IParser parser)
-// {
-// ICompilationUnit unit = parser.Parse (null, "a.cs",
-//@"class AClass {
-// int MyProperty {
-// get { }
-// set { }
-// }
-// string MyProperty2 {
-// set { }
-// }
-// string MyProperty3 {
-// get { }
-// }
-//}").CompilationUnit;
-// Assert.AreEqual (1, unit.Types.Count);
-// IType type = unit.Types[0];
-//
-// Assert.AreEqual (3, type.PropertyCount);
-// List<IProperty> properties = new List<IProperty> (type.Properties);
-// Assert.AreEqual ("MyProperty", properties[0].Name);
-// Assert.IsTrue (properties[0].HasGet);
-// Assert.IsTrue (properties[0].HasSet);
-// Assert.IsFalse (properties[0].IsIndexer);
-//
-// Assert.AreEqual ("MyProperty2", properties[1].Name);
-// Assert.IsFalse (properties[1].HasGet);
-// Assert.IsTrue (properties[1].HasSet);
-// Assert.IsFalse (properties[1].IsIndexer);
-//
-// Assert.AreEqual ("MyProperty3", properties[2].Name);
-// Assert.IsTrue (properties[2].HasGet);
-// Assert.IsFalse (properties[2].HasSet);
-// Assert.IsFalse (properties[2].IsIndexer);
-// }
-//
-// [Test]
-// public void TestProperties ()
-// {
-// DoTestProperties (new McsParser ());
-//// DoTestProperties (new DomParser ());
-// }
-//
-// void DoTestIndexer (IParser parser)
-// {
-// ICompilationUnit unit = parser.Parse (null, "a.cs",
-//@"class AClass {
-// int this[int a] {
-// get { }
-// set { }
-// }
-//}").CompilationUnit;
-// Assert.AreEqual (1, unit.Types.Count);
-// IType type = unit.Types[0];
-//
-// Assert.AreEqual (1, type.IndexerCount);
-// List<IProperty> properties = new List<IProperty> (type.Properties);
-// Assert.IsTrue (properties[0].IsIndexer);
-// Assert.AreEqual (1, properties[0].Parameters.Count);
-// Assert.AreEqual ("a", properties[0].Parameters[0].Name);
-// }
-//
-// [Test]
-// public void TestIndexer ()
-// {
-// DoTestIndexer (new McsParser ());
-//// DoTestIndexer (new DomParser ());
-// }
-//
-// void DoTestEvents (IParser parser)
-// {
-// ICompilationUnit unit = parser.Parse (null, "a.cs",
-//@"class AClass {
-// event EventHandler TestEvent;
-//}").CompilationUnit;
-// Assert.AreEqual (1, unit.Types.Count);
-// IType type = unit.Types[0];
-//
-// Assert.AreEqual (1, type.EventCount);
-// List<IEvent> events = new List<IEvent> (type.Events);
-// Assert.AreEqual ("TestEvent", events[0].Name);
-// Assert.AreEqual ("EventHandler", events[0].ReturnType.Name);
-// }
-//
-// [Test]
-// public void TestEvents ()
-// {
-// DoTestEvents (new McsParser ());
-//// DoTestEvents (new DomParser ());
-// }
-//
-// }
-//}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/NamedArgumentCompletionTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/NamedArgumentCompletionTests.cs
index edb713bd35..90349d23c5 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/NamedArgumentCompletionTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/NamedArgumentCompletionTests.cs
@@ -26,23 +26,18 @@
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.Core;
+using MonoDevelop.Ide.Editor;
+using MonoDevelop.Ide.Editor.Extension;
+using Microsoft.CodeAnalysis;
+using MonoDevelop.Projects;
+using MonoDevelop.Core.ProgressMonitoring;
+using MonoDevelop.Ide.TypeSystem;
namespace MonoDevelop.CSharpBinding
{
@@ -51,11 +46,14 @@ namespace MonoDevelop.CSharpBinding
{
class TestCompletionWidget : ICompletionWidget
{
- Document doc;
+ DocumentContext documentContext;
- public TestCompletionWidget (Document doc)
+ TextEditor editor;
+
+ public TestCompletionWidget (MonoDevelop.Ide.Editor.TextEditor editor, DocumentContext documentContext)
{
- this.doc = doc;
+ this.editor = editor;
+ this.documentContext = documentContext;
}
public string CompletedWord {
@@ -70,17 +68,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,
@@ -94,7 +92,7 @@ namespace MonoDevelop.CSharpBinding
public CodeCompletionContext CurrentCodeCompletionContext {
get {
- return CreateCodeCompletionContext (doc.Editor.Caret.Offset);
+ return CreateCodeCompletionContext (editor.CaretOffset);
}
}
@@ -119,13 +117,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;
}
}
@@ -140,19 +141,30 @@ namespace MonoDevelop.CSharpBinding
return null;
}
}
+
+ double ICompletionWidget.ZoomLevel {
+ get {
+ return 1;
+ }
+ }
+
+ void ICompletionWidget.AddSkipChar (int cursorPosition, char c)
+ {
+ // ignore
+ }
#endregion
}
static CSharpCompletionTextEditorExtension Setup (string input, out TestViewContent content)
{
- TestWorkbenchWindow tww = new TestWorkbenchWindow ();
+ var 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 ('$');
@@ -162,12 +174,25 @@ 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));
+
+ 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;
}
@@ -176,17 +201,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 t = ext.Document.Compilation.FindType (new FullTypeName (type));
- var foundMember = t.GetMembers (m => m.Name == member).First ();
- var data = new MemberCompletionData (ext, foundMember, OutputFlags.ClassBrowserEntries);
- data.DisplayFlags |= ICSharpCode.NRefactory.Completion.DisplayFlags.NamedArgument;
+ var sm = ext.DocumentContext.ParsedDocument.GetAst<SemanticModel> ();
+
+ var t = sm.Compilation.GetTypeByMetadataName (type);
+ var foundMember = t.GetMembers().First (m => m.Name == member);
+ var data = new RoslynSymbolCompletionData (null, ext, foundMember);
+ data.DisplayFlags |= DisplayFlags.NamedArgument;
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;
}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs
index e024ac162f..63c9900409 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs
@@ -26,37 +26,35 @@
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;
-using MonoDevelop.Ide.Gui.Content;
using MonoDevelop.CSharp.Formatting;
-using UnitTests;
-using MonoDevelop.Projects.Policies;
using MonoDevelop.CSharp.Completion;
using MonoDevelop.CSharpBinding.Tests;
+using MonoDevelop.Ide.Editor;
+using MonoDevelop.Ide.Editor.Extension;
+using MonoDevelop.Projects;
+using MonoDevelop.Core.ProgressMonitoring;
namespace MonoDevelop.CSharpBinding
{
[TestFixture]
public class OnTheFlyFormatterTests : UnitTests.TestBase
{
- static CSharpTextEditorIndentation Setup (string input, out TestViewContent content)
+ static void Simulate (string input, Action<TestViewContent, CSharpTextEditorIndentation> act)
{
TestWorkbenchWindow tww = new TestWorkbenchWindow ();
- content = new TestViewContent ();
- content.Data.Options.IndentStyle = IndentStyle.Auto;
+ var content = new TestViewContent ();
+ content.Data.Options = new CustomEditorOptions {
+ IndentStyle = IndentStyle.Auto
+ };
+
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 Document (tww);
var sb = new StringBuilder ();
int cursorPosition = 0, selectionStart = -1, selectionEnd = -1;
@@ -94,70 +92,153 @@ namespace MonoDevelop.CSharpBinding
content.Text = sb.ToString ();
content.CursorPosition = cursorPosition;
+ 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 (Projects.Policies.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);
var ext = new CSharpTextEditorIndentation ();
CSharpTextEditorIndentation.OnTheFlyFormatting = true;
- ext.Initialize (doc);
+ ext.Initialize (doc.Editor, doc);
content.Contents.Add (ext);
doc.UpdateParseDocument ();
if (selectionStart >= 0 && selectionEnd >= 0)
content.GetTextEditorData ().SetSelection (selectionStart, selectionEnd);
- return ext;
+ try {
+ act (content, ext);
+ } finally {
+ TypeSystemService.Unload (solution);
+ }
}
- [Ignore("Semicolon formatting partially deactivated.")]
[Test]
public void TestSemicolon ()
{
- TestViewContent content;
- var ext = Setup (@"class Foo
+ Simulate (@"class Foo
{
void Test ()
{
Console.WriteLine () ;$
}
-}", out content);
- ext.KeyPress (Gdk.Key.semicolon, ';', Gdk.ModifierType.None);
+}", (content, ext) => {
+ ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.semicolon, ';', Gdk.ModifierType.None));
- var newText = content.Text;
- Assert.AreEqual (@"class Foo
+ var newText = content.Text;
+ Assert.AreEqual (@"class Foo
{
void Test ()
{
- Console.WriteLine ();
+ Console.WriteLine();
}
}", newText);
-
+ });
}
- [Ignore("FIXME")]
[Test]
public void TestCloseBrace ()
{
- TestViewContent content;
- var ext = Setup (@"class Foo
+ Simulate (@"class Foo
{
void Test ()
{
Console.WriteLine() ;
}$
-}", out content);
- ext.KeyPress (Gdk.Key.braceright, '}', Gdk.ModifierType.None);
+}", (content, ext) => {
+ ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.braceright, '}', Gdk.ModifierType.None));
+
+ var newText = content.Text;
+ Console.WriteLine (newText);
+ Assert.AreEqual (@"class Foo
+{
+ void Test()
+ {
+ Console.WriteLine();
+ }
+}", newText);
+ });
+
+ }
+
+ [Test]
+ public void TestCloseBraceIf ()
+ {
+ //Notice that some text stay unformatted by design
+ Simulate (@"class Foo
+{
+ void Test ()
+ {
+ Console.WriteLine() ;
+ if(true){
+ Console.WriteLine() ;
+ }$
+ }
+}", (content, ext) => {
+ ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.braceright, '}', Gdk.ModifierType.None));
- var newText = content.Text;
- Console.WriteLine (newText);
- Assert.AreEqual (@"class Foo
+ var newText = content.Text;
+ Console.WriteLine (newText);
+ Assert.AreEqual (@"class Foo
{
void Test ()
- {
- Console.WriteLine ();
+ {
+ Console.WriteLine() ;
+ if (true)
+ {
+ Console.WriteLine();
+ }
}
}", newText);
+ });
+ }
+ [Test]
+ public void TestCloseBraceCatch ()
+ {
+ //Notice that some text stay unformatted by design
+ Simulate (@"class Foo
+{
+ void Test ()
+ {
+ Console.WriteLine() ;
+ try{
+ Console.WriteLine() ;
+ }catch(Exception e){
+ }$
+ }
+}", (content, ext) => {
+ ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.braceright, '}', Gdk.ModifierType.None));
+
+ var newText = content.Text;
+ Console.WriteLine (newText);
+ Assert.AreEqual (@"class Foo
+{
+ void Test ()
+ {
+ Console.WriteLine() ;
+ try
+ {
+ Console.WriteLine();
+ }
+ catch (Exception e)
+ {
+ }
+ }
+}", newText);
+ });
}
@@ -167,34 +248,34 @@ namespace MonoDevelop.CSharpBinding
[Test]
public void TestBug5080 ()
{
- TestViewContent content;
- var ext = Setup ("\"Hello\n\t$", out content);
- ext.ReindentOnTab ();
+ Simulate ("\"Hello\n\t$", (content, ext) => {
+ ext.ReindentOnTab ();
- var newText = content.Text;
- Assert.AreEqual ("\"Hello\n", newText);
+ var newText = content.Text;
+ Assert.AreEqual ("\"Hello\n", newText);
+ });
}
[Test]
public void TestVerbatimToNonVerbatimConversion ()
{
- TestViewContent content;
- Setup ("@$\"\t\"", out content);
- content.GetTextEditorData ().Remove (0, 1);
- var newText = content.Text;
- Assert.AreEqual ("\"\\t\"", newText);
+ Simulate ("@$\"\t\"", (content, ext) => {
+ content.Data.RemoveText (0, 1);
+ var newText = content.Text;
+ Assert.AreEqual ("\"\\t\"", newText);
+ });
}
[Test]
public void TestNonVerbatimToVerbatimConversion ()
{
- TestViewContent content;
- var ext = Setup ("$\"\\t\"", out content);
- content.GetTextEditorData ().Insert (0, "@");
- ext.KeyPress ((Gdk.Key)'@', '@', Gdk.ModifierType.None);
- var newText = content.Text;
- Assert.AreEqual ("@\"\t\"", newText);
+ Simulate ("$\"\\t\"", (content, ext) => {
+ content.Data.InsertText (0, "@");
+ ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'@', '@', Gdk.ModifierType.None));
+ var newText = content.Text;
+ Assert.AreEqual ("@\"\t\"", newText);
+ });
}
/// <summary>
@@ -203,36 +284,36 @@ namespace MonoDevelop.CSharpBinding
[Test]
public void TestBug14686 ()
{
- TestViewContent content;
- var ext = Setup ("$\"\\\\\"", out content);
- content.GetTextEditorData ().Insert (0, "@");
- ext.KeyPress ((Gdk.Key)'@', '@', Gdk.ModifierType.None);
- var newText = content.Text;
- Assert.AreEqual ("@\"\\\"", newText);
+ Simulate ("$\"\\\\\"", (content, ext) => {
+ content.Data.InsertText (0, "@");
+ ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'@', '@', Gdk.ModifierType.None));
+ var newText = content.Text;
+ Assert.AreEqual ("@\"\\\"", newText);
+ });
}
[Test]
public void TestBug14686Case2 ()
{
- TestViewContent content;
- var ext = Setup ("$\"\\\"", out content);
- content.GetTextEditorData ().Insert (0, "@");
- ext.KeyPress ((Gdk.Key)'@', '@', Gdk.ModifierType.None);
- var newText = content.Text;
- Assert.AreEqual ("@\"\\\"", newText);
-
- ext = Setup ("$\"\\\"a", out content);
- content.GetTextEditorData ().Insert (0, "@");
- ext.KeyPress ((Gdk.Key)'@', '@', Gdk.ModifierType.None);
- newText = content.Text;
- Assert.AreEqual ("@\"\\\"a", newText);
+ Simulate ("$\"\\\"", (content, ext) => {
+ content.Data.InsertText (0, "@");
+ ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'@', '@', Gdk.ModifierType.None));
+ var newText = content.Text;
+ Assert.AreEqual ("@\"\\\"", newText);
+ });
+
+ Simulate ("$\"\\\"a", (content, ext) => {
+ content.Data.InsertText (0, "@");
+ ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'@', '@', Gdk.ModifierType.None));
+ var newText = content.Text;
+ Assert.AreEqual ("@\"\\\"a", newText);
+ });
}
[Test]
public void TestCorrectReindentNextLine ()
{
- TestViewContent content;
- var ext = Setup (@"
+ Simulate (@"
class Foo
{
void Bar ()
@@ -241,14 +322,14 @@ class Foo
} catch (Exception e) {$}
}
}
-", out content);
- ext.ReindentOnTab ();
- MiscActions.InsertNewLine (content.Data);
- ext.KeyPress ((Gdk.Key)'\n', '\n', Gdk.ModifierType.None);
+", (content, ext) => {
+ ext.ReindentOnTab ();
+ EditActions.NewLine (ext.Editor);
+ ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'\n', '\n', Gdk.ModifierType.None));
- var newText = content.Text;
+ var newText = content.Text;
- var expected = @"
+ var expected = @"
class Foo
{
void Bar ()
@@ -259,9 +340,10 @@ class Foo
}
}
";
- if (newText != expected)
- Console.WriteLine (newText);
- Assert.AreEqual (expected, newText);
+ if (newText != expected)
+ Console.WriteLine (newText);
+ Assert.AreEqual (expected, newText);
+ });
}
/// <summary>
@@ -270,37 +352,39 @@ class Foo
[Test]
public void TestBug16174_AutoIndent ()
{
- TestViewContent content;
-
- var ext = Setup ("namespace Foo\n{\n\tpublic class Bar\n\t{\n$\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n", out content);
- ext.document.Editor.Options.IndentStyle = IndentStyle.Auto;
- MiscActions.InsertNewLine (content.Data);
- ext.KeyPress (Gdk.Key.Return, '\n', Gdk.ModifierType.None);
-
- var newText = content.Text;
-
- var expected = "namespace Foo\n{\n\tpublic class Bar\n\t{\n\n\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n";
- if (newText != expected)
- Console.WriteLine (newText);
- Assert.AreEqual (expected, newText);
+ Simulate ("namespace Foo\n{\n\tpublic class Bar\n\t{\n$\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n", (content, ext) => {
+ var options = DefaultSourceEditorOptions.Instance;
+ options.IndentStyle = IndentStyle.Auto;
+ ext.Editor.Options = options;
+ EditActions.NewLine (ext.Editor);
+ ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.Return, '\n', Gdk.ModifierType.None));
+
+ var newText = content.Text;
+
+ var expected = "namespace Foo\n{\n\tpublic class Bar\n\t{\n\n\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n";
+ if (newText != expected)
+ Console.WriteLine (newText);
+ Assert.AreEqual (expected, newText);
+ });
}
[Test]
public void TestBug16174_VirtualIndent ()
{
- TestViewContent content;
-
- var ext = Setup ("namespace Foo\n{\n\tpublic class Bar\n\t{\n$\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n", out content);
- ext.document.Editor.Options.IndentStyle = IndentStyle.Virtual;
- MiscActions.InsertNewLine (content.Data);
- ext.KeyPress (Gdk.Key.Return, '\n', Gdk.ModifierType.None);
-
- var newText = content.Text;
-
- var expected = "namespace Foo\n{\n\tpublic class Bar\n\t{\n\n\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n";
- if (newText != expected)
- Console.WriteLine (newText);
- Assert.AreEqual (expected, newText);
+ Simulate ("namespace Foo\n{\n\tpublic class Bar\n\t{\n$\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n", (content, ext) => {
+ var options = DefaultSourceEditorOptions.Instance;
+ options.IndentStyle = IndentStyle.Virtual;
+ ext.Editor.Options = options;
+ EditActions.NewLine (ext.Editor);
+ ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.Return, '\n', Gdk.ModifierType.None));
+
+ var newText = content.Text;
+
+ var expected = "namespace Foo\n{\n\tpublic class Bar\n\t{\n\n\t\tvoid Test()\n\t\t{\n\t\t}\n\t}\n}\n";
+ if (newText != expected)
+ Console.WriteLine (newText);
+ Assert.AreEqual (expected, newText);
+ });
}
@@ -310,12 +394,12 @@ class Foo
[Test]
public void TestBug16283 ()
{
- TestViewContent content;
- var ext = Setup ("$\"\\dev\\null {0}\"", out content);
- content.GetTextEditorData ().Insert (0, "@");
- ext.KeyPress ((Gdk.Key)'@', '@', Gdk.ModifierType.None);
- var newText = content.Text;
- Assert.AreEqual ("@\"\\dev\null {0}\"", newText);
+ Simulate ("$\"\\dev\\null {0}\"", (content, ext) => {
+ content.Data.InsertText (0, "@");
+ ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'@', '@', Gdk.ModifierType.None));
+ var newText = content.Text;
+ Assert.AreEqual ("@\"\\dev\null {0}\"", newText);
+ });
}
/// <summary>
@@ -324,8 +408,7 @@ class Foo
[Test]
public void TestBug17765 ()
{
- TestViewContent content;
- var ext = Setup (@"
+ Simulate (@"
namespace FormatSelectionTest
{
public class EmptyClass
@@ -334,24 +417,51 @@ namespace FormatSelectionTest
{
}->
}
-}", out content);
+}", (content, ext) => {
- OnTheFlyFormatter.Format (ext.document, ext.document.Editor.SelectionRange.Offset, ext.document.Editor.SelectionRange.EndOffset);
+ OnTheFlyFormatter.Format (ext.Editor, ext.DocumentContext, ext.Editor.SelectionRange.Offset, ext.Editor.SelectionRange.EndOffset);
- Assert.AreEqual (@"
+ Assert.AreEqual (@"
namespace FormatSelectionTest
{
public class EmptyClass
{
- public EmptyClass ()
+ public EmptyClass()
{
}
}
-}", ext.document.Editor.Text);
+}", ext.Editor.Text);
+ });
}
+ [Test]
+ public void TestAfterCommentLine ()
+ {
+ Simulate (@"class Foo
+{
+ void Test ()
+ {
+ //random comment
+ Console.WriteLine () ;$
+ }
+}", (content, ext) => {
+ content.Data.Options = new CustomEditorOptions {
+ IndentStyle = IndentStyle.Virtual
+ };
+ ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.semicolon, ';', Gdk.ModifierType.None));
+
+ var newText = content.Text;
+ Assert.AreEqual (@"class Foo
+{
+ void Test ()
+ {
+ //random comment
+ Console.WriteLine();
+ }
+}", newText);
+ });
+ }
}
-
}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/ProjectDomTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/ProjectDomTests.cs
deleted file mode 100644
index 37045dedc3..0000000000
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/ProjectDomTests.cs
+++ /dev/null
@@ -1,174 +0,0 @@
-//
-// ProjectDomTests.cs
-//
-// Author:
-// Mike Krüger <mkrueger@novell.com>
-//
-// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-using NUnit.Framework;
-using MonoDevelop.Ide.Gui;
-using MonoDevelop.Projects;
-using MonoDevelop.Core;
-using MonoDevelop.Ide.CodeCompletion;
-using MonoDevelop.Ide.Gui.Content;
-
-namespace MonoDevelop.CSharpBinding
-{
-/* [TestFixture()]
- public class ProjectDomTests : UnitTests.TestBase
- {
- public delegate void DomCallback (ProjectDom dom);
-
- public static void CheckDomCorrectness (IType type, DomCallback callback)
- {
- CheckDomCorrectness (new IType[] { type }, callback);
- }
-
- public static void CheckDomCorrectness (IEnumerable<IType> types, DomCallback callback)
- {
- //IParserDatabase database = new MonoDevelop.Projects.Dom.MemoryDatabase.MemoryDatabase ();
- IParserDatabase database = new MonoDevelop.Projects.Dom.Serialization.ParserDatabase ();
- ProjectDom dom = database.LoadSingleFileDom ("a.cs");
- Console.WriteLine ("dom:" + dom);
- CompilationUnit unit = new CompilationUnit ("a.cs");
- foreach (IType type in types) {
- unit.Add (type);
- }
- dom.UpdateFromParseInfo (unit);
- callback (dom);
- }
-
- [Test()]
- public void TestTypeInstantiation ()
- {
- DomType type = new DomType () {
- Name = "MyClass",
- ClassType = ClassType.Class
- };
- type.AddTypeParameter (new TypeParameter ("T"));
- IProperty prop = new DomProperty () {
- Name = "Prop",
- ReturnType = new DomReturnType ("T")
- };
- type.Add (prop);
-
-
- CheckDomCorrectness (type, delegate (ProjectDom dom) {
- IType result = dom.GetType ("MyClass", new IReturnType [] { new DomReturnType ("SomeNamespace.OtherType") }, true, true);
- Assert.IsNotNull (result);
- prop = result.Properties.FirstOrDefault ();
- Assert.IsNotNull (prop);
- Assert.AreEqual ("SomeNamespace.OtherType", prop.ReturnType.FullName);
- });
- }
-
- [Test()]
- public void TestGetNamespaceExists ()
- {
- CheckDomCorrectness (new DomType ("A.B.C.TestClass"), delegate (ProjectDom dom) {
- Assert.IsTrue (dom.NamespaceExists("A"));
- Assert.IsTrue (dom.NamespaceExists("A.B"));
- Assert.IsTrue (dom.NamespaceExists("A.B.C"));
- Assert.IsFalse (dom.NamespaceExists("B"));
- Assert.IsFalse (dom.NamespaceExists("C"));
- Assert.IsFalse (dom.NamespaceExists("B.C"));
- Assert.IsFalse (dom.NamespaceExists("A.C"));
- Assert.IsFalse (dom.NamespaceExists(".B"));
- Assert.IsFalse (dom.NamespaceExists(".C"));
- });
- }
-
- [Test()]
- public void TestGetInheritanceTree ()
- {
- DomType[] types = new DomType[] {
- new DomType ("A"),
- new DomType ("B") {
- BaseType = new DomReturnType ("A")
- },
- new DomType ("C") {
- BaseType = new DomReturnType ("B")
- }
- };
-
- CheckDomCorrectness (types, delegate (ProjectDom dom) {
- IType result = dom.GetType ("C");
- Assert.IsNotNull (result);
- HashSet<string> resTypes = new HashSet<string> ();
- foreach (IType t in dom.GetInheritanceTree (result)) {
- resTypes.Add (t.FullName);
- }
- Assert.IsTrue (resTypes.Contains ("A"));
- Assert.IsTrue (resTypes.Contains ("B"));
- Assert.IsTrue (resTypes.Contains ("C"));
- });
- }
-
- [Test()]
- public void TestGetInnerInheritedType ()
- {
- DomType[] types = new DomType[] {
- new DomType ("A"),
- new DomType ("B") {
- BaseType = new DomReturnType ("A")
- }
- };
- types[0].Add (new DomType ("Inner"));
-
- CheckDomCorrectness (types, delegate (ProjectDom dom) {
- IType result = dom.GetType ("B.Inner");
- Assert.IsNotNull (result);
- });
- }
-
- [Test()]
- public void TestGetSubclasses ()
- {
- DomType[] types = new DomType[] {
- new DomType ("A"),
- new DomType ("B") {
- BaseType = new DomReturnType ("A")
- },
- new DomType ("C") {
- BaseType = new DomReturnType ("B")
- }
- };
-
- CheckDomCorrectness (types, delegate (ProjectDom dom) {
- IType result = dom.GetType ("A");
- Assert.IsNotNull (result);
- HashSet<string> resTypes = new HashSet<string> ();
- foreach (IType t in dom.GetSubclasses (result)) {
- resTypes.Add (t.FullName);
- }
- Assert.IsTrue (resTypes.Contains ("A"));
- Assert.IsTrue (resTypes.Contains ("B"));
- Assert.IsTrue (resTypes.Contains ("C"));
- });
- }
- }
- */
-}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestDocument.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestDocument.cs
index 8803593ed1..58a979c0ef 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestDocument.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestDocument.cs
@@ -45,12 +45,12 @@ namespace MonoDevelop.CSharpBinding
public IProjectContent HiddenProjectContent;
- public override IProjectContent GetProjectContext ()
- {
- if (HiddenProjectContent != null)
- return HiddenProjectContent;
- return base.GetProjectContext ();
- }
+// public override IProjectContent GetProjectContext ()
+// {
+// if (HiddenProjectContent != null)
+// return HiddenProjectContent;
+// return base.GetProjectContext ();
+// }
}
}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs
index 698686bd2a..2886fd80c8 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs
@@ -29,16 +29,17 @@
using System;
using System.Linq;
using System.Collections.Generic;
-using Mono.TextEditor;
using MonoDevelop.Core;
using MonoDevelop.Ide.Gui;
using MonoDevelop.Ide.Gui.Content;
+using MonoDevelop.Ide.Editor;
+using MonoDevelop.Core.Text;
namespace MonoDevelop.CSharpBinding.Tests
{
- public class TestViewContent : AbstractViewContent, IEditableTextBuffer, Mono.TextEditor.ITextEditorDataProvider
+ public class TestViewContent : AbstractViewContent
{
- TextEditorData data;
+ TextEditor data;
public override Gtk.Widget Control {
get {
@@ -46,85 +47,84 @@ namespace MonoDevelop.CSharpBinding.Tests
}
}
- public TextEditorData Data {
+ public TextEditor Data {
get {
return this.data;
}
}
public TestViewContent ()
{
- document = new Mono.TextEditor.TextDocument ();
- data = new TextEditorData (document);
+ data = TextEditorFactory.CreateNewEditor ();
+ Contents.Add (data);;
Name = "";
}
- public TestViewContent (TextEditorData data)
+ public TestViewContent (IReadonlyTextDocument doc)
{
- this.document = data.Document;
- this.data = data;
+ data = TextEditorFactory.CreateNewEditor (doc);
+ Contents.Add (data);
Name = "";
}
- public override void Load(string fileName)
+ public override void Load(FileOpenInformation fileOpenInformation)
{
}
FilePath name;
public FilePath Name {
get { return name; }
- set { name = document.FileName = value; }
+ set { name = data.FileName = value; }
}
public int LineCount {
get {
- return document.LineCount;
+ return data.LineCount;
}
}
-
- Mono.TextEditor.TextDocument document;
+
public string Text {
get {
- return document.Text;
+ return data.Text;
}
set {
- document.Text = value;
+ data.Text = value;
}
}
public int InsertText (int position, string text)
{
- document.Insert (position, text);
+ data.InsertText (position, text);
return text.Length;
}
public void DeleteText (int position, int length)
{
- document.Replace (position, length, "");
+ data.ReplaceText (position, length, "");
}
public int Length {
get {
- return document.TextLength;
+ return data.Length;
}
}
public string GetText (int startPosition, int endPosition)
{
- return document.GetTextBetween (startPosition, endPosition);
+ return data.GetTextBetween (startPosition, endPosition);
}
public char GetCharAt (int position)
{
- return document.GetCharAt (position);
+ return data.GetCharAt (position);
}
public int GetPositionFromLineColumn (int line, int column)
{
- return document.LocationToOffset (line, column);
+ return data.LocationToOffset (line, column);
}
public void GetLineColumnFromPosition (int position, out int line, out int column)
{
- DocumentLocation loc = document.OffsetToLocation (position);
+ var loc = data.OffsetToLocation (position);
line = loc.Line;
column = loc.Column;
}
@@ -133,17 +133,17 @@ namespace MonoDevelop.CSharpBinding.Tests
public int CursorPosition {
get {
- return data.Caret.Offset;
+ return data.CaretOffset;
}
set {
- data.Caret.Offset = value;
+ data.CaretOffset = value;
}
}
public int SelectionStartPosition {
get {
if (!data.IsSomethingSelected)
- return data.Caret.Offset;
+ return data.CaretOffset;
return data.SelectionRange.Offset;
}
}
@@ -151,14 +151,14 @@ namespace MonoDevelop.CSharpBinding.Tests
public int SelectionEndPosition {
get {
if (!data.IsSomethingSelected)
- return data.Caret.Offset;
+ return data.CaretOffset;
return data.SelectionRange.EndOffset;
}
}
public void Select (int startPosition, int endPosition)
{
- data.SelectionRange = new TextSegment (startPosition, endPosition - startPosition);
+ data.SelectionRange = TextSegment.FromBounds (startPosition, endPosition);
}
public void ShowPosition (int position)
@@ -204,15 +204,20 @@ namespace MonoDevelop.CSharpBinding.Tests
public override object GetContent (Type type)
{
- return Contents.FirstOrDefault (o => type.IsInstanceOfType (type)) ?? base.GetContent (type);
+ return Contents.FirstOrDefault (type.IsInstanceOfType) ?? base.GetContent (type);
}
-
+
+ public override IEnumerable<T> GetContents<T> ()
+ {
+ return Contents.OfType<T> ();
+ }
+
public IDisposable OpenUndoGroup ()
{
return new DisposeStub ();
}
- public TextEditorData GetTextEditorData ()
+ public TextEditor GetTextEditorData ()
{
return data;
}
@@ -230,6 +235,5 @@ namespace MonoDevelop.CSharpBinding.Tests
}
#endregion
public event EventHandler CaretPositionSet;
- public event EventHandler<TextChangedEventArgs> TextChanged;
}
}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/UnitTesteditorIntegrationTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/UnitTesteditorIntegrationTests.cs
index 9a7e8e1077..237e7e08de 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/UnitTesteditorIntegrationTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/UnitTesteditorIntegrationTests.cs
@@ -25,13 +25,16 @@
// THE SOFTWARE.
using System;
-using System.Collections;
using MonoDevelop.Ide.Gui;
using System.Collections.Generic;
-using Mono.Addins;
using NUnit.Framework;
using MonoDevelop.CSharp;
+using System.Threading;
+using MonoDevelop.Projects;
+using MonoDevelop.Ide.TypeSystem;
+using MonoDevelop.Ide;
+using MonoDevelop.Core.ProgressMonitoring;
namespace MonoDevelop.CSharpBinding.Tests
{
@@ -40,19 +43,18 @@ namespace MonoDevelop.CSharpBinding.Tests
{
static UnitTestTextEditorExtension Setup (string input, out TestViewContent content)
{
- TestWorkbenchWindow tww = new TestWorkbenchWindow ();
+ var tww = new TestWorkbenchWindow ();
content = new TestViewContent ();
tww.ViewContent = content;
- content.ContentName = "a.cs";
- content.GetTextEditorData ().Document.MimeType = "text/x-csharp";
-
- Document doc = new Document (tww);
+ content.ContentName = "/a.cs";
+ content.Data.MimeType = "text/x-csharp";
+ MonoDevelop.AnalysisCore.AnalysisOptions.EnableUnitTestEditorIntegration.Set (true);
+ var doc = new Document (tww);
var text = @"namespace NUnit.Framework {
- using System;
- class TestFixtureAttribute : Attribute {}
- class TestAttribute : Attribute {}
-} namespace Test { " + input +"}";
+ public class TestFixtureAttribute : System.Attribute {}
+ public class TestAttribute : System.Attribute {}
+} namespace TestNs { " + input +"}";
int endPos = text.IndexOf ('$');
if (endPos >= 0)
text = text.Substring (0, endPos) + text.Substring (endPos + 1);
@@ -60,28 +62,46 @@ namespace MonoDevelop.CSharpBinding.Tests
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 ("/a.cs", BuildAction.Compile));
+
+ var solution = new 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 UnitTestTextEditorExtension ();
- compExt.Initialize (doc);
+ compExt.Initialize (doc.Editor, doc);
content.Contents.Add (compExt);
-
doc.UpdateParseDocument ();
+ TypeSystemService.Unload (solution);
return compExt;
}
+ protected override void InternalSetup (string rootDir)
+ {
+ base.InternalSetup (rootDir);
+ IdeApp.Initialize (new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor ());
+ }
+
[Test]
public void TestSimple ()
{
TestViewContent content;
var ext = Setup (@"using NUnit.Framework;
[TestFixture]
-class Test
+class TestClass
{
[Test]
public void MyTest () {}
}
", out content);
- var tests = ext.GatherUnitTests ();
+ var tests = ext.GatherUnitTests (default(CancellationToken)).Result;
Assert.IsNotNull (tests);
Assert.AreEqual (2, tests.Count);
}
@@ -91,12 +111,12 @@ class Test
{
TestViewContent content;
var ext = Setup (@"using NUnit.Framework;
-class Test
+class TestClass
{
public void MyTest () {}
}
", out content);
- var tests = ext.GatherUnitTests ();
+ var tests = ext.GatherUnitTests (default(CancellationToken)).Result;
Assert.IsNotNull (tests);
Assert.AreEqual (0, tests.Count);
}
@@ -122,13 +142,34 @@ public class Derived : MyBase
public void MyTest () {}
}
", out content);
- var tests = ext.GatherUnitTests ();
+ var tests = ext.GatherUnitTests (default(CancellationToken)).Result;
Assert.IsNotNull (tests);
Assert.AreEqual (2, tests.Count);
- Assert.AreEqual ("Test.Derived", tests [0].UnitTestIdentifier);
- Assert.AreEqual ("Test.Derived.MyTest", tests [1].UnitTestIdentifier);
+ Assert.AreEqual ("TestNs.Derived", tests [0].UnitTestIdentifier);
+ Assert.AreEqual ("TestNs.Derived.MyTest", tests [1].UnitTestIdentifier);
}
+
+
+ /// <summary>
+ /// Bug 19651 - Should not require [TestFixture] for Unit Test Integration
+ /// </summary>
+ [Test]
+ public void TestBug19651 ()
+ {
+ TestViewContent content;
+ var ext = Setup (@"using NUnit.Framework;
+class TestClass
+{
+ [Test]
+ public void MyTest () {}
+}
+", out content);
+ var tests = ext.GatherUnitTests (default(CancellationToken)).Result;
+ Assert.IsNotNull (tests);
+ Assert.AreEqual (2, tests.Count);
+ }
+
}
}