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')
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/GenerateNewMemberTests.cs90
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/ResolveNamespaceTests.cs413
-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
-rw-r--r--main/tests/UnitTests/MonoDevelop.Core/BacktrackingStringMatcherTests.cs15
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs207
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/SortSelectedLinesTests.cs66
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/ReadonlyTextDocumentTestBase.cs164
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs55
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/MonoTextEditorImplementationTests.cs56
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/SimpleReadonlyDocument_Tests.cs41
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/StringTextSource_Tests.cs47
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/TextDocumentTestBase.cs173
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorProjectionTests.cs78
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorTestBase.cs45
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/TextSourceTestBase.cs169
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs9
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs632
-rwxr-xr-xmain/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs205
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs162
-rw-r--r--main/tests/UnitTests/MonoDevelop.Projects/CompletionDatabaseTests.cs889
-rw-r--r--main/tests/UnitTests/MonoDevelop.Projects/DomCompilationUnitTests.cs133
-rw-r--r--main/tests/UnitTests/MonoDevelop.Projects/DomPersistenceTests.cs457
-rw-r--r--main/tests/UnitTests/MonoDevelop.Projects/DomTests.cs228
-rw-r--r--main/tests/UnitTests/MonoDevelop.Projects/SolutionTests.cs2
-rw-r--r--main/tests/UnitTests/MonoDevelop.SourceEditor/DebugTooltipTests.cs67
-rw-r--r--main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs45
-rw-r--r--main/tests/UnitTests/TestBase.cs5
-rw-r--r--main/tests/UnitTests/UnitTests.csproj70
-rw-r--r--main/tests/UnitTests/packages.config7
38 files changed, 1954 insertions, 3722 deletions
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/GenerateNewMemberTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/GenerateNewMemberTests.cs
index c83146a734..1751e877d1 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/GenerateNewMemberTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/GenerateNewMemberTests.cs
@@ -30,9 +30,12 @@ using MonoDevelop.CSharpBinding.Tests;
using System.Collections.Generic;
using MonoDevelop.CSharpBinding;
using MonoDevelop.Ide.Gui;
-using Mono.TextEditor;
using MonoDevelop.Ide.TypeSystem;
using System.Linq;
+using MonoDevelop.Refactoring;
+using MonoDevelop.Core.ProgressMonitoring;
+using Microsoft.CodeAnalysis;
+using MonoDevelop.Ide.Editor;
namespace MonoDevelop.CSharpBinding.Refactoring
{
@@ -41,17 +44,14 @@ namespace MonoDevelop.CSharpBinding.Refactoring
{
static void TestInsertionPoints (string text)
{
-
- TestWorkbenchWindow tww = new TestWorkbenchWindow ();
- TestViewContent sev = new TestViewContent ();
- var project = new UnknownProject ();
- project.FileName = "test.csproj";
-
- TypeSystemService.LoadProject (project);
-
- sev.Project = project;
- tww.ViewContent = sev;
+ var tww = new TestWorkbenchWindow ();
+ var content = new TestViewContent ();
+ tww.ViewContent = content;
+ content.ContentName = "/a.cs";
+ content.Data.MimeType = "text/x-csharp";
+ MonoDevelop.AnalysisCore.AnalysisOptions.EnableUnitTestEditorIntegration.Set (true);
var doc = new MonoDevelop.Ide.Gui.Document (tww);
+
var data = doc.Editor;
List<InsertionPoint> loc = new List<InsertionPoint> ();
for (int i = 0; i < text.Length; i++) {
@@ -61,7 +61,7 @@ namespace MonoDevelop.CSharpBinding.Refactoring
ch = text [i];
NewLineInsertion insertBefore = NewLineInsertion.None;
NewLineInsertion insertAfter = NewLineInsertion.None;
-
+
switch (ch) {
case 'n':
break;
@@ -83,7 +83,7 @@ namespace MonoDevelop.CSharpBinding.Refactoring
case 'S':
insertBefore = insertAfter = NewLineInsertion.BlankLine;
break;
-
+
case 't':
insertBefore = NewLineInsertion.Eol;
insertAfter = NewLineInsertion.BlankLine;
@@ -104,21 +104,42 @@ namespace MonoDevelop.CSharpBinding.Refactoring
Assert.Fail ("unknown insertion point:" + ch);
break;
}
- loc.Add (new InsertionPoint (data.Document.OffsetToLocation (data.Document.TextLength), insertBefore, insertAfter));
+ var vv = data.OffsetToLocation (data.Length);
+ loc.Add (new InsertionPoint (new DocumentLocation (vv.Line, vv.Column), insertBefore, insertAfter));
} else {
- data.Insert (data.Document.TextLength, ch.ToString ());
+ data.InsertText (data.Length, ch.ToString ());
}
}
-
- var parsedFile = TypeSystemService.ParseFile (project, "program.cs", "text/x-csharp", data.Document.Text);
- var foundPoints = CodeGenerationService.GetInsertionPoints (doc.Editor, parsedFile, parsedFile.TopLevelTypeDefinitions.First ());
- Assert.AreEqual (loc.Count, foundPoints.Count, "point count doesn't match");
+
+ 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 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 parsedFile = doc.UpdateParseDocument ();
+ var model = parsedFile.GetAst<SemanticModel> ();
+
+ var sym = model.GetEnclosingSymbol (data.Text.IndexOf ('{'));
+ var type = sym as INamedTypeSymbol ?? sym.ContainingType;
+
+ var foundPoints = InsertionPointService.GetInsertionPoints (doc.Editor, parsedFile, type, type.Locations.First ());
+ // Assert.AreEqual (loc.Count, foundPoints.Count, "point count doesn't match");
for (int i = 0; i < loc.Count; i++) {
Assert.AreEqual (loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match");
Assert.AreEqual (loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
Assert.AreEqual (loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
}
+
+ TypeSystemService.Unload (solution);
+
}
[Test()]
@@ -287,7 +308,36 @@ public class EmptyClass
");
}
-
+ [Test]
+ public void TestComplexInsertionPOintCase3 ()
+ {
+ TestInsertionPoints (@"using System;
+class vaevle
+{
+@D int fooBar = 0;
+@u
+
+ public event EventHandler FooBar;
+@u
+
+ public vaevle ()
+ {
+ FooBar += HandleEventHandler;
+ }
+@u
+
+ public static void Main (string [] args)
+ {
+ try {
+ System.Console.WriteLine (nameof (args));
+ } catch (Exception e) when (true) {
+
+ }
+ }
+@s}
+
+");
+ }
}
}
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/ResolveNamespaceTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/ResolveNamespaceTests.cs
deleted file mode 100644
index 5b53a5a12a..0000000000
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/ResolveNamespaceTests.cs
+++ /dev/null
@@ -1,413 +0,0 @@
-//
-// ResolveNamespaceTests.cs
-//
-// Author:
-// Mike Krüger <mkrueger@xamarin.com>
-//
-// Copyright (c) 2012 Xamarin Inc. (http://xamarin.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 NUnit.Framework;
-using MonoDevelop.CSharpBinding.Tests;
-using System.Collections.Generic;
-using MonoDevelop.CSharpBinding;
-using MonoDevelop.Ide.Gui;
-using Mono.TextEditor;
-using ICSharpCode.NRefactory.Semantics;
-using ICSharpCode.NRefactory.CSharp;
-using MonoDevelop.CSharp;
-using MonoDevelop.CSharp.Completion;
-using MonoDevelop.Refactoring;
-using System.Linq;
-using MonoDevelop.Projects;
-using MonoDevelop.Ide.TypeSystem;
-
-namespace MonoDevelop.CSharpBinding.Refactoring
-{
- [TestFixture]
- public class ResolveNamespaceTests : UnitTests.TestBase
- {
- static Document Setup (string input)
- {
- var tww = new TestWorkbenchWindow ();
- var content = new TestViewContent ();
-
- var project = Services.ProjectService.CreateDotNetProject ("C#");
- project.Name = "test";
- project.References.Add (new ProjectReference (ReferenceType.Package, "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
- project.References.Add (new ProjectReference (ReferenceType.Package, "System.Core"));
-
- project.FileName = "test.csproj";
-
- var wrapper = TypeSystemService.LoadProject (project);
- wrapper.EnsureReferencesAreLoaded ();
- wrapper.ReconnectAssemblyReferences ();
- content.Project = project;
-
- tww.ViewContent = content;
- content.ContentName = "a.cs";
- content.GetTextEditorData ().Document.MimeType = "text/x-csharp";
- var doc = new Document (tww);
-
- var text = input;
- int endPos = text.IndexOf ('$');
- if (endPos >= 0)
- text = text.Substring (0, endPos) + text.Substring (endPos + 1);
-
- content.Text = text;
- content.CursorPosition = Math.Max (0, endPos);
-
- var compExt = new CSharpCompletionTextEditorExtension ();
- compExt.Initialize (doc);
- content.Contents.Add (compExt);
- doc.UpdateParseDocument ();
- return doc;
- }
-
- List<MonoDevelop.Refactoring.ResolveCommandHandler.PossibleNamespace> GetResult (string input)
- {
- var doc = Setup (input);
- var location = doc.Editor.Caret.Location;
- ResolveResult resolveResult;
- AstNode node;
- doc.TryResolveAt (location, out resolveResult, out node);
- return ResolveCommandHandler.GetPossibleNamespaces (doc, node, ref resolveResult);
- }
-
- [Test]
- public void TestObjectCreationType ()
- {
- var result = GetResult (@"class Test {
- void MyMethod ()
- {
- var list = new $List<string> ();
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
- }
-
- [Test]
- public void TestLocalVariableType ()
- {
- var result = GetResult (@"class Test {
- void MyMethod ()
- {
- $List<string> list;
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
- }
-
- [Test]
- public void TestParameterType ()
- {
- var result = GetResult (@"class Test {
- void MyMethod ($List<string> list)
- {
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
- }
-
- [Test]
- public void TestFieldType ()
- {
- var result = GetResult (@"class Test {
- $List<string> list;
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
- }
-
-
- [Test]
- public void TestBaseType ()
- {
- var result = GetResult (@"class Test : $List<string> {}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
- }
-
-
- [Test]
- public void TestLocalVariableValid ()
- {
- var result = GetResult (@"using System.Collections.Generic;
-class Test {
- void MyMethod ()
- {
- $List<string> list;
- }
-}");
- Assert.AreEqual (0, result.Count);
- }
-
- [Test]
- public void TestAttributeCase1 ()
- {
- var result = GetResult (@"
-[$Obsolete]
-class Test {
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System"));
- }
-
- [Test]
- public void TestAttributeCase2 ()
- {
-
- var result = GetResult (@"
-[$SerializableAttribute]
-class Test {
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System"));
- }
-
- [Test]
- public void TestAmbigiousResolveResult ()
- {
-
- var result = GetResult (@"namespace Foo { class Bar {} }
-namespace Foo2 { class Bar {} }
-
-namespace My
-{
- using Foo;
- using Foo2;
-
- class Program
- {
- public static void Main ()
- {
- $Bar bar;
- }
- }
-}");
- foreach (var a in result)
- Console.WriteLine (a);
- Assert.IsTrue (result.Any (t => t.Namespace == "Foo"));
- Assert.IsTrue (result.Any (t => t.Namespace == "Foo2"));
- }
-
- [Test]
- public void TestExtensionMethod ()
- {
- var result = GetResult (@"class Program
-{
- public static void Main (string[] args)
- {
- args.$First ();
- }
-}");
- foreach (var a in result)
- Console.WriteLine (a);
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Linq"));
- }
-
-
- #region Bug 3453 - [New Resolver] "Resolve" doesn't show up from time
- [Test]
- public void TestBug3453Case1 ()
- {
- var result = GetResult (@"class Test {
- string GetName ()
- {
- var encoding = $Encoding
- return encoding.EncodingName;
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Text"));
- }
-
- [Test]
- public void TestBug3453Case2 ()
- {
- var result = GetResult (@"class Test {
- string GetName ()
- {
- $Encoding
- return encoding.EncodingName;
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Text"));
- }
-
- [Test]
- public void TestBug3453Case3 ()
- {
- var result = GetResult (@"class Test {
- string GetName ()
- {
- $Encoding.
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Text"));
- }
-
- [Test]
- public void TestBug3453Case3WithGeneris ()
- {
- var result = GetResult (@"class Test {
- string GetName ()
- {
- $List<string>.
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
- }
- #endregion
-
- /// <summary>
- /// Bug 4361 - Cannot 'resolve' an unknown type
- /// </summary>
- [Test]
- public void TestBug4361 ()
- {
- var result = GetResult (@"using System;
-
-namespace sadfhgjhkfj
-{
- class MainClass
- {
- public static void Main (string[] args)
- {
- while (true) {
- var t = new Thre$ad
- }
- }
- }
-}");
- foreach (var a in result)
- Console.WriteLine (a);
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Threading"));
- }
-
- [Test]
- public void TestBug4361Case2 ()
- {
- var result = GetResult (@"using System;
-
-namespace sadfhgjhkfj
-{
- class MainClass
- {
- public static void Main (string[] args)
- {
- while (true) {
- var t = new Thre$ad[0];
- }
- }
- }
-}");
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Threading"));
- }
-
- /// <summary>
- /// Bug 4493 - 'Resolve' context action offers incorrect options
- /// </summary>
- [Test]
- public void TestBug4493 ()
- {
- var result = GetResult (@"using System;
-
-namespace sadfhgjhkfj
-{
- class MainClass
- {
- public static void Main (string[] args)
- {
- S$tack<int> a;
- }
- }
-}"
- );
-
- Assert.IsFalse (result.Any (t => t.Namespace == "System.Collections"));
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
- }
-
-
- /// <summary>
- /// Bug 5206 - Resolve -> Add Using statement does not work after "|"
- /// </summary>
- [Test]
- public void TestBug5206 ()
- {
- var result = GetResult (@"using System;
-
-namespace TestConsole
-{
- class MainClass
- {
- public static void Main (string[] args)
- {
- var f = typeof (int).GetFields (System.Reflection.BindingFlags.Static | Binding$Flags
- }
- }
-}"
- );
-
- Assert.IsTrue (result.Any (t => t.Namespace == "System.Reflection"));
- }
-
- /// <summary>
- /// Bug 4749 - Resolve is incorrect for inner classes
- /// </summary>
- [Test]
- public void TestBug4749 ()
- {
-
- var result = GetResult (@"namespace Test { public class Foo { public class Bar {} } }
-
-class Program
-{
- public static void Main ()
- {
- $Bar bar;
- }
-}
-");
- foreach (var a in result)
- Console.WriteLine (a);
- Assert.IsTrue (result.Any (t => t.Namespace == "Test.Foo" && !t.IsAccessibleWithGlobalUsing));
- }
-
-
- /// <summary>
- /// Bug 10059 - Resolve type fails for nested static types
- /// </summary>
- [Test]
- public void TestBug10059 ()
- {
- var result = GetResult (@"namespace ConsoleTest
-{
- class MainClass
- {
- $Environment.SpecialFolder F { get; }
- }
-}
-"
- );
-
- Assert.IsTrue (result.Any (t => t.Namespace == "System"));
- }
-
-
- }
-}
-
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);
+ }
+
}
}
diff --git a/main/tests/UnitTests/MonoDevelop.Core/BacktrackingStringMatcherTests.cs b/main/tests/UnitTests/MonoDevelop.Core/BacktrackingStringMatcherTests.cs
index 4fd2ad602d..3cda234a7e 100644
--- a/main/tests/UnitTests/MonoDevelop.Core/BacktrackingStringMatcherTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.Core/BacktrackingStringMatcherTests.cs
@@ -30,6 +30,7 @@ using System.Linq;
namespace MonoDevelop.Core
{
+ [TestFixture]
public class BacktrackingStringMatcherTests
{
[Test()]
@@ -87,6 +88,20 @@ namespace MonoDevelop.Core
CompareMatch(match, "*****--");
}
+
+ [Test()]
+ public void TestBacktrackBug ()
+ {
+ var matcher = StringMatcher.GetMatcher ("dlli", true);
+ var match = matcher.GetMatch("DllList");
+ CompareMatch(match, "**-**--");
+
+ matcher = StringMatcher.GetMatcher ("dLli", true);
+ match = matcher.GetMatch("DllList");
+ Assert.IsNull (match, "match found");
+ }
+
+
[Test()]
public void TestUnderscoreAtEnd ()
{
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs
new file mode 100644
index 0000000000..4ac482e082
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs
@@ -0,0 +1,207 @@
+//
+// CodeCommentTests.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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.Text;
+using NUnit.Framework;
+using UnitTests;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public class CodeCommentTests : TestBase
+ {
+ internal static TextEditor CreateTextEditor (string input)
+ {
+ var editor = TextEditorFactory.CreateNewEditor ();
+ editor.MimeType = "text/x-csharp";
+
+ var sb = new StringBuilder ();
+ int cursorPosition = 0, selectionStart = -1, selectionEnd = -1;
+
+ for (int i = 0; i < input.Length; i++) {
+ var ch = input [i];
+ switch (ch) {
+ case '$':
+ cursorPosition = sb.Length;
+ break;
+ case '<':
+ if (i + 1 < input.Length) {
+ if (input [i + 1] == '-') {
+ selectionStart = sb.Length;
+ i++;
+ break;
+ }
+ }
+ goto default;
+ case '-':
+ if (i + 1 < input.Length) {
+ var next = input [i + 1];
+ if (next == '>') {
+ selectionEnd = sb.Length;
+ i++;
+ break;
+ }
+ }
+ goto default;
+ default:
+ sb.Append (ch);
+ break;
+ }
+ }
+ editor.Text = sb.ToString ();
+ editor.CaretOffset = cursorPosition;
+ if (selectionStart >= 0 && selectionEnd >= 0)
+ editor.SetSelection (selectionStart, selectionEnd);
+ return editor;
+ }
+
+ static void AssertEditorState (TextEditor editor, string input)
+ {
+ var sb = new StringBuilder ();
+ int cursorPosition = -1, selectionStart = -1, selectionEnd = -1;
+
+ for (int i = 0; i < input.Length; i++) {
+ var ch = input [i];
+ switch (ch) {
+ case '$':
+ cursorPosition = sb.Length;
+ break;
+ case '<':
+ if (i + 1 < input.Length) {
+ if (input [i + 1] == '-') {
+ selectionStart = sb.Length;
+ i++;
+ break;
+ }
+ }
+ goto default;
+ case '-':
+ if (i + 1 < input.Length) {
+ var next = input [i + 1];
+ if (next == '>') {
+ selectionEnd = sb.Length;
+ i++;
+ break;
+ }
+ }
+ goto default;
+ default:
+ sb.Append (ch);
+ break;
+ }
+ }
+ if (cursorPosition >= 0)
+ Assert.AreEqual (cursorPosition, editor.CaretOffset, "Cursor position mismatch.");
+ if (selectionStart >= 0) {
+ Assert.AreEqual (selectionStart, editor.SelectionRange.Offset, "Selection start mismatch.");
+ Assert.AreEqual (selectionEnd, editor.SelectionRange.EndOffset, "Selection end mismatch.");
+ }
+ Assert.AreEqual (sb.ToString (), editor.Text, "Editor text doesn't match.");
+ }
+
+ [Test]
+ public void TestAddComment()
+ {
+ var editor = CreateTextEditor (@"class Foo
+{
+ <-void Bar ()
+ {
+
+ }->
+}");
+ ((TextEditorViewContent)editor.GetViewContent ()).AddCodeComment ();
+ AssertEditorState (editor, @"class Foo
+{
+ //<-void Bar ()
+ //{
+
+ //}->
+}");
+ }
+
+ [Test]
+ public void TestRemoveComment()
+ {
+ var editor = CreateTextEditor ( @"class Foo
+{
+ //<-void Bar ()
+ //{
+
+ //}->
+}");
+ ((TextEditorViewContent)editor.GetViewContent ()).RemoveCodeComment ();
+ AssertEditorState (editor,@"class Foo
+{
+ <-void Bar ()
+ {
+
+ }->
+}");
+ }
+
+ [Test]
+ public void TestToggle_Add()
+ {
+ var editor = CreateTextEditor (@"class Foo
+{
+ <-void Bar ()
+ {
+
+ }->
+}");
+ ((TextEditorViewContent)editor.GetViewContent ()).ToggleCodeComment ();
+ AssertEditorState (editor, @"class Foo
+{
+ //<-void Bar ()
+ //{
+
+ //}->
+}");
+ }
+
+ [Test]
+ public void TestToggle_Remove()
+ {
+ var editor = CreateTextEditor ( @"class Foo
+{
+ //<-void Bar ()
+ //{
+
+ //}->
+}");
+ ((TextEditorViewContent)editor.GetViewContent ()).ToggleCodeComment ();
+ AssertEditorState (editor,@"class Foo
+{
+ <-void Bar ()
+ {
+
+ }->
+}");
+ }
+
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/SortSelectedLinesTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/SortSelectedLinesTests.cs
new file mode 100644
index 0000000000..aff4feefdc
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Commands/SortSelectedLinesTests.cs
@@ -0,0 +1,66 @@
+//
+// SortSelectedLinesTests.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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.Text;
+using NUnit.Framework;
+using UnitTests;
+using MonoDevelop.Ide.Commands;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public class SortSelectedLinesTests : TestBase
+ {
+ [Test]
+ public void SortSimpleTest ()
+ {
+ var editor = CodeCommentTests.CreateTextEditor (@"
+9
+<-8
+7
+6
+5
+4
+3
+2->
+1
+");
+ EditActions.SortSelectedLines (editor);
+ Assert.AreEqual (@"
+9
+2
+3
+4
+5
+6
+7
+8
+1
+", editor.Text);
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/ReadonlyTextDocumentTestBase.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/ReadonlyTextDocumentTestBase.cs
new file mode 100644
index 0000000000..4b0685ee57
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/ReadonlyTextDocumentTestBase.cs
@@ -0,0 +1,164 @@
+//
+// ReadonlyTextDocumentTestBase.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 NUnit.Framework;
+using MonoDevelop.Core.Text;
+using System.Text;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public abstract class ReadonlyTextDocumentTestBase : TextSourceTestBase
+ {
+ protected sealed override ITextSource CreateTextSource (string text, Encoding enc = null, bool useBom = false)
+ {
+ return CreateReadonlyTextDocument (text, enc, useBom);
+ }
+
+ protected abstract IReadonlyTextDocument CreateReadonlyTextDocument (string text, Encoding enc = null, bool useBom = false);
+
+
+ [Test]
+ public void TestLineCount()
+ {
+ var doc = CreateReadonlyTextDocument ("aaa\nbbb\nccc\n");
+ Assert.AreEqual (4, doc.LineCount);
+ }
+
+
+ [Test]
+ public void TestLocationToOffset()
+ {
+ var doc = CreateReadonlyTextDocument ("aaa\nbbb\nccc\n");
+ Assert.AreEqual (0, doc.LocationToOffset (1, 1));
+ Assert.AreEqual (4, doc.LocationToOffset (2, 1));
+ Assert.AreEqual (11, doc.LocationToOffset (3, 4));
+ }
+
+ [Test]
+ public void TestOffsetToLocation()
+ {
+ var doc = CreateReadonlyTextDocument ("aaa\nbbb\nccc\n");
+ Assert.AreEqual (new DocumentLocation (1, 1), doc.OffsetToLocation (0));
+ Assert.AreEqual (new DocumentLocation (2, 1), doc.OffsetToLocation (4));
+ Assert.AreEqual (new DocumentLocation (3, 4), doc.OffsetToLocation (11));
+ }
+
+ [Test]
+ public void TestGetLine()
+ {
+ var doc = CreateReadonlyTextDocument ("aaa\nbbb\nccc\n");
+ var line1 = doc.GetLine (1);
+ Assert.AreEqual (0, line1.Offset);
+ Assert.AreEqual (3, line1.Length);
+ Assert.AreEqual (1, line1.DelimiterLength);
+ Assert.AreEqual (1, line1.LineNumber);
+
+ var line2 = doc.GetLine (2);
+ Assert.AreEqual (4, line2.Offset);
+ Assert.AreEqual (3, line2.Length);
+ Assert.AreEqual (1, line2.DelimiterLength);
+ Assert.AreEqual (2, line2.LineNumber);
+
+ var line3 = doc.GetLine (3);
+ Assert.AreEqual (8, line3.Offset);
+ Assert.AreEqual (3, line3.Length);
+ Assert.AreEqual (1, line3.DelimiterLength);
+ Assert.AreEqual (3, line3.LineNumber);
+
+ var line4 = doc.GetLine (4);
+ Assert.AreEqual (12, line4.Offset);
+ Assert.AreEqual (0, line4.Length);
+ Assert.AreEqual (0, line4.DelimiterLength);
+ Assert.AreEqual (4, line4.LineNumber);
+ }
+
+ [Test]
+ public void GetLineByOffset()
+ {
+ var doc = CreateReadonlyTextDocument ("aaa\nbbb\nccc\n");
+ for (int i = 0; i < 3; i++) {
+ var line1 = doc.GetLineByOffset (0 + i);
+ Assert.AreEqual (0, line1.Offset);
+ Assert.AreEqual (3, line1.Length);
+ Assert.AreEqual (1, line1.DelimiterLength);
+ Assert.AreEqual (1, line1.LineNumber);
+ }
+
+ for (int i = 0; i < 3; i++) {
+ var line2 = doc.GetLineByOffset (4 + i);
+ Assert.AreEqual (4, line2.Offset);
+ Assert.AreEqual (3, line2.Length);
+ Assert.AreEqual (1, line2.DelimiterLength);
+ Assert.AreEqual (2, line2.LineNumber);
+ }
+
+ for (int i = 0; i < 3; i++) {
+ var line3 = doc.GetLineByOffset (8 + i);
+ Assert.AreEqual (8, line3.Offset);
+ Assert.AreEqual (3, line3.Length);
+ Assert.AreEqual (1, line3.DelimiterLength);
+ Assert.AreEqual (3, line3.LineNumber);
+ }
+
+ var line4 = doc.GetLineByOffset (12);
+ Assert.AreEqual (12, line4.Offset);
+ Assert.AreEqual (0, line4.Length);
+ Assert.AreEqual (0, line4.DelimiterLength);
+ Assert.AreEqual (4, line4.LineNumber);
+ }
+
+ [Test]
+ public void TestLineParsingLineEndings()
+ {
+ var doc = CreateReadonlyTextDocument ("1\n2\r\n3\r4\u00855\u000B6\u000C7\u20288\u2029");
+ Assert.AreEqual (UnicodeNewline.LF, doc.GetLine (1).UnicodeNewline);
+ Assert.AreEqual (1, doc.GetLine (1).DelimiterLength);
+
+ Assert.AreEqual (UnicodeNewline.CRLF, doc.GetLine (2).UnicodeNewline);
+ Assert.AreEqual (2, doc.GetLine (2).DelimiterLength);
+
+ Assert.AreEqual (UnicodeNewline.CR, doc.GetLine (3).UnicodeNewline);
+ Assert.AreEqual (1, doc.GetLine (3).DelimiterLength);
+
+ Assert.AreEqual (UnicodeNewline.NEL, doc.GetLine (4).UnicodeNewline);
+ Assert.AreEqual (1, doc.GetLine (4).DelimiterLength);
+
+ Assert.AreEqual (UnicodeNewline.VT, doc.GetLine (5).UnicodeNewline);
+ Assert.AreEqual (1, doc.GetLine (5).DelimiterLength);
+
+ Assert.AreEqual (UnicodeNewline.FF, doc.GetLine (6).UnicodeNewline);
+ Assert.AreEqual (1, doc.GetLine (6).DelimiterLength);
+
+ Assert.AreEqual (UnicodeNewline.LS, doc.GetLine (7).UnicodeNewline);
+ Assert.AreEqual (1, doc.GetLine (7).DelimiterLength);
+
+ Assert.AreEqual (UnicodeNewline.PS, doc.GetLine (8).UnicodeNewline);
+ Assert.AreEqual (1, doc.GetLine (8).DelimiterLength);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs
new file mode 100644
index 0000000000..82cbe2ca27
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs
@@ -0,0 +1,55 @@
+//
+// SimpleBracketMatcherTests.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 Mono.TextEditor;
+using MonoDevelop.Ide.Editor.Util;
+using NUnit.Framework;
+using UnitTests;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public class SimpleBracketMatcherTests : TestBase
+ {
+ [TestCase ("{}", 0, 1)]
+ [TestCase ("{}", 1, 0)]
+ public void MatchingBracketTests (string text, int offset, int expectedOffsetMatch)
+ {
+ var editor = TextEditorFactory.CreateNewEditor ();
+ editor.MimeType = "text/x-csharp";
+ editor.Text = text;
+ var document = new TextDocument (text);
+
+ int actualOffset = SimpleBracketMatcher.GetMatchingBracketOffset (editor, offset);
+ int actualOffset2 = document.GetMatchingBracketOffset (offset);
+
+ Assert.AreEqual (actualOffset2, actualOffset);
+ Assert.AreEqual (expectedOffsetMatch, actualOffset);
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/MonoTextEditorImplementationTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/MonoTextEditorImplementationTests.cs
new file mode 100644
index 0000000000..18819ab481
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/MonoTextEditorImplementationTests.cs
@@ -0,0 +1,56 @@
+//
+// MonoTextEditorImplementationTests.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 MonoDevelop.Ide.Editor;
+using System.Text;
+
+namespace MonoDevelop.Ide.Editor
+{
+ public class MonoTextEditorImplementationTests : TextEditorTestBase
+ {
+ protected override TextEditor CreateTextEditor (string text, Encoding enc = null, bool useBom = false)
+ {
+ var editor = TextEditorFactory.CreateNewEditor ();
+ editor.Text = text;
+ editor.Encoding = enc;
+ editor.UseBOM = useBom;
+ return editor;
+ }
+ }
+
+ public class MonoTextEditorSnapshotImplementationTests : ReadonlyTextDocumentTestBase
+ {
+ protected override IReadonlyTextDocument CreateReadonlyTextDocument (string text, Encoding enc = null, bool useBom = false)
+ {
+ var editor = TextEditorFactory.CreateNewEditor ();
+ editor.Text = text;
+ editor.Encoding = enc;
+ editor.UseBOM = useBom;
+ return editor.CreateDocumentSnapshot ();
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/SimpleReadonlyDocument_Tests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/SimpleReadonlyDocument_Tests.cs
new file mode 100644
index 0000000000..0e20ea8dda
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/SimpleReadonlyDocument_Tests.cs
@@ -0,0 +1,41 @@
+//
+// SimpleReadonlyDocument_Tests.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 MonoDevelop.Ide.Editor;
+using MonoDevelop.Ide.Editor.Util;
+using MonoDevelop.Core.Text;
+
+namespace MonoDevelop.Ide.Editor
+{
+ public class SimpleReadonlyDocument_Tests : ReadonlyTextDocumentTestBase
+ {
+ protected override IReadonlyTextDocument CreateReadonlyTextDocument (string text, System.Text.Encoding enc, bool useBom = false)
+ {
+ return SimpleReadonlyDocument.CreateReadonlyDocumentAsync (new StringTextSource (text, enc, useBom)).Result;
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/StringTextSource_Tests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/StringTextSource_Tests.cs
new file mode 100644
index 0000000000..955eacd4f5
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/Tests/StringTextSource_Tests.cs
@@ -0,0 +1,47 @@
+//
+// StringTextSource_Tests.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 MonoDevelop.Core.Text;
+
+namespace MonoDevelop.Ide.Editor
+{
+ public class StringTextSource_Tests : TextSourceTestBase
+ {
+ protected override ITextSource CreateTextSource (string text, System.Text.Encoding enc = null, bool useBom = false)
+ {
+ return new StringTextSource (text, enc, useBom);
+ }
+ }
+
+ public class StringTextSource_Snapshot_Tests : TextSourceTestBase
+ {
+ protected override ITextSource CreateTextSource (string text, System.Text.Encoding enc = null, bool useBom = false)
+ {
+ return new StringTextSource (text, enc, useBom).CreateSnapshot ();
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextDocumentTestBase.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextDocumentTestBase.cs
new file mode 100644
index 0000000000..e5e368c41d
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextDocumentTestBase.cs
@@ -0,0 +1,173 @@
+//
+// TextDocumentTestBase.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 NUnit.Framework;
+using MonoDevelop.Core.Text;
+using System.Text;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public abstract class TextDocumentTestBase : ReadonlyTextDocumentTestBase
+ {
+ protected sealed override IReadonlyTextDocument CreateReadonlyTextDocument (string text, Encoding enc = null, bool useBom = false)
+ {
+ return CreateTextDocument (text, enc, useBom);
+ }
+
+ protected abstract ITextDocument CreateTextDocument (string text, Encoding enc = null, bool useBom = false);
+
+ [Test]
+ public void InsertTextTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.InsertText (3, "Hello");
+ Assert.AreEqual (textDoc.Text, "123Hello45");
+ }
+
+ [Test]
+ public void InsertText_TextSourceTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.InsertText (3, new StringTextSource ("Hello"));
+ Assert.AreEqual (textDoc.Text, "123Hello45");
+ }
+
+ [Test]
+ public void RemoveText_TextSourceTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.RemoveText (2, 2);
+ Assert.AreEqual (textDoc.Text, "125");
+ }
+
+ [Test]
+ public void RemoveText_Segment_TextSourceTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.RemoveText (new TextSegment (2, 2));
+ Assert.AreEqual (textDoc.Text, "125");
+ }
+
+ [Test]
+ public void ReplaceTextTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.ReplaceText (2, 2, "Hello");
+ Assert.AreEqual (textDoc.Text, "12Hello5");
+ }
+
+ [Test]
+ public void Replace_Segment_TextTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.ReplaceText (new TextSegment (2, 2), "Hello");
+ Assert.AreEqual (textDoc.Text, "12Hello5");
+ }
+
+
+ [Test]
+ public void Replace_TextSourceTextTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.ReplaceText (2, 2, new StringTextSource ("Hello"));
+ Assert.AreEqual (textDoc.Text, "12Hello5");
+ }
+
+ [Test]
+ public void Replace_TextSource_Segment_TextTest()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ textDoc.ReplaceText (new TextSegment (2, 2), new StringTextSource ("Hello"));
+ Assert.AreEqual (textDoc.Text, "12Hello5");
+ }
+
+ [Test]
+ public void TestUndoOperation()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ Assert.IsFalse (textDoc.IsInAtomicUndo);
+ using (var undo = textDoc.OpenUndoGroup ()) {
+ Assert.IsTrue (textDoc.IsInAtomicUndo);
+ }
+ Assert.IsFalse (textDoc.IsInAtomicUndo);
+ }
+
+
+ [Test]
+ public void TestTextChanging()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ TextChangeEventArgs changeArgs = null;
+ string text = null;
+ textDoc.TextChanging += delegate(object sender, TextChangeEventArgs e) {
+ changeArgs = e;
+ text = textDoc.Text;
+ };
+ textDoc.ReplaceText (2, 2, "Hello");
+ Assert.AreEqual (textDoc.Text, "12Hello5");
+ Assert.AreEqual (text, "12345");
+ Assert.AreEqual (changeArgs.Offset, 2);
+ Assert.AreEqual (changeArgs.RemovalLength, 2);
+ Assert.AreEqual (changeArgs.RemovedText.Text, "34");
+ Assert.AreEqual (changeArgs.InsertionLength, "Hello".Length);
+ Assert.AreEqual (changeArgs.InsertedText.Text, "Hello");
+ }
+
+ [Test]
+ public void TestTextChanged()
+ {
+ var textDoc = CreateTextDocument ("12345");
+ TextChangeEventArgs changeArgs = null;
+ string text = null;
+ textDoc.TextChanged += delegate(object sender, TextChangeEventArgs e) {
+ changeArgs = e;
+ text = textDoc.Text;
+ };
+ textDoc.ReplaceText (2, 2, "Hello");
+ Assert.AreEqual (textDoc.Text, "12Hello5");
+ Assert.AreEqual (text, "12Hello5");
+ Assert.AreEqual (changeArgs.Offset, 2);
+ Assert.AreEqual (changeArgs.RemovalLength, 2);
+ Assert.AreEqual (changeArgs.RemovedText.Text, "34");
+ Assert.AreEqual (changeArgs.InsertionLength, "Hello".Length);
+ Assert.AreEqual (changeArgs.InsertedText.Text, "Hello");
+ }
+
+// [Test]
+// public void TestLineInserted()
+// {
+// var textDoc = CreateTextDocument ("12345");
+// LineEventArgs changeArgs = null;
+// textDoc.LineInserted += (sender, e) => changeArgs = e;
+// textDoc.InsertText (0, "foo\n");
+// Assert.AreEqual (1, changeArgs.Line.LineNumber);
+// Assert.AreEqual (changeArgs.Line.Length, "foo".Length);
+// }
+
+ }
+}
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorProjectionTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorProjectionTests.cs
new file mode 100644
index 0000000000..5cc9c56ce9
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorProjectionTests.cs
@@ -0,0 +1,78 @@
+//
+// TextEditorProjectionTests.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 NUnit.Framework;
+using System.Collections.Generic;
+using MonoDevelop.Ide.Editor.Projection;
+using MonoDevelop.Core.Text;
+using MonoDevelop.Ide.Gui;
+using MonoDevelop.CSharpBinding;
+using UnitTests;
+using MonoDevelop.CSharpBinding.Tests;
+using System.Linq;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public class TextEditorProjectionTests : TestBase
+ {
+ [Test]
+ public void TestProjectionUpdate ()
+ {
+ var editor = TextEditorFactory.CreateNewEditor ();
+ editor.Text = "1234567890";
+
+ var projectedDocument = TextEditorFactory.CreateNewDocument (
+ new StringTextSource ("__12__34__56__78__90"),
+ "a"
+ );
+
+ var segments = new List<ProjectedSegment> ();
+ for (int i = 0; i < 5; i++) {
+ segments.Add (new ProjectedSegment (i * 2, 2 + i * 4, 2));
+ }
+ var projection = new Projection.Projection (projectedDocument, segments);
+ var tww = new TestWorkbenchWindow ();
+ var content = new TestViewContent ();
+ tww.ViewContent = content;
+
+ var originalContext = new Document (tww);
+ var projectedEditor = projection.CreateProjectedEditor (originalContext);
+ editor.SetOrUpdateProjections (originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
+ editor.InsertText (1, "foo");
+ Assert.AreEqual ("__1foo2__34__56__78__90", projectedEditor.Text);
+
+ Assert.AreEqual (2 , projection.ProjectedSegments.ElementAt (0).ProjectedOffset);
+ Assert.AreEqual (2 + "foo".Length, projection.ProjectedSegments.ElementAt (0).Length);
+ for (int i = 1; i < 5; i++) {
+ Assert.AreEqual (2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt (i).ProjectedOffset);
+ Assert.AreEqual (2, projection.ProjectedSegments.ElementAt (i).Length);
+ }
+
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorTestBase.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorTestBase.cs
new file mode 100644
index 0000000000..3de39dd5b9
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextEditorTestBase.cs
@@ -0,0 +1,45 @@
+//
+// TextEditorTestBase.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 NUnit.Framework;
+using MonoDevelop.Core.Text;
+using System.Text;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public abstract class TextEditorTestBase : TextDocumentTestBase
+ {
+ protected sealed override ITextDocument CreateTextDocument (string text, Encoding enc = null, bool useBom = false)
+ {
+ return CreateTextEditor (text, enc, useBom);
+ }
+
+ protected abstract TextEditor CreateTextEditor (string text, Encoding enc = null, bool useBom = false);
+ }
+
+}
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextSourceTestBase.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextSourceTestBase.cs
new file mode 100644
index 0000000000..a3710af4a4
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/TextSourceTestBase.cs
@@ -0,0 +1,169 @@
+//
+// TextSourceTestBase.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.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 UnitTests;
+using NUnit.Framework.Internal;
+using MonoDevelop.Core.Text;
+using System.Text;
+using NUnit.Framework;
+using System.IO;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public abstract class TextSourceTestBase : TestBase
+ {
+ protected abstract ITextSource CreateTextSource (string text, Encoding enc = null, bool useBom = false);
+
+ [Test]
+ public void TestTextProperty()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ Assert.AreEqual (txt, test.Text);
+ }
+
+ [Test]
+ public void TestLengthProperty()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ Assert.AreEqual (txt.Length, test.Length);
+ }
+
+ [Test]
+ public void TestGetCharAt()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ for (int i = 0; i < txt.Length; i++) {
+ Assert.AreEqual (txt[i], test.GetCharAt (i));
+ }
+ }
+
+ [Test]
+ public void TestTextAt()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ for (int i = 0; i < txt.Length; i++) {
+ Assert.AreEqual (txt.Substring (0, i), test.GetTextAt (0, i));
+ }
+ }
+
+ [Test]
+ public void TestTextAt_Segment()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ for (int i = 0; i < txt.Length; i++) {
+ Assert.AreEqual (txt.Substring (0, i), test.GetTextAt (new TextSegment (0, i)));
+ }
+ }
+
+ [Test]
+ public void TestCreateReader()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ var readText = test.CreateReader ().ReadToEnd ();
+ Assert.AreEqual (txt, readText);
+ }
+
+ [Test]
+ public void TestCreateReaderAt()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ var readText = test.CreateReader (2, 2).ReadToEnd ();
+ Assert.AreEqual (txt.Substring (2, 2), readText);
+ }
+
+ [Test]
+ public void TestCreateReaderAt_Segment()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ var readText = test.CreateReader (new TextSegment (2, 2)).ReadToEnd ();
+ Assert.AreEqual (txt.Substring (2, 2), readText);
+ }
+
+ [Test]
+ public void TestWriteTextTo()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ var writer = new StringWriter ();
+ test.WriteTextTo (writer);
+ Assert.AreEqual (txt, writer.ToString ());
+ }
+
+ [Test]
+ public void TestWriteTextToAt()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ var writer = new StringWriter ();
+ test.WriteTextTo (writer, 2, 2);
+ Assert.AreEqual (txt.Substring (2, 2), writer.ToString ());
+ }
+
+ [Test]
+ public void TestWriteTextToAt_Segment()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ var writer = new StringWriter ();
+ test.WriteTextTo (writer, new TextSegment (2, 2));
+ Assert.AreEqual (txt.Substring (2, 2), writer.ToString ());
+ }
+
+ [Test]
+ public void TestCreateSnapshotAt()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt).CreateSnapshot (2, 2);
+ Assert.AreEqual (txt.Substring (2, 2), test.Text);
+ }
+
+ [Test]
+ public void TestCreateSnapshotAt_Segment()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt).CreateSnapshot (new TextSegment (2, 2));
+ Assert.AreEqual (txt.Substring (2, 2), test.Text);
+ }
+
+ [Test]
+ public void TestGetTextBetween()
+ {
+ const string txt = "test";
+ var test = CreateTextSource (txt);
+ Assert.AreEqual (txt.Substring (1, txt.Length - 2), test.GetTextBetween (1, txt.Length - 1));
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs
index 461f66b910..60d6e6d1c3 100644
--- a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs
@@ -26,6 +26,7 @@
using System;
using NUnit.Framework;
+using MonoDevelop.Components;
namespace MonoDevelop.Ide.FindInFiles
{
@@ -39,7 +40,7 @@ namespace MonoDevelop.Ide.FindInFiles
"simple",
1,
5,
- new Mono.TextEditor.HslColor (1d, 1d, 1d)
+ new HslColor (1d, 1d, 1d)
);
Assert.AreEqual ("s<span background=\"#FFFFFF\">impl</span>e", result);
}
@@ -54,7 +55,7 @@ namespace MonoDevelop.Ide.FindInFiles
"<span foreground=\"#000000\">Console.WriteLine (</span><span foreground=\"#3364A4\">base</span><span foreground=\"#000000\">.ToString());</span>",
19,
24,
- new Mono.TextEditor.HslColor (1d, 1d, 1d)
+ new HslColor (1d, 1d, 1d)
);
Assert.AreEqual ("<span foreground=\"#000000\">Console.WriteLine (</span><span foreground=\"#3364A4\"><span background=\"#FFFFFF\">base</span></span><span foreground=\"#000000\"><span background=\"#FFFFFF\">.</span>ToString());</span>", result);
}
@@ -70,7 +71,7 @@ namespace MonoDevelop.Ide.FindInFiles
"<span foreground=\"#000000\">List&lt;RevisionPath&gt; foo;</span>",
5,
17,
- new Mono.TextEditor.HslColor (1d, 1d, 1d)
+ new HslColor (1d, 1d, 1d)
);
Assert.AreEqual ("<span foreground=\"#000000\">List&lt;<span background=\"#FFFFFF\">RevisionPath</span>&gt; foo;</span>", result);
}
@@ -83,7 +84,7 @@ namespace MonoDevelop.Ide.FindInFiles
"<span foreground=\"#000000\">ec.Report.Error (</span><span foreground=\"#A40000\">29</span><span foreground=\"#000000\">, loc, </span><span foreground=\"#A40000\">\"Cannot implicitly convert type `{0}' to `{1}'\"</span><span foreground=\"#000000\">,</span>",
16,
20,
- new Mono.TextEditor.HslColor (1d, 1d, 1d)
+ new HslColor (1d, 1d, 1d)
);
Assert.AreEqual ("<span foreground=\"#000000\">ec.Report.Error <span background=\"#FFFFFF\">(</span></span><span foreground=\"#A40000\"><span background=\"#FFFFFF\">29</span></span><span foreground=\"#000000\"><span background=\"#FFFFFF\">,</span> loc, </span><span foreground=\"#A40000\">\"Cannot implicitly convert type `{0}' to `{1}'\"</span><span foreground=\"#000000\">,</span>", result);
}
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs
deleted file mode 100644
index 2b86670596..0000000000
--- a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs
+++ /dev/null
@@ -1,632 +0,0 @@
-//
-// MemberCollectorTests.cs
-//
-// Author:
-// Mansheng Yang <lightyang0@gmail.com>
-//
-// Copyright (c) 2012 Mansheng Yang
-//
-// 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.Linq;
-using System.Collections.Generic;
-using NUnit.Framework;
-using MonoDevelop.Projects;
-using ICSharpCode.NRefactory.TypeSystem;
-using MonoDevelop.Ide.TypeSystem;
-using ICSharpCode.NRefactory.CSharp;
-using ICSharpCode.NRefactory.CSharp.TypeSystem;
-using Mono.CSharp.Nullable;
-using GLib;
-
-namespace MonoDevelop.Ide.FindInFiles
-{
- [TestFixture ()]
- public class MemberCollectorTests : UnitTests.TestBase
- {
- IAssembly GenerateAssembly(Project project, string code)
- {
- var wrapper = TypeSystemService.LoadProject (project);
- TypeSystemService.ParseFile ("test.cs", "text/x-csharp", code, wrapper);
- wrapper.RequestLoad ();
- do {
- System.Threading.Thread.Sleep (10);
- } while (!wrapper.IsLoaded);
- var result = wrapper.Compilation.MainAssembly;
- return result;
- }
-
- List<IMember> CollectMembers (string code, string typeName, Predicate<IUnresolvedMember> filter1, Predicate<IMember> filter2,
- bool includeOverloads, bool matchDeclaringType)
- {
- var fileName = string.Format ("test{0}.csproj", Environment.TickCount); // use a new file name for each test to avoid conflicts
- var project = new UnknownProject { FileName = fileName };
-
- var solution = new Solution ();
- solution.RootFolder.AddItem (project);
-
- var baseType = GenerateAssembly (project, code).GetTypeDefinition ("", typeName, 0);
-
- var members = baseType.GetMembers (filter1).Concat (baseType.GetConstructors (filter1));
- if (filter2 != null)
- members = members.Where (m => filter2(m));
- var result = MemberCollector.CollectMembers (solution, members.First (), ReferenceFinder.RefactoryScope.Solution,
- includeOverloads, matchDeclaringType).ToList ();
- TypeSystemService.UnloadProject (project, true);
- return result;
- }
-
- List<IMember> CollectMembers (string code, string typeName, string memberName, Predicate<IMember> searchMemberFilter,
- bool includeOverloads, bool matchDeclaringType)
- {
- return CollectMembers (code, typeName, m => m.Name == memberName && m.DeclaringTypeDefinition.Name == typeName,
- searchMemberFilter, includeOverloads, matchDeclaringType);
- }
-
- void TestCollectMembers (string code, string typeName, string memberName, IEnumerable<Predicate<IMember>> expected,
- Predicate<IMember> searchMemberFilter = null, bool includeOverloads = true, bool matchDeclaringType = false)
- {
- var result = CollectMembers (code, typeName, memberName, searchMemberFilter, includeOverloads, matchDeclaringType);
- VerifyResult (result, expected);
- }
-
- void TestCollectMembersForAllTypes (string code, string memberName, IList<String> typeNames,
- IList<Predicate<IMember>> filters = null)
- {
- // all the members should be in the result
- var expected = new List<Predicate<IMember>>();
- for (int i = 0; i < typeNames.Count; i++)
- expected.Add (GetMemberFilter (typeNames[i], memberName, filters == null ? null : filters[i]));
-
- for (int i = 0; i < typeNames.Count; i++)
- TestCollectMembers (code, typeNames[i], memberName, expected, filters == null ? null : filters[i]);
- }
-
- void VerifyResult<T>(List<T> result, IEnumerable<Predicate<T>> expected)
- {
- Assert.AreEqual (expected.Count (), result.Count);
- foreach (var pred in expected)
- Assert.AreEqual (1, result.RemoveAll (pred));
- }
-
- bool MatchParameters (IMember m, IList<string> paramTypes)
- {
- var member = (IParameterizedMember)m;
- if (member.Parameters.Count != paramTypes.Count) return false;
- for (int i = 0; i < paramTypes.Count; i++) {
- if (member.Parameters[i].Type.Name != paramTypes[i]) return false;
- }
- return true;
- }
-
- Predicate<IMember> GetMemberFilter (string declaringType, string memberName, Predicate<IMember> filter = null)
- {
- return m => m.Name == memberName && m.DeclaringType.Name == declaringType && (filter == null || filter (m));
- }
-
- [Test]
- public void TestMethodOverrides ()
- {
- var code = @"
-class A
-{
- public virtual void Method () { }
-}
-class B : A
-{
- public override void Method () { }
-}
-class C : B
-{
- public sealed void Method () { }
-}
-class D : A
-{
- public override void Method () { }
-}";
-
- var memberName = "Method";
- var types = new [] {"A", "B", "C", "D"};
- TestCollectMembersForAllTypes (code, memberName, types);
- }
-
- [Test]
- public void TestEventOverrides ()
- {
- var code = @"
-class A
-{
- public virtual event EventHandler Event;
-}
-class B : A
-{
- public override event EventHandler Event;
-}
-class C : B
-{
- public sealed override event EventHandler Event;
-}
-class D : A
-{
- public override event EventHandler Event;
-}";
- var memberName = "Event";
- var types = new [] {"A", "B", "C", "D"};
- TestCollectMembersForAllTypes (code, memberName, types);
- }
-
- [Test]
- public void TestPropertyOverrides ()
- {
- var code = @"
-class A
-{
- public virtual int Prop
- { get; set; }
-}
-class B : A
-{
- public override int Prop
- { get; set; }
-}
-class C : B
-{
- public override sealed int Prop
- { get; set; }
-}
-class D : A
-{
- public override int Prop
- { get; set; }
-}";
- var memberName = "Prop";
- var types = new [] {"A", "B", "C", "D"};
- TestCollectMembersForAllTypes (code, memberName, types);
- }
-
- [Test]
- public void TestSingleInterfaceImpl ()
- {
- var code = @"
-interface IA
-{
- void Method();
-}
-class A : IA
-{
- public virtual void Method() { };
-}
-class B : A
-{
- public override void Method() { };
-}
-class C : IA
-{
- public void Method() { };
-}";
- var memberName = "Method";
- var types = new [] {"A", "B", "C", "IA"};
- TestCollectMembersForAllTypes (code, memberName, types);
- }
-
- [Test]
- public void TestMultiInterfacesImpl1 ()
- {
- var code = @"
-interface IA
-{
- void Method();
-}
-interface IB
-{
- void Method();
-}
-class A : IA, IB
-{
- public void Method() { }
-}
-class B : IA
-{
- public void Method() { }
-}
-class C : IB
-{
- public void Method() { }
-}";
- string memberName = "Method";
-
- var expected1 = new List<Predicate<IMember>>();
- expected1.Add (GetMemberFilter ("A", memberName));
- expected1.Add (GetMemberFilter ("B", memberName));
- expected1.Add (GetMemberFilter ("C", memberName));
- expected1.Add (GetMemberFilter ("IA", memberName));
- expected1.Add (GetMemberFilter ("IB", memberName));
- TestCollectMembers (code, "A", memberName, expected1);
- }
-
- [Test]
- public void TestMultiInterfacesImpl2 ()
- {
- var code = @"
-interface IA
-{
- void Method();
-}
-interface IB
-{
- void Method();
-}
-class A : IA, IB
-{
- public void Method() { }
-}
-class B : IA
-{
- public void Method() { }
-}
-class C : IB
-{
- public void Method() { }
-}";
- string memberName = "Method";
-
- var expected2 = new List<Predicate<IMember>>();
- expected2.Add (GetMemberFilter ("A", memberName));
- expected2.Add (GetMemberFilter ("B", memberName));
- expected2.Add (GetMemberFilter ("IA", memberName));
- TestCollectMembers (code, "B", memberName, expected2);
- TestCollectMembers (code, "IA", memberName, expected2);
- }
-
- [Test]
- public void TestMultiInterfacesImpl3 ()
- {
- var code = @"
-interface IA
-{
- void Method();
-}
-interface IB
-{
- void Method();
-}
-class A : IA, IB
-{
- public void Method() { }
-}
-class B : IA
-{
- public void Method() { }
-}
-class C : IB
-{
- public void Method() { }
-}";
- string memberName = "Method";
-
- var expected3 = new List<Predicate<IMember>>();
- expected3.Add (GetMemberFilter ("A", memberName));
- expected3.Add (GetMemberFilter ("C", memberName));
- expected3.Add (GetMemberFilter ("IB", memberName));
- TestCollectMembers (code, "C", memberName, expected3);
- TestCollectMembers (code, "IB", memberName, expected3);
- }
-
- [Test]
- public void TestMethodOverloads ()
- {
- var code = @"
-class A
-{
- public void Method () { }
- public void Method (int i) { }
- public void Method (string i) { }
-}
-struct B
-{
- public void Method () { }
- public void Method (int i) { }
- public void Method (string i) { }
-}";
- var emptyParam = new string [] { };
- var intParam = new [] {"Int32"};
- var strParam = new [] {"String"};
- var paramList = new [] {emptyParam, intParam, strParam};
- var paramFilters = paramList.Select (p => new Predicate<IMember> (m => MatchParameters (m, p)));
-
- var memberName = "Method";
- var typeNames = new [] {"A", "B"};
- foreach (var typeName in typeNames) {
- var expected = paramFilters.Select (p => GetMemberFilter (typeName, memberName, p)).ToList ();
- foreach (var filter in paramFilters)
- TestCollectMembers (code, typeName, memberName, expected, filter);
- }
- }
-
- [Test]
- public void TestIncludeOverloads ()
- {
- var code = @"
-class A
-{
- public virtual void Method () { }
- public void Method (int i) { }
-}
-class B : A
-{
- public override void Method () { }
- public void Method (string i) { }
-}
-class C : B
-{
- public override void Method () { }
- public void Method (double i) { }
-}
-class D : A
-{
- public override void Method () { }
- public void Method (char i) { }
-}";
- var emptyParam = new string [] { };
- var intParam = new [] {"Int32"};
- var strParam = new [] {"String"};
- var doubleParam = new [] {"Double"};
- var charParam = new [] {"Char"};
- var paramList = new [] { emptyParam, emptyParam, emptyParam, emptyParam, intParam, strParam, doubleParam, charParam };
- var paramFilters = paramList.Select (p => new Predicate<IMember> (m => MatchParameters (m, p)));
-
- var memberName = "Method";
- var types = new [] {"A", "B", "C", "D", "A", "B", "C", "D"};
- TestCollectMembersForAllTypes (code, memberName, types, paramFilters.ToList ());
-
- }
-
- [Test]
- public void TestExcludeOverloads ()
- {
- var code = @"
-class A
-{
- public virtual void Method () { }
- public void Method (int i) { }
-}
-class B : A
-{
- public override void Method () { }
- public void Method (string i) { }
-}
-class C : B
-{
- public override void Method () { }
- public void Method (double i) { }
-}
-class D : A
-{
- public override void Method () { }
- public void Method (char i) { }
-}";
- var emptyParam = new string [] { };
- var intParam = new [] {"Int32"};
- var strParam = new [] {"String"};
- var doubleParam = new [] {"Double"};
- var charParam = new [] {"Char"};
-
- string memberName = "Method";
-
- var types = new [] {"A", "B", "C", "D"};
- var paramList = new [] {intParam, strParam, doubleParam, charParam};
- for (int i = 0; i < types.Length; i++) {
- Predicate<IMember> paramFilter = m => MatchParameters (m, paramList[i]);
- TestCollectMembers (code, types[i], memberName, new [] { GetMemberFilter (types[i], memberName, paramFilter)}, paramFilter, false);
- }
-
- var expected = types.Select (t => new Predicate<IMember> (GetMemberFilter (t, memberName, m => MatchParameters (m,emptyParam))))
- .ToList ();
- foreach (var type in types)
- TestCollectMembers (code, type,memberName, expected, m => MatchParameters (m, emptyParam), false);
-
- }
-
- [Test]
- public void TestInterfacePlusOverrides ()
- {
- string code = @"
-class A
-{
- public virtual void Method() { };
-}
-interface IA
-{
- void Method();
-}
-class B : A, IA
-{
- public override void Method() { };
-}";
- string memberName = "Method";
-
- var expected1 = new List<Predicate<IMember>> ();
- expected1.Add (GetMemberFilter ("A", memberName));
- expected1.Add (GetMemberFilter ("B", memberName));
-
- var expected2 = new List<Predicate<IMember>> ();
- expected2.Add (GetMemberFilter ("IA", memberName));
- expected2.Add (GetMemberFilter ("B", memberName));
-
- var expected3 = new List<Predicate<IMember>> ();
- expected3.Add (GetMemberFilter ("A", memberName));
- expected3.Add (GetMemberFilter ("IA", memberName));
- expected3.Add (GetMemberFilter ("B", memberName));
-
- TestCollectMembers (code, "A", memberName, expected1);
- TestCollectMembers (code, "IA", memberName, expected2);
- TestCollectMembers (code, "B", memberName, expected3);
- }
-
- [Test]
- public void TestGetBaseTypes ()
- {
- string code = @"
-class A { }
-class B : A { }
-interface IA { }
-class C : A, IA { }
-interface IB { }
-class D : B, IA, IB { }
-";
- var project = new UnknownProject ();
- project.FileName = "test.csproj";
- var assembly = GenerateAssembly (project, code);
-
- var A = assembly.GetTypeDefinition ("", "A", 0);
- var B = assembly.GetTypeDefinition ("", "B", 0);
- var C = assembly.GetTypeDefinition ("", "C", 0);
- var D = assembly.GetTypeDefinition ("", "D", 0);
- var IA = assembly.GetTypeDefinition ("", "IA", 0);
- var IB = assembly.GetTypeDefinition ("", "IB", 0);
-
- var result1 = MemberCollector.GetBaseTypes (new [] {A, B, C, D}).ToList ();
- VerifyResult (result1, new Predicate<ITypeDefinition>[] {t => t == A});
-
- var result2 = MemberCollector.GetBaseTypes (new [] {A, B, C, IA}).ToList ();
- VerifyResult (result2, new Predicate<ITypeDefinition>[]
- {t => t == A, t => t == IA});
-
- var result3 = MemberCollector.GetBaseTypes (new [] {A, B, C, D, IA, IB}).ToList ();
- VerifyResult (result3, new Predicate<ITypeDefinition>[]
- {t => t == A, t => t == IA, t => t == IB});
- TypeSystemService.UnloadProject (project, true);
- }
-
- [Test]
- public void TestMatchDeclaringType ()
- {
- var code = @"
-class A
-{
- public virtual void Method() { };
- public void Method(int i) { };
-}
-class B : A
-{
- public override void Method() { };
-}";
- var memberName = "Method";
- var emptyParam = new string [] { };
- var intParam = new [] { "Int32" };
-
- var paramList = new [] { emptyParam, intParam };
- var expected1 = paramList.Select (p => GetMemberFilter ("A", memberName, m => MatchParameters (m, p))).ToList ();
- foreach (var filter in expected1)
- TestCollectMembers (code, "A", memberName, expected1, filter, true, true);
-
- var expected2 = new List<Predicate<IMember>> { GetMemberFilter ("A", memberName, m => MatchParameters (m, emptyParam)) };
- TestCollectMembers (code, "A", memberName, expected2, expected2 [0], false, true);
-
- var expected3 = new List<Predicate<IMember>> { GetMemberFilter ("B", memberName, m => MatchParameters (m, emptyParam)) };
- TestCollectMembers (code, "B", memberName, expected3, expected3 [0], false, true);
- }
-
- [Test]
- public void TestConstructor ()
- {
- var code = @"
-class A
-{
-public A() { }
-public A(int i) { }
-}";
- var emptyParam = new string [] { };
- var intParam = new [] { "Int32" };
- var filters = new List<Predicate<IMember>>
- {
- m => m.SymbolKind == SymbolKind.Constructor && MatchParameters(m, emptyParam),
- m => m.SymbolKind == SymbolKind.Constructor && MatchParameters(m, intParam)
- };
-
- foreach (var filter in filters) {
- var result1 = CollectMembers (code, "A", m => true, filter, true, false);
- VerifyResult (result1, filters);
- }
-
- var result2 = CollectMembers (code, "A", m => true, filters [0], false, true);
- VerifyResult (result2, new [] { filters [0] });
- }
-
-
- [Test]
- public void TestStaticConstructor ()
- {
- var code = @"
-class A
-{
-public A() { }
-static A() { }
-}";
- var emptyParam = new string [] { };
- Predicate<IMember> filter = m => m.SymbolKind == SymbolKind.Constructor && MatchParameters(m, emptyParam);
- var result1 = CollectMembers (code, "A", m => true, filter, true, false);
- Assert.AreEqual (2, result1.Count);
- }
-
-
- [Test]
- public void TestShadowedMember ()
- {
- var code = @"
-class A
-{
- public int Prop
- { get; set; }
-}
-class B : A
-{
- public int Prop
- { get; set; }
-}";
- var members = CollectMembers (code, "A", "Prop", m => true, true, false);
- Assert.AreEqual (1, members.Count);
- }
-
- /// <summary>
- /// Bug 11714 - Rename interface member does not affect other implementations
- /// </summary>
- [Test]
- public void TestBug11714 ()
- {
- var code = @"
-class A : IA
-{
- public int Prop
- { get; set; }
-}
-
-interface IA { int Prop { get; set; } }
-
-class B : IA
-{
- public int Prop
- { get; set; }
-}";
- var members = CollectMembers (code, "A", "Prop", m => true, true, false);
- Assert.AreEqual (3, members.Count);
- }
-
- }
-}
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs
deleted file mode 100755
index 0d67d4142c..0000000000
--- a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs
+++ /dev/null
@@ -1,205 +0,0 @@
-//
-// SearchCollectorTests.cs
-//
-// Author:
-// Mansheng Yang <lightyang0@gmail.com>
-//
-// Copyright (c) 2012 Mansheng Yang
-//
-// 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 ICSharpCode.NRefactory.TypeSystem;
-using MonoDevelop.Core;
-using MonoDevelop.Projects;
-using MonoDevelop.Ide.TypeSystem;
-using NUnit.Framework;
-
-namespace MonoDevelop.Ide.FindInFiles
-{
- [TestFixture]
- public class SearchCollectorTests : UnitTests.TestBase
- {
-
- void VerifyResult<T> (List<T> result, List<T> expected)
- {
- Assert.AreEqual (expected.Count (), result.Count);
- foreach (var item in expected)
- Assert.AreEqual (true, result.Remove(item));
- }
-
- void TestCollectProjects (Solution solution, IEnumerable<IEntity> entities, IEnumerable<Project> expected)
- {
- VerifyResult (SearchCollector.CollectProjects (solution, entities).ToList (), expected.ToList ());
- }
-
- void VerifyResult (List<SearchCollector.FileList> result, List<Tuple<Project, IEnumerable<FilePath>>> expected)
- {
- Assert.AreEqual (expected.Count, result.Count);
- Console.WriteLine (result [0].Files.Count ());
- foreach (var item in expected ) {
- var tuple = item;
- Assert.AreEqual (1, result.RemoveAll (
- f => tuple.Item1 == f.Project && tuple.Item2.All (fileName => f.Files.Any (p => p == fileName))));
- }
- }
-
- void TestCollectFiles (Solution solution, IEnumerable<IEntity> entities, IEnumerable<Tuple<Project, IEnumerable<FilePath>>> expected)
- {
- VerifyResult (SearchCollector.CollectFiles (solution, entities).ToList (), expected.ToList ());
- }
-
- void TestCollectFiles (Project project, IEnumerable<IEntity> entities, IEnumerable<Tuple<Project, IEnumerable<FilePath>>> expected)
- {
- VerifyResult (SearchCollector.CollectFiles (project, entities).ToList (), expected.ToList ());
- }
-
- static Tuple<Project, IEnumerable<FilePath>> CreateTestTuple (Project project, IEnumerable<FilePath> files)
- {
- return Tuple.Create (project, files);
- }
-
- static Tuple<Project, IEnumerable<FilePath>> CreateTestTuple (Project project)
- {
- return Tuple.Create (project, project.Files.Select (f => f.FilePath));
- }
-
- [Ignore("Unreliable")]
- [Test]
- public void TestCollectFiles ()
- {
- var code1 = @"
-namespace project1 {
- class A
- {
- private void Method1() { }
- public void Method2() { }
- }
- public class B
- { }
-}";
- var project1 = new UnknownProject { FileName = "projectc1.csproj" };
- var project2 = new MonoDevelop.CSharp.Project.CSharpProject { FileName = "projectc2.csproj" };
- project2.References.Add (new MonoDevelop.Projects.ProjectReference (project1));
-
- var solution = new Solution ();
- solution.RootFolder.AddItem (project1);
- solution.RootFolder.AddItem (project2);
- solution.RootFolder.AddItem (new UnknownProject { FileName = "dummy.csproj" });
-
- project1.AddFile (new ProjectFile ("dummy.cs"));
- TypeSystemService.LoadProject (project2);
- var wrapper = TypeSystemService.LoadProject (project1);
- TypeSystemService.ParseFile ("test.cs", "text/x-csharp", code1, wrapper);
- var compilation = wrapper.Compilation;
-
- var typeA = compilation.MainAssembly.GetTypeDefinition ("project1", "A", 0);
-
- TestCollectFiles (project1, typeA.GetMembers (m => m.Name == "Method1"),
- new [] { CreateTestTuple (project1, new [] { (FilePath)"test.cs" }) });
- TestCollectFiles (project1, new [] { typeA }, new [] { CreateTestTuple (project1) });
- TestCollectFiles (project1, typeA.GetMembers (m => m.Name == "Method2"), new [] { CreateTestTuple (project1) });
- TestCollectFiles (project1, typeA.GetMembers(), new [] { CreateTestTuple (project1) });
-
- TestCollectFiles (solution, typeA.GetMembers (m => m.Name == "Method1"),
- new [] { CreateTestTuple (project1, new [] { (FilePath)"test.cs" }) });
- TestCollectFiles (solution, typeA.GetMembers (), new [] { CreateTestTuple (project1) });
-
- var typeB = compilation.MainAssembly.GetTypeDefinition ("project1", "B", 0);
- TestCollectFiles (solution, new [] { typeB }, new [] { CreateTestTuple (project1), CreateTestTuple (project2) });
- TestCollectFiles (solution, new [] { typeA, typeB }, new [] { CreateTestTuple (project1), CreateTestTuple (project2) });
- TypeSystemService.UnloadProject (project1);
- TypeSystemService.UnloadProject (project2);
- }
-
- [Ignore("Unreliable")]
- [Test]
- public void TestCollectProjects ()
- {
- var code = @"
-namespace project1 {
- class A
- {
- private void Method1() { }
- public void Method2() { }
- }
- public class B
- {
- private void Method1() { }
- protected void Method2() { }
- }
-}";
- var project1 = new UnknownProject { FileName = "project1.csproj" };
- var project2 = new MonoDevelop.CSharp.Project.CSharpProject { FileName = "project2.csproj" };
- var solution = new Solution ();
- solution.RootFolder.AddItem (project1);
- solution.RootFolder.AddItem (project2);
- solution.RootFolder.AddItem (new UnknownProject { FileName = "project3.csproj" });
-
- TypeSystemService.LoadProject (project2);
- var wrapper = TypeSystemService.LoadProject (project1);
- TypeSystemService.ParseFile ("test.cs", "text/x-csharp", code, wrapper);
- var compilation = wrapper.Compilation;
-
- var typeA = compilation.MainAssembly.GetTypeDefinition ("project1", "A", 0);
- Assert.IsNotNull (typeA);
- TestCollectProjects (solution, new [] { typeA }, new [] { project1 });
- TestCollectProjects (solution, typeA.GetMembers (), new [] { project1 });
- TestCollectProjects (solution, typeA.GetMembers (m => m.Name == "Method1"), new [] { project1 });
- TestCollectProjects (solution, typeA.GetMembers (m => m.Name == "Method2"), new [] { project1 });
-
- project2.References.Add (new MonoDevelop.Projects.ProjectReference (project1));
- var typeB = compilation.MainAssembly.GetTypeDefinition ("project1", "B", 0);
- Assert.IsNotNull (typeB);
- TestCollectProjects (solution, new [] { typeB }, new Project [] { project1, project2 });
- TestCollectProjects (solution, typeB.GetMembers (), new Project [] { project1, project2 });
- TestCollectProjects (solution, typeB.GetMembers (m => m.Name == "Method1"), new [] { project1 });
- TestCollectProjects (solution, typeB.GetMembers (m => m.Name == "Method2"), new Project [] { project1, project2 });
- TypeSystemService.UnloadProject (project1);
- TypeSystemService.UnloadProject (project2);
- }
-
- [Ignore("Unreliable")]
- [Test]
- public void TestCollectForExternalReference ()
- {
- var projects = new List<Project> ();
- var solution = new Solution ();
- for (int i = 0; i < 3; i++) {
- var project = new MonoDevelop.CSharp.Project.CSharpProject { FileName = String.Format ("projectx{0}.csproj", i) };
- projects.Add (project);
- solution.RootFolder.AddItem (project);
- project.AddFile (new ProjectFile (String.Format ("dummy{0}.cs", i)));
- project.AddReference (typeof (object).Assembly.Location);
- TypeSystemService.LoadProject (project);
- TypeSystemService.GetProjectContentWrapper (project).ReconnectAssemblyReferences ();
- }
- solution.RootFolder.AddItem (new UnknownProject { FileName = "test.csproj" });
-
- var compilation = TypeSystemService.GetCompilation (projects[0]);
- var intType = compilation.GetAllTypeDefinitions ().First(t => t.Name == "Int32");
- Assert.AreEqual (null, TypeSystemService.GetProject (intType));
- TestCollectProjects (solution, new [] { intType }, projects);
- TestCollectFiles (solution, new [] { intType }, projects.Select (CreateTestTuple));
- }
-
- }
-}
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs
index 61647513d5..ad079d75f4 100644
--- a/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs
@@ -32,6 +32,7 @@ using MonoDevelop.Projects;
using MonoDevelop.Core;
using MonoDevelop.Ide.CodeCompletion;
using MonoDevelop.Ide.Gui.Content;
+using MonoDevelop.Ide.Editor.Extension;
namespace MonoDevelop.Ide.Gui
{
@@ -92,6 +93,9 @@ namespace MonoDevelop.Ide.Gui
get {
return sb.Length;
}
+ set {
+ throw new NotSupportedException ();
+ }
}
public int TextLength {
@@ -111,6 +115,17 @@ namespace MonoDevelop.Ide.Gui
return null;
}
}
+
+ double ICompletionWidget.ZoomLevel {
+ get {
+ return 1;
+ }
+ }
+
+ void ICompletionWidget.AddSkipChar (int cursorPosition, char c)
+ {
+ // ignore
+ }
#endregion
public void AddChar (char ch)
{
@@ -125,43 +140,51 @@ namespace MonoDevelop.Ide.Gui
static void SimulateInput (CompletionListWindow listWindow, string input)
{
+ var testCompletionWidget = ((TestCompletionWidget)listWindow.CompletionWidget);
+ bool isClosed = false;
+ listWindow.WindowClosed += delegate {
+ isClosed = true;
+ };
foreach (char ch in input) {
switch (ch) {
case '8':
- listWindow.PreProcessKeyEvent (Gdk.Key.Up, '\0', Gdk.ModifierType.None);
- listWindow.PostProcessKeyEvent (Gdk.Key.Up, '\0', Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Up, '\0', Gdk.ModifierType.None));
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Up, '\0', Gdk.ModifierType.None));
break;
case '2':
- listWindow.PreProcessKeyEvent (Gdk.Key.Down, '\0', Gdk.ModifierType.None);
- listWindow.PostProcessKeyEvent (Gdk.Key.Down, '\0', Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Down, '\0', Gdk.ModifierType.None));
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Down, '\0', Gdk.ModifierType.None));
break;
case '4':
- listWindow.PreProcessKeyEvent (Gdk.Key.Left, '\0', Gdk.ModifierType.None);
- listWindow.PostProcessKeyEvent (Gdk.Key.Left, '\0', Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Left, '\0', Gdk.ModifierType.None));
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Left, '\0', Gdk.ModifierType.None));
break;
case '6':
- listWindow.PreProcessKeyEvent (Gdk.Key.Right, '\0', Gdk.ModifierType.None);
- listWindow.PostProcessKeyEvent (Gdk.Key.Right, '\0', Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Right, '\0', Gdk.ModifierType.None));
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Right, '\0', Gdk.ModifierType.None));
break;
case '\t':
- listWindow.PreProcessKeyEvent (Gdk.Key.Tab, '\t', Gdk.ModifierType.None);
- listWindow.PostProcessKeyEvent (Gdk.Key.Tab, '\t', Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Tab, '\t', Gdk.ModifierType.None));
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Tab, '\t', Gdk.ModifierType.None));
break;
case '\b':
- listWindow.PreProcessKeyEvent (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None);
- ((TestCompletionWidget)listWindow.CompletionWidget).Backspace ();
- listWindow.PostProcessKeyEvent (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None));
+ testCompletionWidget.Backspace ();
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.BackSpace, '\b', Gdk.ModifierType.None));
break;
case '\n':
- listWindow.PreProcessKeyEvent (Gdk.Key.Return, '\n', Gdk.ModifierType.None);
- listWindow.PostProcessKeyEvent (Gdk.Key.Return, '\n', Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Return, '\n', Gdk.ModifierType.None));
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk (Gdk.Key.Return, '\n', Gdk.ModifierType.None));
break;
default:
- listWindow.PreProcessKeyEvent ((Gdk.Key)ch, ch, Gdk.ModifierType.None);
- ((TestCompletionWidget)listWindow.CompletionWidget).AddChar (ch);
- listWindow.PostProcessKeyEvent ((Gdk.Key)ch, ch, Gdk.ModifierType.None);
+ listWindow.PreProcessKeyEvent (KeyDescriptor.FromGtk ((Gdk.Key)ch, ch, Gdk.ModifierType.None));
+ testCompletionWidget.AddChar (ch);
+ listWindow.PostProcessKeyEvent (KeyDescriptor.FromGtk ((Gdk.Key)ch, ch, Gdk.ModifierType.None));
break;
}
+ // window closed.
+ if (isClosed)
+ break;
}
}
@@ -194,8 +217,9 @@ namespace MonoDevelop.Ide.Gui
static string RunSimulation (SimulationSettings settings)
{
CompletionListWindow listWindow = CreateListWindow (settings);
+ var testCompletionWidget = (TestCompletionWidget)listWindow.CompletionWidget;
SimulateInput (listWindow, settings.SimulatedInput);
- return ((TestCompletionWidget)listWindow.CompletionWidget).CompletedWord;
+ return testCompletionWidget.CompletedWord;
}
static CompletionListWindow CreateListWindow (CompletionListWindowTests.SimulationSettings settings)
@@ -204,7 +228,6 @@ namespace MonoDevelop.Ide.Gui
dataList.AutoSelect = settings.AutoSelect;
dataList.AddRange (settings.CompletionData);
dataList.DefaultCompletionString = settings.DefaultCompletionString;
- ListWindow.ClearHistory ();
CompletionListWindow listWindow = new CompletionListWindow () {
CompletionDataList = dataList,
CompletionWidget = new TestCompletionWidget (),
@@ -480,7 +503,6 @@ namespace MonoDevelop.Ide.Gui
Assert.AreEqual ("/AbAb", output);
}
- [Ignore("Behavior was changed - commit with '.' now works everytime")]
[Test]
public void TestMatchPunctuationCommitOnSpaceAndPunctuation3 ()
{
@@ -591,8 +613,8 @@ namespace MonoDevelop.Ide.Gui
[Test]
public void TestBug543984 ()
{
- string output = RunSimulation ("", "foo b\n", true, true, false, "foo bar", "foo bar baz");
- Assert.AreEqual ("foo bar", output);
+ string output = RunSimulation ("", "foo#b\n", true, true, false, "foo#bar", "foo#bar#baz");
+ Assert.AreEqual ("foo#bar", output);
}
[Test]
@@ -817,6 +839,100 @@ namespace MonoDevelop.Ide.Gui
Assert.AreEqual ("d", output);
}
+ [Test]
+ public void TestSpaceCommits ()
+ {
+ string output = RunSimulation ("", "over ", true, true,
+ "override",
+ "override foo");
+
+ Assert.AreEqual ("override", output);
+ }
+
+
+
+ [Test]
+ public void TestNumberInput ()
+ {
+ string output = RunSimulation ("", "1.", true, true, false, "foo1");
+ Assert.IsTrue (string.IsNullOrEmpty (output), "output was " + output);
+ }
+
+ static void ContinueSimulation (CompletionListWindow listWindow, ICompletionDataList list, ref TestCompletionWidget testCompletionWidget, string simulatedInput)
+ {
+ listWindow.ResetState ();
+ listWindow.CodeCompletionContext = new CodeCompletionContext ();
+ listWindow.CompletionDataList = list;
+ listWindow.CompletionWidget = testCompletionWidget = new TestCompletionWidget ();
+ listWindow.List.FilterWords ();
+ listWindow.ResetSizes ();
+ listWindow.UpdateWordSelection ();
+ SimulateInput (listWindow, simulatedInput);
+ listWindow.CompleteWord ();
+ }
+
+ [Test]
+ public void TestMruSimpleLastItem ()
+ {
+ var settings = new SimulationSettings () {
+ AutoSelect = true,
+ CompleteWithSpaceOrPunctuation = true,
+ AutoCompleteEmptyMatch = true,
+ CompletionData = new[] { "FooBar1", "Bar", "FooFoo2"}
+ };
+
+ var listWindow = CreateListWindow (settings);
+ var list = listWindow.CompletionDataList;
+ var testCompletionWidget = (TestCompletionWidget)listWindow.CompletionWidget;
+
+ SimulateInput (listWindow, "FooBar\t");
+ Assert.AreEqual ("FooBar1", testCompletionWidget.CompletedWord);
+
+ ContinueSimulation (listWindow, list, ref testCompletionWidget, "FooFoo\t");
+ Assert.AreEqual ("FooFoo2", testCompletionWidget.CompletedWord);
+
+ ContinueSimulation (listWindow, list, ref testCompletionWidget, "F\t");
+ Assert.AreEqual ("FooFoo2", testCompletionWidget.CompletedWord);
+ }
+
+ [Test]
+ public void TestMruEmptyMatch ()
+ {
+ var settings = new SimulationSettings () {
+ AutoSelect = true,
+ CompleteWithSpaceOrPunctuation = true,
+ AutoCompleteEmptyMatch = true,
+ CompletionData = new[] { "Foo", "Bar", "Test"}
+ };
+
+ var listWindow = CreateListWindow (settings);
+ var list = listWindow.CompletionDataList;
+ var testCompletionWidget = (TestCompletionWidget)listWindow.CompletionWidget;
+ SimulateInput (listWindow, "Foo\t");
+ ContinueSimulation (listWindow, list, ref testCompletionWidget, "F\t");
+ Assert.AreEqual ("Foo", testCompletionWidget.CompletedWord);
+
+ ContinueSimulation (listWindow, list, ref testCompletionWidget, "Bar\t");
+ Assert.AreEqual ("Bar", testCompletionWidget.CompletedWord);
+
+ ContinueSimulation (listWindow, list, ref testCompletionWidget, "\t");
+ Assert.AreEqual ("Bar", testCompletionWidget.CompletedWord);
+ }
+
+ [Test]
+ public void TestCloseWithPunctiation ()
+ {
+ var output = RunSimulation ("", "\"\t", true, true, false, punctuationData);
+ Assert.AreEqual (null, output);
+ }
+
+ [Test]
+ public void TestPreference ()
+ {
+ string output = RunSimulation ("", "expr\t", true, true, false, "expression", "PostfixExpressionStatementSyntax");
+ Assert.AreEqual ("expression", output);
+ }
+
[TestFixtureSetUp]
public void SetUp()
diff --git a/main/tests/UnitTests/MonoDevelop.Projects/CompletionDatabaseTests.cs b/main/tests/UnitTests/MonoDevelop.Projects/CompletionDatabaseTests.cs
deleted file mode 100644
index 228a8b8a23..0000000000
--- a/main/tests/UnitTests/MonoDevelop.Projects/CompletionDatabaseTests.cs
+++ /dev/null
@@ -1,889 +0,0 @@
-// CompletionDatabaseTests.cs
-//
-// Author:
-// Lluis Sanchez Gual <lluis@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.IO;
-using System.Collections.Generic;
-using MonoDevelop.Projects;
-using MonoDevelop.Projects.Dom;
-using MonoDevelop.Projects.Dom.Parser;
-using NUnit.Framework;
-using UnitTests;
-using Mono.CSharp;
-using System.Linq;
-
-namespace MonoDevelop.Projects
-{
- [TestFixture]
- public class CompletionDatabaseTests: TestBase
- {
- Solution solution;
- ProjectDom mainProject;
- ProjectDom lib1;
- ProjectDom lib2;
-
- public override void Setup ()
- {
- base.Setup ();
- string solFile = Util.GetSampleProject ("completion-db-test", "CompletionDbTest.sln");
- solution = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
- ProjectDomService.Load (solution);
-
- Project prj;
- prj = solution.FindProjectByName ("Library2");
- lib2 = ProjectDomService.GetProjectDom (prj);
- lib2.ForceUpdate (true);
- prj = solution.FindProjectByName ("Library1");
- lib1 = ProjectDomService.GetProjectDom (prj);
- lib1.ForceUpdate (true);
- prj = solution.FindProjectByName ("CompletionDbTest");
- mainProject = ProjectDomService.GetProjectDom (prj);
- mainProject.ForceUpdate (true);
- }
-
- public override void TearDown ()
- {
- ProjectDomService.Unload (solution);
- base.TearDown ();
- }
-
- void ReplaceFile (string targetRelativePath, string sourceRelativePath)
- {
- string tfile = mainProject.Project.GetAbsoluteChildPath (targetRelativePath);
- string sfile = mainProject.Project.GetAbsoluteChildPath (sourceRelativePath);
- File.Copy (sfile, tfile, true);
- ProjectDomService.Parse (tfile, null);
- }
-
- [Test]
- public void References ()
- {
- Assert.AreEqual (4, mainProject.References.Count);
- Assert.AreEqual (3, lib1.References.Count);
- Assert.AreEqual (3, lib2.References.Count);
- }
-
- [Test]
- public void SimpleGetType ()
- {
- // Simple get
- IType type = mainProject.GetType ("CompletionDbTest.MainClass");
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.MainClass", type.FullName);
-
- // Deep search in local project
- type = mainProject.GetType ("CompletionDbTest.MainClass", true);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.MainClass", type.FullName);
-
- // Non deep search
- // FIXME: deep search is currently the same as non-deep-search
-// type = mainProject.GetType ("Library2.CWidget", false);
-// Assert.IsNull (type);
-
- // Deep search by default
- type = mainProject.GetType ("Library2.CWidget");
- Assert.IsNotNull (type);
- Assert.AreEqual ("Library2.CWidget", type.FullName);
-
- //check that references are accessible, but not references of references
- type = mainProject.GetType ("Library3.Lib3Class");
- Assert.IsNull (type);
- type = lib2.GetType ("Library3.Lib3Class");
- Assert.IsNotNull (type);
-
- // Deep insensitive
- type = mainProject.GetType ("library2.cwidget", true, false);
- Assert.IsNotNull (type);
- Assert.AreEqual ("Library2.CWidget", type.FullName);
-
- // Case sensitive
- type = mainProject.GetType ("library2.cwidget", true, true);
- Assert.IsNull (type);
-
- // Not generic
- type = mainProject.GetType ("CompletionDbTest.MainClass", 1, true);
- Assert.IsNull (type);
-
- // System.Object
- type = mainProject.GetType ("System.Object", true, true);
- Assert.IsNotNull (type);
- Assert.AreEqual ("System.Object", type.FullName);
- }
-
- [Test]
- public void GetGenericType ()
- {
- List<IReturnType> args = new List<IReturnType> ();
- DomReturnType rt = new DomReturnType ("System.String");
- args.Add (rt);
- IType type = mainProject.GetType ("CompletionDbTest.SomeGeneric", args);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.SomeGeneric[System.String]", type.FullName);
- Assert.AreEqual (0, type.TypeParameters.Count);
-
- IMethod met = FindMember (type, "Run") as IMethod;
- Assert.IsNotNull (met);
- Assert.AreEqual (1, met.Parameters.Count);
- Assert.AreEqual ("System.String", met.Parameters[0].ReturnType.FullName);
- Assert.IsNotNull (met.ReturnType);
- Assert.AreEqual ("System.String", met.ReturnType.FullName);
-
- type = mainProject.GetType ("Library2.GenericWidget");
- Assert.IsNotNull (type);
- Assert.AreEqual ("Library2.GenericWidget", type.FullName);
- Assert.AreEqual (0, type.TypeParameters.Count);
-
- type = mainProject.GetType ("Library2.GenericWidget", 1, true);
- Assert.IsNotNull (type);
- Assert.AreEqual ("Library2.GenericWidget", type.FullName);
- Assert.AreEqual (1, type.TypeParameters.Count);
-
- type = mainProject.GetType ("Library2.GenericWidget", 2, true);
- Assert.IsNotNull (type);
- Assert.AreEqual ("Library2.GenericWidget", type.FullName);
- Assert.AreEqual (2, type.TypeParameters.Count);
-
- type = mainProject.GetType ("Library2.GenericWidget", 3, true);
- Assert.IsNull (type);
-
- // Inner generic type
-
- type = mainProject.GetType ("Library2.Container.InnerClass1", 1, true);
- Assert.IsNotNull (type);
- }
-
- IMember FindMember (IType type, string name)
- {
- foreach (IMember mem in type.Members)
- if (mem.Name == name)
- return mem;
- return null;
- }
-
- [Test]
- public void GetSubclasses ()
- {
- IType type = mainProject.GetType ("Library2.CWidget", true);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("Library2.CContainer"));
- Assert.IsTrue (types.Contains ("Library2.SomeContainer.CInnerWidget"));
- Assert.IsTrue (types.Contains ("Library2.CExtraContainer"));
- Assert.IsTrue (types.Contains ("Library2.SomeContainer.CExtraInnerWidget"));
- Assert.IsTrue (types.Contains ("Library1.CBin"));
- Assert.IsTrue (types.Contains ("Library1.CList"));
- Assert.IsTrue (types.Contains ("Library1.SomeContainer.CInnerWidget"));
- Assert.IsTrue (types.Contains ("Library1.SomeContainer.SomeInnerContainer.CSubInnerWidget"));
- Assert.IsTrue (types.Contains ("Library1.CExtraBin"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerSub"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub.CInnerWidget1"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub.CInnerWidget2"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub.CInnerWidget3"));
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget1"));
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget2"));
- Assert.AreEqual (16, types.Count);
-
- // No deep search
-
- type = mainProject.GetType ("Library2.CWidget", true);
- Assert.IsNotNull (type);
-
- types.Clear ();
- foreach (IType t in mainProject.GetSubclasses (type, false))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget1"));
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget2"));
- Assert.AreEqual (2, types.Count);
-
- // Interface subclassing
-
- type = mainProject.GetType ("Library2.IObject", true);
- Assert.IsNotNull (type);
-
- types.Clear ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("Library2.CExtraContainer"));
- Assert.IsTrue (types.Contains ("Library2.SomeContainer.CExtraInnerWidget"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub.CInnerWidget1"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub.CInnerWidget2"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerSub"));
- Assert.IsTrue (types.Contains ("Library1.ISimple"));
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget1"));
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget2"));
- Assert.AreEqual (9, types.Count);
- }
-
- [Test]
- public void GetFileTypes ()
- {
- string file = lib1.Project.GetAbsoluteChildPath ("MyClass.cs");
-
- List<string> types = new List<string> ();
- foreach (IType t in lib1.GetTypes (file))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("Library1.CBin"));
- Assert.IsTrue (types.Contains ("Library1.CList"));
- Assert.IsTrue (types.Contains ("Library1.SomeContainer"));
- Assert.IsTrue (types.Contains ("Library1.CExtraBin"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerSub"));
- Assert.IsTrue (types.Contains ("Library1.CExtraContainerInnerSub"));
- Assert.IsTrue (types.Contains ("Library1.ISimple"));
- Assert.IsTrue (types.Contains ("Library1.TestAttribute"));
-
- Assert.AreEqual (8, types.Count);
- }
-
- [Test]
- public void GetInheritanceTree ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.CustomWidget1", false);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (type))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget1"));
- Assert.IsTrue (types.Contains ("Library1.CBin"));
- Assert.IsTrue (types.Contains ("Library1.ISimple"));
- Assert.IsTrue (types.Contains ("Library2.CWidget"));
- Assert.IsTrue (types.Contains ("Library2.IObject"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (6, types.Count);
-
- type = mainProject.GetType ("CompletionDbTest.CustomWidget2", false);
-
- types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (type))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.CustomWidget2"));
- Assert.IsTrue (types.Contains ("Library1.SomeContainer.CInnerWidget"));
- Assert.IsTrue (types.Contains ("Library2.IObject"));
- Assert.IsTrue (types.Contains ("Library2.CWidget"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (5, types.Count);
- }
-
-
- [Test]
- public void GetInheritanceTreeForEnumsAndStructs ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.TestEnum", false);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (type)) {
- Console.WriteLine (t.FullName);
- types.Add (t.FullName);
- }
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.TestEnum"));
- Assert.IsTrue (types.Contains ("System.Enum"));
- Assert.IsTrue (types.Contains ("System.Object"));
-
- type = mainProject.GetType ("CompletionDbTest.TestStruct", false);
-
- types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (type))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.TestStruct"));
- Assert.IsTrue (types.Contains ("System.ValueType"));
- Assert.IsTrue (types.Contains ("System.Object"));
- }
- [Test]
- public void GetNamespaceContents ()
- {
- var types = new List<string> ();
- foreach (IMember mem in mainProject.GetNamespaceContents ("SharedNamespace1", true, true))
- types.Add (mem.FullName);
- Assert.IsTrue (types.Contains ("SharedNamespace1.A"));
- Assert.IsTrue (types.Contains ("SharedNamespace1.B"));
- Assert.IsTrue (types.Contains ("SharedNamespace1.E"));
- Assert.IsTrue (types.Contains ("SharedNamespace1.F"));
- Assert.AreEqual (4, types.Count);
-
- types = new List<string> ();
- foreach (IMember mem in mainProject.GetNamespaceContents ("SharedNamespace1", false, true))
- types.Add (mem.FullName);
- Assert.IsTrue (types.Contains ("SharedNamespace1.A"));
- Assert.IsTrue (types.Contains ("SharedNamespace1.B"));
- Assert.AreEqual (2, types.Count);
-
- types = new List<string> ();
- foreach (IMember mem in mainProject.GetNamespaceContents ("sharednamespace1", true, false))
- types.Add (mem.FullName);
- Assert.IsTrue (types.Contains ("SharedNamespace1.A"));
- Assert.IsTrue (types.Contains ("SharedNamespace1.B"));
- Assert.IsTrue (types.Contains ("SharedNamespace1.E"));
- Assert.IsTrue (types.Contains ("SharedNamespace1.F"));
- Assert.AreEqual (4, types.Count);
-
- types = new List<string> ();
- foreach (IMember mem in mainProject.GetNamespaceContents ("SharedNamespace2", true, true))
- types.Add (mem.FullName);
- Assert.IsTrue (types.Contains ("SharedNamespace2.C"));
- Assert.IsTrue (types.Contains ("SharedNamespace2.D"));
- Assert.IsTrue (types.Contains ("SharedNamespace2.G"));
- Assert.IsTrue (types.Contains ("SharedNamespace2.H"));
- Assert.AreEqual (4, types.Count);
-
- types = new List<string> ();
- foreach (IMember mem in mainProject.GetNamespaceContents ("SharedNamespace2", false, true))
- types.Add (mem.FullName);
- Assert.AreEqual (0, types.Count);
- }
-
- [Test]
- public void GetGenericSubclassesNoParams ()
- {
- IType type = mainProject.GetType ("Library2.GenericWidget", true);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (GetName(t));
-
- Assert.IsTrue (types.Contains ("Library2.GenericBin"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBin"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidget"));
- Assert.AreEqual (3, types.Count);
- }
-
- [Test]
- public void GetGenericSubclassesTemplate ()
- {
- // Uninstantiated generic type with one parameter
-
- IType type = mainProject.GetType ("Library2.GenericWidget", 1, true);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (GetName (t));
-
- // We don't support getting the subclasses of a parametrized type.
- // It is not clear what should be considered a subclass in this case.
- Assert.AreEqual (0, types.Count);
- }
-
- [Test]
- public void GetGenericSubclassesParamsInt ()
- {
- // Generic type with one parameter
-
- List<IReturnType> args = new List<IReturnType> ();
- args.Add (new DomReturnType ("System.Int32"));
-
- IType type = mainProject.GetType ("Library2.GenericWidget", args);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (GetName(t));
-
- Assert.IsTrue (types.Contains ("Library2.GenericBin[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library2.GenericBinInt"));
- Assert.IsTrue (types.Contains ("Library2.Container.InnerClass1[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library2.Container.InnerClass2"));
- Assert.IsTrue (types.Contains ("Library2.Container.InnerClass3"));
- Assert.IsTrue (types.Contains ("Library2.Container.InnerClass4"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidget[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBin[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBinInt1"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBinInt2"));
- Assert.IsTrue (types.Contains ("Library1.SubInnerClass[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library1.SubContainer.InnerClass1[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library1.SubContainer.InnerClass2"));
- Assert.IsTrue (types.Contains ("Library1.SubContainer.InnerClass3"));
- Assert.IsTrue (types.Contains ("Library1.SubContainer.InnerClass4"));
- Assert.AreEqual (15, types.Count);
- }
-
- [Test]
- public void GetGenericSubclassesParamsString ()
- {
- // Generic type with one string parameter
-
- List<IReturnType> args = new List<IReturnType> ();
- args.Add (new DomReturnType ("System.String"));
-
- IType type = mainProject.GetType ("Library2.GenericWidget", args);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (GetName(t));
-
- Assert.IsTrue (types.Contains ("Library2.GenericBin[System.String]"));
- Assert.IsTrue (types.Contains ("Library2.GenericBinString"));
- Assert.IsTrue (types.Contains ("Library2.Container.InnerClass1[System.String]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidget[System.String]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBin[System.String]"));
- Assert.IsTrue (types.Contains ("Library1.SubInnerClass[System.String]"));
- Assert.IsTrue (types.Contains ("Library1.SubContainer.InnerClass1[System.String]"));
- Assert.AreEqual (7, types.Count);
- }
-
- [Test]
- public void GetGenericSubclassesParamsStringInt ()
- {
- // Generic type with one string and one int
-
- List<IReturnType> args = new List<IReturnType> ();
- args.Add (new DomReturnType ("System.String"));
- args.Add (new DomReturnType ("System.Int32"));
-
- IType type = mainProject.GetType ("Library2.GenericWidget", args);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (GetName(t));
-
- Assert.IsTrue (types.Contains ("Library2.GenericBin[System.String,System.Int32]"));
- Assert.IsTrue (types.Contains ("Library2.SpecialGenericBin[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library2.GenericBinStringInt"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBin[System.String,System.Int32]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidget[System.String,System.Int32]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBinStringInt1"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBinStringInt2"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidgetStringNull[System.Int32]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidgetNullInt[System.String]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidgetSwapped[System.Int32,System.String]"));
- Assert.AreEqual (10, types.Count);
- }
-
- [Test]
- public void GetGenericSubclassesParamsIntString ()
- {
- // Generic type with one int and one string
-
- List<IReturnType> args = new List<IReturnType> ();
- args.Add (new DomReturnType ("System.Int32"));
- args.Add (new DomReturnType ("System.String"));
-
- IType type = mainProject.GetType ("Library2.GenericWidget", args);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (GetName(t));
-
- Assert.IsTrue (types.Contains ("Library2.GenericBin[System.Int32,System.String]"));
- Assert.IsTrue (types.Contains ("Library2.GenericBinIntString"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericBin[System.Int32,System.String]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidget[System.Int32,System.String]"));
- Assert.IsTrue (types.Contains ("Library1.SubGenericWidgetSwapped[System.String,System.Int32]"));
- Assert.AreEqual (5, types.Count);
- }
-
- string GetName (IType t)
- {
- if (t.TypeParameters.Count == 0)
- return t.FullName;
- else
- return t.FullName + "`" + t.TypeParameters.Count;
- }
-
-/* [Test]
- public void GetObjectSubclasses ()
- {
- IType type = mainProject.GetType ("System.Object", true);
- Assert.IsNotNull (type);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetSubclasses (type, true))
- types.Add (t.FullName);
- }
-*/
-
- [Test]
- public void RewriteGenericType ()
- {
- // Check that the instantiated type cache is properly invalidated
- // when a generic type changes.
-
- List<IReturnType> args = new List<IReturnType> ();
- args.Add (new DomReturnType ("System.Int32"));
- IType type = mainProject.GetType ("CompletionDbTest.GenericRewrite", args);
- Assert.IsNotNull (type);
- Assert.IsTrue (type is InstantiatedType);
- Assert.IsTrue (type.FieldCount == 1);
-
- ReplaceFile ("GenericRewrite.cs", "Replacements/GenericRewrite.cs");
-
- type = mainProject.GetType ("CompletionDbTest.GenericRewrite", args);
- Assert.IsNotNull (type);
- Assert.IsTrue (type is InstantiatedType);
- Assert.IsTrue (type.FieldCount == 2);
- }
-
- [Test]
- public void GenericConstraintTest_Class ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.GenericConstraintTest1", 1, false);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.GenericConstraintTest1", type.FullName);
- Assert.AreEqual (1, type.TypeParameters.Count);
- Assert.AreEqual (1, type.FieldCount);
-
- List<IField> fs = new List<IField> (type.Fields);
- IReturnType rt = fs [0].ReturnType;
-
- IType fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("T", fieldType.Name);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest1.T"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (2, types.Count);
- }
-
- [Test]
- public void GenericConstraintTest_Struct ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.GenericConstraintTest2", 1, false);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.GenericConstraintTest2", type.FullName);
- Assert.AreEqual (1, type.TypeParameters.Count);
- Assert.AreEqual (1, type.FieldCount);
-
- List<IField> fs = new List<IField> (type.Fields);
- IReturnType rt = fs [0].ReturnType;
-
- IType fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("T", fieldType.Name);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest2.T"));
- Assert.IsTrue (types.Contains ("System.ValueType"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (3, types.Count);
- }
-
- [Test]
- public void GenericConstraintTest_New ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.GenericConstraintTest3", 1, false);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.GenericConstraintTest3", type.FullName);
- Assert.AreEqual (1, type.TypeParameters.Count);
- Assert.AreEqual (1, type.FieldCount);
-
- List<IField> fs = new List<IField> (type.Fields);
- IReturnType rt = fs [0].ReturnType;
-
- IType fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("T", fieldType.Name);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest3.T"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (2, types.Count);
- }
-
- [Test]
- public void GenericConstraintTest_WithBase ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.GenericConstraintTest4", 2, false);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.GenericConstraintTest4", type.FullName);
- Assert.AreEqual (2, type.TypeParameters.Count);
- Assert.AreEqual (2, type.FieldCount);
-
- // First field
-
- List<IField> fs = new List<IField> (type.Fields);
- IReturnType rt = fs [0].ReturnType;
-
- IType fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("T", fieldType.Name);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest4.T"));
- Assert.IsTrue (types.Contains ("Library1.CBin"));
- Assert.IsTrue (types.Contains ("Library2.CWidget"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (4, types.Count);
-
- // Second field
-
- rt = fs [1].ReturnType;
-
- fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("U", fieldType.Name);
-
- types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest4.U"));
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest4.T"));
- Assert.IsTrue (types.Contains ("Library1.CBin"));
- Assert.IsTrue (types.Contains ("Library2.CWidget"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (5, types.Count);
- }
-
- [Test]
- public void GenericConstraintTest_WithWrongBase ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.GenericConstraintTest5", 2, false);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.GenericConstraintTest5", type.FullName);
- Assert.AreEqual (2, type.TypeParameters.Count);
- Assert.AreEqual (2, type.FieldCount);
-
- // First field
-
- List<IField> fs = new List<IField> (type.Fields);
- IReturnType rt = fs [0].ReturnType;
-
- IType fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("T", fieldType.Name);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest5.T"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (2, types.Count);
-
- // Second field
-
- rt = fs [1].ReturnType;
-
- fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("U", fieldType.Name);
-
- types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest5.U"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (2, types.Count);
- }
-
- [Test]
- public void GenericConstraintTest_ClassAndInterface ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.GenericConstraintTest6", 1, false);
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.GenericConstraintTest6", type.FullName);
- Assert.AreEqual (1, type.TypeParameters.Count);
- Assert.AreEqual (1, type.FieldCount);
-
- List<IField> fs = new List<IField> (type.Fields);
- IReturnType rt = fs [0].ReturnType;
-
- IType fieldType = mainProject.GetType (rt);
- Assert.IsNotNull (fieldType);
- Assert.AreEqual ("T", fieldType.Name);
-
- List<string> types = new List<string> ();
- foreach (IType t in mainProject.GetInheritanceTree (fieldType))
- types.Add (t.FullName);
-
- Assert.IsTrue (types.Contains ("CompletionDbTest.GenericConstraintTest6.T"));
- Assert.IsTrue (types.Contains ("Library1.CBin"));
- Assert.IsTrue (types.Contains ("Library2.CWidget"));
- Assert.IsTrue (types.Contains ("System.ICloneable"));
- Assert.IsTrue (types.Contains ("System.Object"));
- Assert.AreEqual (5, types.Count);
- }
-
- [Test]
- public void PartialClass ()
- {
- IType type = mainProject.GetType ("CompletionDbTest.PartialTest");
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.PartialTest", type.FullName);
-
- List<string> members = new List<string> ();
- foreach (IMember mem in type.Members)
- members.Add (mem.Name);
-
- Assert.AreEqual (15, members.Count);
- Assert.IsTrue (members.Contains ("Field1"));
- Assert.IsTrue (members.Contains ("Property1"));
- Assert.IsTrue (members.Contains ("Event1"));
- Assert.IsTrue (members.Contains ("Method1"));
- Assert.IsTrue (members.Contains ("Inner1"));
- Assert.IsTrue (members.Contains ("Field2"));
- Assert.IsTrue (members.Contains ("Property2"));
- Assert.IsTrue (members.Contains ("Event2"));
- Assert.IsTrue (members.Contains ("Method2"));
- Assert.IsTrue (members.Contains ("Inner2"));
- Assert.IsTrue (members.Contains ("Field3"));
- Assert.IsTrue (members.Contains ("Property3"));
- Assert.IsTrue (members.Contains ("Event3"));
- Assert.IsTrue (members.Contains ("Method3"));
- Assert.IsTrue (members.Contains ("Inner3"));
-
- ReplaceFile ("PartialTest2.cs", "Replacements/PartialTest2.cs");
-
- type = mainProject.GetType ("CompletionDbTest.PartialTest");
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.PartialTest", type.FullName);
-
- members = new List<string> ();
- foreach (IMember mem in type.Members)
- members.Add (mem.Name);
-
- Assert.AreEqual (10, members.Count);
- Assert.IsTrue (members.Contains ("Field2"));
- Assert.IsTrue (members.Contains ("Property2"));
- Assert.IsTrue (members.Contains ("Event2"));
- Assert.IsTrue (members.Contains ("Method2"));
- Assert.IsTrue (members.Contains ("Inner2"));
- Assert.IsTrue (members.Contains ("Field3"));
- Assert.IsTrue (members.Contains ("Property3"));
- Assert.IsTrue (members.Contains ("Event3"));
- Assert.IsTrue (members.Contains ("Method3"));
- Assert.IsTrue (members.Contains ("Inner3"));
-
- ReplaceFile ("PartialTest2.cs", "Replacements/EmptyFile.cs");
-
- type = mainProject.GetType ("CompletionDbTest.PartialTest");
- Assert.IsNotNull (type);
- Assert.AreEqual ("CompletionDbTest.PartialTest", type.FullName);
-
- members = new List<string> ();
- foreach (IMember mem in type.Members)
- members.Add (mem.Name);
-
- Assert.AreEqual (5, members.Count);
- Assert.IsTrue (members.Contains ("Field3"));
- Assert.IsTrue (members.Contains ("Property3"));
- Assert.IsTrue (members.Contains ("Event3"));
- Assert.IsTrue (members.Contains ("Method3"));
- Assert.IsTrue (members.Contains ("Inner3"));
-
- ReplaceFile ("PartialTest1.cs", "Replacements/EmptyFile.cs");
-
- type = mainProject.GetType ("CompletionDbTest.PartialTest");
- Assert.IsNull (type);
- }
-
- [Test]
- public void NamespaceExistsTest ()
- {
- Assert.IsTrue (mainProject.NamespaceExists ("Level1"), "Level1 doesn't exist.");
- Assert.IsTrue (mainProject.NamespaceExists ("Level1.Level2"), "Level1.Level2 doesn't exist.");
- Assert.IsTrue (mainProject.NamespaceExists ("Level1.Level2.Level3"), "Level1.Level2.Level3 doesn't exist.");
- Assert.IsTrue (mainProject.NamespaceExists ("Level1.Level2.Level3.Level4"), "Level1.Level2.Level3.Level4 doesn't exist.");
- Assert.IsFalse (mainProject.NamespaceExists ("Level1.Level2.Level3.Level4.Level5"), "Level5 shouldn't exist.");
- Assert.IsFalse (mainProject.NamespaceExists ("Level1.Level3"), "level1.level3 shouldn't exist.");
- }
-
- [Test]
- public void ClassAttributeTest ()
- {
- // Simple get
- IType type = mainProject.GetType ("CompletionDbTest.AttributeTest");
- Assert.IsNotNull (type);
- Assert.AreEqual (1, type.Attributes.Count ());
- Assert.AreEqual ("Serializable", type.Attributes.First ().Name);
- }
-
- [Test]
- public void MemberAttributeTest ()
- {
- // Simple get
- IType type = mainProject.GetType ("CompletionDbTest.AttributeTest2");
- Assert.IsNotNull (type);
-
- var prop = type.Properties.First ();
- Assert.AreEqual (1, prop.Attributes.Count ());
- Assert.AreEqual ("Obsolete", prop.Attributes.First ().Name);
-
- var method = type.Methods.First ();
- Assert.AreEqual (1, method.Attributes.Count ());
- Assert.AreEqual ("Obsolete", method.Attributes.First ().Name);
- }
-
- [Test]
- public void CustomAttributeTest ()
- {
- // Simple get
- IType type = mainProject.GetType ("CompletionDbTest.AttributeTest3");
- Assert.IsNotNull (type);
- Assert.AreEqual (1, type.Attributes.Count ());
-
- var att = type.Attributes.First ();
- Assert.AreEqual ("Library1.TestAttribute", att.AttributeType.FullName);
- Assert.AreEqual (2, att.PositionalArguments.Count);
-
- var expr1 = att.PositionalArguments[0] as System.CodeDom.CodePrimitiveExpression;
- Assert.IsNotNull (expr1);
- Assert.AreEqual ("str1", expr1.Value);
-
- var expr2 = att.PositionalArguments[1] as System.CodeDom.CodePrimitiveExpression;
- Assert.IsNotNull (expr2);
- Assert.AreEqual (5, expr2.Value);
-
- Assert.AreEqual (1, att.NamedArguments.Count);
- Assert.IsTrue (att.NamedArguments.ContainsKey ("Blah"));
- var expr3 = att.NamedArguments["Blah"] as System.CodeDom.CodePrimitiveExpression;
- Assert.IsNotNull (expr3);
- Assert.AreEqual ("str2", expr3.Value);
- }
-
- }
-}
diff --git a/main/tests/UnitTests/MonoDevelop.Projects/DomCompilationUnitTests.cs b/main/tests/UnitTests/MonoDevelop.Projects/DomCompilationUnitTests.cs
deleted file mode 100644
index 68a7f30ff1..0000000000
--- a/main/tests/UnitTests/MonoDevelop.Projects/DomCompilationUnitTests.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-// DomCompilationUnitTests.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 System.IO;
-using NUnit.Framework;
-using MonoDevelop.Projects.Dom;
-
-namespace UnitTests
-{
- [TestFixture()]
- public class DomCompilationUnitTests : UnitTests.TestBase
- {
- [Test()]
- public void TestGetNamespaceContentsCase1 ()
- {
- CompilationUnit unit = new CompilationUnit ("file.cs");
- unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
- unit.Add (new DomType ("ANamespace.AClass2"));
- unit.Add (new DomType ("ANamespace.BClass2"));
- unit.Add (new DomType ("CClass3"));
-
- List<IMember> member = new List<IMember> ();
- unit.GetNamespaceContents (member, "", true);
- Assert.AreEqual (2, member.Count);
- Namespace ns = member[0] as Namespace;
- Assert.IsNotNull (ns);
- Assert.AreEqual ("ANamespace", ns.Name);
-
- IType type = member[1] as IType;
- Assert.IsNotNull (type);
- Assert.AreEqual ("CClass3", type.FullName);
- }
-
- [Test()]
- public void TestGetNamespaceContentsCase2 ()
- {
- CompilationUnit unit = new CompilationUnit ("file.cs");
- unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
- unit.Add (new DomType ("ANamespace.AClass2"));
- unit.Add (new DomType ("ANamespace.BClass2"));
- unit.Add (new DomType ("CClass3"));
-
- List<IMember> member = new List<IMember> ();
- unit.GetNamespaceContents (member, "ANamespace", true);
-
- Assert.AreEqual (3, member.Count);
- Namespace ns = member[0] as Namespace;
- Assert.IsNotNull (ns);
- Assert.AreEqual ("AnotherNamespace", ns.Name);
-
- IType type = member[1] as IType;
- Assert.IsNotNull (type);
- Assert.AreEqual ("AClass2", type.Name);
-
- type = member[2] as IType;
- Assert.IsNotNull (type);
- Assert.AreEqual ("BClass2", type.Name);
- }
-
- [Test()]
- public void TestGetNamespaceContentsCase3 ()
- {
- CompilationUnit unit = new CompilationUnit ("file.cs");
- unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
- unit.Add (new DomType ("ANamespace.AClass2"));
- unit.Add (new DomType ("ANamespace.BClass2"));
- unit.Add (new DomType ("CClass3"));
-
- List<IMember> member = new List<IMember> ();
- unit.GetNamespaceContents (member, "ANamespace.AnotherNamespace", true);
- Assert.AreEqual (3, member.Count);
-
- IType type = member[0] as IType;
- Assert.IsNotNull (type);
- Assert.AreEqual ("AClass", type.Name);
-
- type = member[1] as IType;
- Assert.IsNotNull (type);
- Assert.AreEqual ("BClass", type.Name);
-
- type = member[2] as IType;
- Assert.IsNotNull (type);
- Assert.AreEqual ("CClass", type.Name);
- }
-
- [Test()]
- public void TestGetNamespaceContentsCase4 ()
- {
- CompilationUnit unit = new CompilationUnit ("file.cs");
- unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
- unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
- unit.Add (new DomType ("ANamespace.AClass2"));
- unit.Add (new DomType ("ANamespace.BClass2"));
- unit.Add (new DomType ("CClass3"));
-
- List<IMember> member = new List<IMember> ();
- unit.GetNamespaceContents (member, "ANamespace.NotExist", true);
- Assert.AreEqual (0, member.Count);
- }
- }
-}
diff --git a/main/tests/UnitTests/MonoDevelop.Projects/DomPersistenceTests.cs b/main/tests/UnitTests/MonoDevelop.Projects/DomPersistenceTests.cs
deleted file mode 100644
index 06238256eb..0000000000
--- a/main/tests/UnitTests/MonoDevelop.Projects/DomPersistenceTests.cs
+++ /dev/null
@@ -1,457 +0,0 @@
-//
-// DomPersistenceTests.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.CodeDom;
-using System.Collections.Generic;
-using System.IO;
-using NUnit.Framework;
-using MonoDevelop.Projects.Dom;
-using MonoDevelop.Projects.Dom.Serialization;
-
-namespace MonoDevelop.Projects.DomTests
-{
- [TestFixture()]
- public class DomPersistenceTests : UnitTests.TestBase
- {
-
- [Test()]
- public void ReadWriteLocationTest ()
- {
- DomLocation input = new DomLocation (3, 9);
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, null, input);
- byte[] bytes = ms.ToArray ();
-
- DomLocation result = DomPersistence.ReadLocation (CreateReader (bytes), null);
- Assert.AreEqual (3, result.Line);
- Assert.AreEqual (9, result.Column);
- }
-
- [Test()]
- public void ReadWriteRegionTest ()
- {
- DomRegion input = new DomRegion (1, 2, 3, 4);
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomRegion result = DomPersistence.ReadRegion (CreateReader (bytes), DefaultNameDecoder);
- Assert.AreEqual (1, result.Start.Line);
- Assert.AreEqual (2, result.Start.Column);
- Assert.AreEqual (3, result.End.Line);
- Assert.AreEqual (4, result.End.Column);
- }
-
-
- [Test()]
- public void ReadWriteFieldTest ()
- {
- DomField input = new DomField ();
- input.Name = "TestField";
- input.Location = new DomLocation (5, 10);
- input.Documentation = "testDocumentation";
- input.Modifiers = Modifiers.Static;
- input.ReturnType = new DomReturnType ("System.String");
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomField result = DomPersistence.ReadField (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("TestField", result.Name);
- Assert.AreEqual ("testDocumentation", result.Documentation);
- Assert.AreEqual (new DomLocation (5, 10), result.Location);
- Assert.AreEqual (Modifiers.Static, result.Modifiers);
- Assert.AreEqual ("System.String", result.ReturnType.FullName);
- }
-
- [Test()]
- public void ReadWriteFieldTest2 ()
- {
- DomField input = new DomField ();
- input.Name = null;
- input.Location = DomLocation.Empty;
- input.Documentation = null;
- input.Modifiers = Modifiers.None;
- input.ReturnType = null;
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomField result = DomPersistence.ReadField (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual (null, result.Name);
- Assert.AreEqual (null, result.Documentation);
- Assert.AreEqual (DomLocation.Empty, result.Location);
- Assert.AreEqual (Modifiers.None, result.Modifiers);
- Assert.AreEqual (null, result.ReturnType);
- }
-
- [Test()]
- public void ReadWriteReturnTypeTest ()
- {
- DomReturnType input = new DomReturnType ();
- input.Name = "Test";
- input.Namespace = "Namespace";
- input.ArrayDimensions = 5;
- input.IsByRef = true;
- input.IsNullable = true;
- input.PointerNestingLevel = 666;
- input.AddTypeParameter (new DomReturnType ("System.String"));
- input.AddTypeParameter (new DomReturnType ("System.Int32"));
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- IReturnType result = DomPersistence.ReadReturnType (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("Test", result.Name);
- Assert.AreEqual ("Namespace", result.Namespace);
- Assert.AreEqual ("Namespace.Test", result.FullName);
- Assert.AreEqual (5, result.ArrayDimensions);
- Assert.AreEqual (true, result.IsByRef);
- Assert.AreEqual (true, result.IsNullable);
- Assert.AreEqual ("System.String", result.GenericArguments[0].FullName);
- Assert.AreEqual ("System.Int32", result.GenericArguments[1].FullName);
- }
-
- [Test()]
- public void ReadWriteMethodTest ()
- {
- DomMethod input = new DomMethod ();
- input.Name = "Test";
- input.MethodModifier = MethodModifier.IsConstructor;
- input.Add (new DomParameter (input, "par1", DomReturnType.Void));
- input.AddTypeParameter (new TypeParameter ("T"));
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomMethod result = DomPersistence.ReadMethod (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("Test", result.Name);
- Assert.AreEqual (true, result.IsConstructor);
- Assert.AreEqual ("par1", result.Parameters [0].Name);
- Assert.AreEqual ("Void", result.Parameters [0].ReturnType.Name);
- Assert.AreEqual (1, result.TypeParameters.Count);
- Assert.AreEqual ("T", result.TypeParameters [0].Name);
- }
-
- [Test()]
- public void ReadWriteDelegateTest ()
- {
- DomType input = DomType.CreateDelegate (null, "TestDelegate", new DomLocation (10, 10), DomReturnType.Void, new List<IParameter> ());
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomType result = DomPersistence.ReadType (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("TestDelegate", result.Name);
- Assert.AreEqual (ClassType.Delegate, result.ClassType);
- }
-
- [Test()]
- public void ReadWritePropertyTest ()
- {
- DomProperty input = new DomProperty ();
- input.Name = "Test";
- input.PropertyModifier = PropertyModifier.IsIndexer | PropertyModifier.HasGet | PropertyModifier.HasSet;
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomProperty result = DomPersistence.ReadProperty (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("Test", result.Name);
- Assert.AreEqual (true, result.IsIndexer);
- Assert.AreEqual (true, result.HasGet);
- Assert.AreEqual (true, result.HasSet);
- }
-
- [Test()]
- public void ReadWriteEventTest ()
- {
- DomEvent input = new DomEvent ();
- input.Name = "Test";
- input.AddMethod = new DomMethod ("AddMethod", Modifiers.New, MethodModifier.None, DomLocation.Empty, DomRegion.Empty);
- input.RemoveMethod = new DomMethod ("RemoveMethod", Modifiers.New, MethodModifier.None, DomLocation.Empty, DomRegion.Empty);
- input.RaiseMethod = new DomMethod ("RaiseMethod", Modifiers.New, MethodModifier.None, DomLocation.Empty, DomRegion.Empty);
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomEvent result = DomPersistence.ReadEvent (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("Test", result.Name);
- Assert.AreEqual ("AddMethod", result.AddMethod.Name);
- Assert.AreEqual ("RemoveMethod", result.RemoveMethod.Name);
- Assert.AreEqual ("RaiseMethod", result.RaiseMethod.Name);
- }
-
- [Test()]
- public void ReadWriteTypeTest ()
- {
- DomType input = new DomType ();
- input.Name = "Test";
- input.ClassType = ClassType.Struct;
- input.BaseType = new DomReturnType ("BaseClass");
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomType result = DomPersistence.ReadType (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("Test", result.Name);
- Assert.AreEqual (ClassType.Struct, result.ClassType);
- Assert.AreEqual ("BaseClass", result.BaseType.Name);
- }
-
- [Test()]
- public void ReadWriteTypeTestComplex ()
- {
- DomType input = new DomType ();
-
- input.Name = "Test";
- input.ClassType = ClassType.Struct;
- input.BaseType = new DomReturnType ("BaseClass");
- input.AddInterfaceImplementation (new DomReturnType ("Interface1"));
- input.AddInterfaceImplementation (new DomReturnType ("Interface2"));
-
- input.Add (new DomMethod ("TestMethod", Modifiers.None, MethodModifier.None, DomLocation.Empty, DomRegion.Empty));
- input.Add (new DomMethod (".ctor", Modifiers.None, MethodModifier.IsConstructor, DomLocation.Empty, DomRegion.Empty));
-
- input.Add (new DomField ("TestField", Modifiers.None, DomLocation.Empty, DomReturnType.Void));
- input.Add (new DomProperty ("TestProperty", Modifiers.None, DomLocation.Empty, DomRegion.Empty, DomReturnType.Void));
- input.Add (new DomEvent ("TestEvent", Modifiers.None, DomLocation.Empty, DomReturnType.Void));
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, input);
- byte[] bytes = ms.ToArray ();
-
- DomType result = DomPersistence.ReadType (CreateReader (bytes), DefaultNameDecoder, null);
- Assert.AreEqual ("Test", result.Name);
- Assert.AreEqual (ClassType.Struct, result.ClassType);
- Assert.AreEqual ("BaseClass", result.BaseType.Name);
- Assert.AreEqual (1, result.MethodCount);
- Assert.AreEqual (1, result.ConstructorCount);
- Assert.AreEqual (1, result.FieldCount);
- Assert.AreEqual (1, result.PropertyCount);
- Assert.AreEqual (1, result.EventCount);
-
- }
-
- [Test()]
- public void ReadWriteAttributeTest ()
- {
- DomAttribute attr = new DomAttribute ();
-
- CodePropertyReferenceExpression exp1 = new CodePropertyReferenceExpression ();
- exp1.TargetObject = new CodeTypeReferenceExpression ("SomeType");
- exp1.PropertyName = "SomeProperty";
-
- CodeTypeOfExpression exp2 = new CodeTypeOfExpression ("SomeTypeOf");
-
- CodeBinaryOperatorExpression exp3 = new CodeBinaryOperatorExpression ();
- exp3.Left = new CodePrimitiveExpression ("one");
- exp3.Right = new CodePrimitiveExpression ("two");
- exp3.Operator = CodeBinaryOperatorType.Add;
-
- CodePrimitiveExpression exp4 = new CodePrimitiveExpression (37);
-
- attr.AddPositionalArgument (exp1);
- attr.AddPositionalArgument (exp2);
- attr.AddPositionalArgument (exp3);
- attr.AddPositionalArgument (exp4);
-
- MemoryStream ms = new MemoryStream ();
- BinaryWriter writer = new BinaryWriter (ms);
- DomPersistence.Write (writer, DefaultNameEncoder, attr);
- byte[] bytes = ms.ToArray ();
- DomAttribute result = DomPersistence.ReadAttribute (CreateReader (bytes), DefaultNameDecoder, null);
-
- Assert.AreEqual (4, result.PositionalArguments.Count);
-
- Assert.AreEqual (typeof(CodePropertyReferenceExpression), result.PositionalArguments [0].GetType ());
- CodePropertyReferenceExpression rexp1 = (CodePropertyReferenceExpression) result.PositionalArguments [0];
- Assert.AreEqual (typeof(CodeTypeReferenceExpression), rexp1.TargetObject.GetType ());
- Assert.AreEqual ("SomeType", ((CodeTypeReferenceExpression)rexp1.TargetObject).Type.BaseType);
- Assert.AreEqual ("SomeProperty", rexp1.PropertyName);
-
- Assert.AreEqual (typeof(CodeTypeOfExpression), result.PositionalArguments [1].GetType ());
- Assert.AreEqual ("SomeTypeOf", ((CodeTypeOfExpression)result.PositionalArguments [1]).Type.BaseType);
-
- Assert.AreEqual (typeof(CodeBinaryOperatorExpression), result.PositionalArguments [2].GetType ());
- CodeBinaryOperatorExpression rexp3 = (CodeBinaryOperatorExpression) result.PositionalArguments [2];
- Assert.AreEqual (typeof(CodePrimitiveExpression), rexp3.Left.GetType ());
- Assert.AreEqual ("one", ((CodePrimitiveExpression)rexp3.Left).Value);
- Assert.AreEqual (typeof(CodePrimitiveExpression), rexp3.Right.GetType ());
- Assert.AreEqual ("two", ((CodePrimitiveExpression)rexp3.Right).Value);
-
- Assert.AreEqual (typeof(CodePrimitiveExpression), result.PositionalArguments [3].GetType ());
- Assert.AreEqual (37, ((CodePrimitiveExpression)result.PositionalArguments [3]).Value);
- }
-
- static BinaryReader CreateReader (byte[] bytes)
- {
- return new BinaryReader (new MemoryStream (bytes));
- }
-
-// Doesn't work: ?
-// byte[] Write<T> (T input)
-// {
-// MemoryStream ms = new MemoryStream ();
-// BinaryWriter writer = new BinaryWriter (ms);
-// DomPersistence.Write (writer, null, input);
-// return ms.ToArray ();
-// }
-
-
- static StringNameTable DefaultNameEncoder;
- static StringNameTable DefaultNameDecoder;
-
- static DomPersistenceTests ()
- {
- DefaultNameEncoder = new StringNameTable (sharedNameTable);
- DefaultNameDecoder = new StringNameTable (sharedNameTable);
- }
-
- static readonly string[] sharedNameTable = new string[] {
- "", // 505195
- "System.Void", // 116020
- "To be added", // 78598
- "System.Int32", // 72669
- "System.String", // 72097
- "System.Object", // 48530
- "System.Boolean", // 46200
- ".ctor", // 39938
- "System.IntPtr", // 35184
- "To be added.", // 19082
- "value", // 11906
- "System.Byte", // 8524
- "To be added: an object of type 'string'", // 7928
- "e", // 7858
- "raw", // 7830
- "System.IAsyncResult", // 7760
- "System.Type", // 7518
- "name", // 7188
- "object", // 6982
- "System.UInt32", // 6966
- "index", // 6038
- "To be added: an object of type 'int'", // 5196
- "System.Int64", // 4166
- "callback", // 4158
- "System.EventArgs", // 4140
- "method", // 4030
- "System.Enum", // 3980
- "value__", // 3954
- "Invoke", // 3906
- "result", // 3856
- "System.AsyncCallback", // 3850
- "System.MulticastDelegate", // 3698
- "BeginInvoke", // 3650
- "EndInvoke", // 3562
- "node", // 3416
- "sender", // 3398
- "context", // 3310
- "System.EventHandler", // 3218
- "System.Double", // 3206
- "type", // 3094
- "x", // 3056
- "System.Single", // 2940
- "data", // 2930
- "args", // 2926
- "System.Char", // 2813
- "Gdk.Key", // 2684
- "ToString", // 2634
- "'a", // 2594
- "System.Drawing.Color", // 2550
- "y", // 2458
- "To be added: an object of type 'object'", // 2430
- "System.DateTime", // 2420
- "message", // 2352
- "GLib.GType", // 2292
- "o", // 2280
- "a <see cref=\"T:System.Int32\" />", // 2176
- "path", // 2062
- "obj", // 2018
- "Nemerle.Core.list`1", // 1950
- "System.Windows.Forms", // 1942
- "System.Collections.ArrayList", // 1918
- "a <see cref=\"T:System.String\" />", // 1894
- "key", // 1868
- "Add", // 1864
- "arg0", // 1796
- "System.IO.Stream", // 1794
- "s", // 1784
- "arg1", // 1742
- "provider", // 1704
- "System.UInt64", // 1700
- "System.Drawing.Rectangle", // 1684
- "System.IFormatProvider", // 1684
- "gch", // 1680
- "System.Exception", // 1652
- "Equals", // 1590
- "System.Drawing.Pen", // 1584
- "count", // 1548
- "System.Collections.IEnumerator", // 1546
- "info", // 1526
- "Name", // 1512
- "System.Attribute", // 1494
- "gtype", // 1470
- "To be added: an object of type 'Type'", // 1444
- "System.Collections.Hashtable", // 1416
- "array", // 1380
- "System.Int16", // 1374
- "Gtk", // 1350
- "System.ComponentModel.ITypeDescriptorContext", // 1344
- "System.Collections.ICollection", // 1330
- "Dispose", // 1330
- "Gtk.Widget", // 1326
- "System.Runtime.Serialization.StreamingContext", // 1318
- "Nemerle.Compiler.Parsetree.PExpr", // 1312
- "System.Guid", // 1310
- "i", // 1302
- "Gtk.TreeIter", // 1300
- "text", // 1290
- "System.Runtime.Serialization.SerializationInfo", // 1272
- "state", // 1264
- "Remove" // 1256
- };
- }
-}
diff --git a/main/tests/UnitTests/MonoDevelop.Projects/DomTests.cs b/main/tests/UnitTests/MonoDevelop.Projects/DomTests.cs
deleted file mode 100644
index 29760a7a29..0000000000
--- a/main/tests/UnitTests/MonoDevelop.Projects/DomTests.cs
+++ /dev/null
@@ -1,228 +0,0 @@
-//
-// DomTests.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.IO;
-using NUnit.Framework;
-using MonoDevelop.Projects.Dom;
-using MonoDevelop.Projects.Dom.Serialization;
-using MonoDevelop.Projects.Dom.Parser;
-using MonoDevelop.Core.Assemblies;
-
-namespace MonoDevelop.Projects.DomTests
-{
- [TestFixture()]
- public class DomTests : UnitTests.TestBase
- {
- [Test()]
- public void InstantiatedMethodByArgumentTest ()
- {
- // build "T MyMethod<T> (T a)"
- DomMethod method = new DomMethod ();
- method.Name = "MyMethod";
- method.ReturnType = new DomReturnType ("T");
- method.AddTypeParameter (new TypeParameter ("T"));
- method.Add (new DomParameter (method, "a", new DomReturnType ("T")));
-
- // give int as param type
- List<IReturnType> genArgs = new List<IReturnType> ();
- List<IReturnType> args = new List<IReturnType> ();
- args.Add (DomReturnType.Int32);
- IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
-
- // check
- Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
- Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.Parameters[0].ReturnType.FullName);
- }
-
- [Test()]
- public void InstantiatedMethodByParameterTest ()
- {
- // build "T MyMethod<T> (T[] a)"
- DomMethod method = new DomMethod ();
- method.Name = "MyMethod";
- method.ReturnType = new DomReturnType ("T");
- method.AddTypeParameter (new TypeParameter ("T"));
- DomReturnType returnType = new DomReturnType ("T");
- returnType.ArrayDimensions = 1;
- method.Add (new DomParameter (method, "a", returnType));
-
- // give int[] as param type.
- List<IReturnType> genArgs = new List<IReturnType> ();
- List<IReturnType> args = new List<IReturnType> ();
- returnType = new DomReturnType (DomReturnType.Int32.FullName);
- returnType.ArrayDimensions = 1;
- args.Add (returnType);
-
- IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
-
- // check (note that return type should be int and not int[])
- Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
- Assert.AreEqual (0, instMethod.ReturnType.ArrayDimensions);
- Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.Parameters[0].ReturnType.FullName);
- }
-
- [Test()]
- public void InstantiatedMethodByArgumentTest_Complex ()
- {
- // build "T MyMethod<T,S> (S b, KeyValuePair<S, T> a)"
- DomMethod method = new DomMethod ();
- method.Name = "MyMethod";
- method.ReturnType = new DomReturnType ("T");
- method.AddTypeParameter (new TypeParameter ("T"));
- method.AddTypeParameter (new TypeParameter ("S"));
- method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
-
- DomReturnType returnType = new DomReturnType ("KeyValuePair");
- returnType.AddTypeParameter (new DomReturnType ("T"));
- returnType.AddTypeParameter (new DomReturnType ("S"));
- method.Add (new DomParameter (method, "a", returnType));
-
- // give int, object as param type
- List<IReturnType> genArgs = new List<IReturnType> ();
- List<IReturnType> args = new List<IReturnType> ();
- genArgs.Add (DomReturnType.Int32);
- genArgs.Add (DomReturnType.Object);
-
- IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
-
- // check
- Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
- Assert.AreEqual (DomReturnType.Object.FullName, instMethod.Parameters[0].ReturnType.FullName);
-
- Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[0].FullName);
- Assert.AreEqual (DomReturnType.Object.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[1].FullName);
- }
-
- [Test()]
- public void ExtensionMethodTest ()
- {
- // build "T MyMethod<T, S> (this KeyValuePair<T, S> a, S b)"
- DomMethod method = new DomMethod ();
- method.Name = "MyMethod";
- method.ReturnType = new DomReturnType ("T");
- method.AddTypeParameter (new TypeParameter ("T"));
- method.AddTypeParameter (new TypeParameter ("S"));
-
- DomReturnType returnType = new DomReturnType ("KeyValuePair");
- returnType.AddTypeParameter (new DomReturnType ("T"));
- returnType.AddTypeParameter (new DomReturnType ("S"));
- method.Add (new DomParameter (method, "a", returnType));
- method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
-
- // Build extendet type KeyValuePair<int, object>
- DomType type = new DomType ("KeyValuePair");
- type.AddTypeParameter (new TypeParameter ("T"));
- type.AddTypeParameter (new TypeParameter ("S"));
- IType extType = DomType.CreateInstantiatedGenericTypeInternal (type, new IReturnType[] { DomReturnType.Int32, DomReturnType.Object });
- Console.WriteLine (extType);
-
- // extend method
- List<IReturnType> genArgs = new List<IReturnType> ();
- List<IReturnType> args = new List<IReturnType> ();
-
- ExtensionMethod extMethod = new ExtensionMethod (extType, method, genArgs, args);
-
- Console.WriteLine (extMethod);
- // check
- Assert.AreEqual (DomReturnType.Int32.FullName, extMethod.ReturnType.FullName);
- Assert.AreEqual (DomReturnType.Object.FullName, extMethod.Parameters[0].ReturnType.FullName);
- }
-
-
- [Test()]
- public void ExtensionMethodPreserveParameterTest ()
- {
- // build "T MyMethod<T, S> (T a, S b)"
- DomMethod method = new DomMethod ();
- method.Name = "MyMethod";
- method.ReturnType = new DomReturnType ("T");
- method.AddTypeParameter (new TypeParameter ("T"));
- method.AddTypeParameter (new TypeParameter ("S"));
-
- method.Add (new DomParameter (method, "a", new DomReturnType ("T")));
- method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
-
- // extend method
- List<IReturnType> genArgs = new List<IReturnType> ();
- List<IReturnType> args = new List<IReturnType> ();
- DomType extType = new DomType ("MyType");
-
- ExtensionMethod extMethod = new ExtensionMethod (extType, method, genArgs, args);
-
- // check for MyType MyMethod<S> (S b)
- Assert.AreEqual ("MyType", extMethod.ReturnType.FullName);
- Assert.AreEqual ("S", extMethod.Parameters[0].ReturnType.FullName);
- Assert.AreEqual (1, extMethod.TypeParameters.Count);
- Assert.AreEqual ("S", extMethod.TypeParameters[0].Name);
- }
-
- [Test()]
- public void InstantiatedMethodByArgumentTestComplex2 ()
- {
- // build "T MyMethod<T> (MyType<T> a)"
- DomMethod method = new DomMethod ();
- method.Name = "MyMethod";
- method.ReturnType = new DomReturnType ("T");
- method.AddTypeParameter (new TypeParameter ("T"));
-
- DomReturnType returnType = new DomReturnType ("MyType");
- returnType.AddTypeParameter (new DomReturnType ("T"));
- method.Add (new DomParameter (method, "a", returnType));
-
- // give int as param type
- List<IReturnType> genArgs = new List<IReturnType> ();
- List<IReturnType> args = new List<IReturnType> ();
- returnType = new DomReturnType ("MyType");
- returnType.AddTypeParameter (DomReturnType.Int32);
- args.Add (returnType);
- IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
-
- // check
- Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
- }
-
- [Test()]
- public void ParseAssemblyUriTests ()
- {
- TargetRuntime runtime;
- TargetFramework fx;
- string file;
- ProjectDomService.ParseAssemblyUri ("Assembly:Mono 2.4.2.3:/usr/lib/mono/2.0/mscorlib.dll", out runtime, out fx, out file);
- Assert.AreEqual ("/usr/lib/mono/2.0/mscorlib.dll", file);
-
- ProjectDomService.ParseAssemblyUri ("Assembly:MS.NET:C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\mscorlib.dll", out runtime, out fx, out file);
- Assert.AreEqual ("C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\mscorlib.dll", file);
-
- ProjectDomService.ParseAssemblyUri ("Assembly:Mono r142024 Wed Sep 16 11:39:25 BST 2009:/usr/local/lib/mono/2.0/mscorlib.dll", out runtime, out fx, out file);
- Assert.AreEqual ("/usr/local/lib/mono/2.0/mscorlib.dll", file);
-
-
- }
-
- }
-}
diff --git a/main/tests/UnitTests/MonoDevelop.Projects/SolutionTests.cs b/main/tests/UnitTests/MonoDevelop.Projects/SolutionTests.cs
index 4b288fe6f4..512f93ebb9 100644
--- a/main/tests/UnitTests/MonoDevelop.Projects/SolutionTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.Projects/SolutionTests.cs
@@ -391,7 +391,7 @@ namespace MonoDevelop.Projects
SolutionConfigurationSelector config = (SolutionConfigurationSelector) "Debug";
- Assert.IsTrue (p.NeedsBuilding (config));
+ Assert.IsTrue (p. NeedsBuilding (config));
Assert.IsTrue (lib1.NeedsBuilding (config));
Assert.IsTrue (lib2.NeedsBuilding (config));
diff --git a/main/tests/UnitTests/MonoDevelop.SourceEditor/DebugTooltipTests.cs b/main/tests/UnitTests/MonoDevelop.SourceEditor/DebugTooltipTests.cs
index 683df8fe39..f84bdc2d0a 100644
--- a/main/tests/UnitTests/MonoDevelop.SourceEditor/DebugTooltipTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.SourceEditor/DebugTooltipTests.cs
@@ -28,7 +28,6 @@ using NUnit.Framework;
using Mono.TextEditor;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
-using MonoDevelop.CSharp.Resolver;
using MonoDevelop.CSharpBinding;
using MonoDevelop.CSharpBinding.Tests;
using MonoDevelop.CSharp.Completion;
@@ -37,37 +36,62 @@ using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.CSharp.Resolver;
using MonoDevelop.CSharp;
+using MonoDevelop.Projects;
+using MonoDevelop.Core.ProgressMonitoring;
+using MonoDevelop.Ide.TypeSystem;
+using MonoDevelop.Debugger;
+using UnitTests;
namespace MonoDevelop.SourceEditor
{
[TestFixture]
- public class DebugTooltipTests
+ public class DebugTooltipTests : TestBase
{
Document document;
string content;
+ MonoDevelop.Projects.Solution solution;
- static Document CreateDocument (string input)
+ Document CreateDocument (string input)
{
- var tww = new TestWorkbenchWindow ();
- var content = new TestViewContent ();
- tww.ViewContent = content;
- content.ContentName = "a.cs";
- content.GetTextEditorData ().Document.MimeType = "text/x-csharp";
- var doc = new Document (tww);
-
var text = input;
int endPos = text.IndexOf ('$');
if (endPos >= 0)
text = text.Substring (0, endPos) + text.Substring (endPos + 1);
+ var project = new DotNetAssemblyProject (Microsoft.CodeAnalysis.LanguageNames.CSharp);
+ project.Name = "test";
+ project.References.Add (new MonoDevelop.Projects.ProjectReference (ReferenceType.Package, "mscorlib"));
+ project.References.Add (new MonoDevelop.Projects.ProjectReference (ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
+ project.References.Add (new MonoDevelop.Projects.ProjectReference (ReferenceType.Package, "System.Core"));
+
+ project.FileName = "test.csproj";
+ project.Files.Add (new ProjectFile ("/a.cs", BuildAction.Compile));
+
+ solution = new MonoDevelop.Projects.Solution ();
+ var config = solution.AddConfiguration ("", true);
+ solution.DefaultSolutionFolder.AddItem (project);
+ using (var monitor = new NullProgressMonitor ())
+ TypeSystemService.Load (solution, monitor, false);
+
+ var tww = new TestWorkbenchWindow ();
+ var content = new TestViewContent ();
+ tww.ViewContent = content;
+ content.ContentName = "/a.cs";
+ content.Data.MimeType = "text/x-csharp";
+ content.Project = project;
+
+
content.Text = text;
content.CursorPosition = Math.Max (0, endPos);
+ var doc = new Document (tww);
+ doc.SetProject (project);
var compExt = new CSharpCompletionTextEditorExtension ();
- compExt.Initialize (doc);
+ compExt.Initialize (doc.Editor, doc);
content.Contents.Add (compExt);
doc.UpdateParseDocument ();
+
return doc;
}
@@ -177,18 +201,19 @@ namespace DebuggerTooltipTests
document = CreateDocument (content);
}
+ public override void TearDown()
+ {
+ TypeSystemService.Unload (solution);
+ base.TearDown ();
+ }
+
static string ResolveExpression (Document doc, string content, int offset)
{
var editor = doc.Editor;
- ResolveResult result;
- int startOffset;
- AstNode node;
-
var loc = editor.OffsetToLocation (offset);
- if (!doc.TryResolveAt (loc, out result, out node))
- return null;
+ var resolver = doc.GetContent<IDebuggerExpressionResolver> ();
- return CSharpCompletionTextEditorExtension.ResolveExpression (doc.Editor, result, node, out startOffset);
+ return resolver.ResolveExpressionAsync (editor, doc, offset, default(System.Threading.CancellationToken)).Result.Text;
}
int GetBasicOffset (string expr)
@@ -264,15 +289,15 @@ namespace DebuggerTooltipTests
public void TestFieldDeclarations ()
{
Assert.AreEqual ("DebuggerTooltipTests.Abc.StaticField", ResolveExpression (document, content, GetBasicOffset ("StaticField")));
- Assert.AreEqual ("this.@double", ResolveExpression (document, content, GetBasicOffset ("@double")));
- Assert.AreEqual ("this.field", ResolveExpression (document, content, GetBasicOffset ("field")));
+ Assert.AreEqual ("@double", ResolveExpression (document, content, GetBasicOffset ("@double")));
+ Assert.AreEqual ("field", ResolveExpression (document, content, GetBasicOffset ("field")));
}
[Test]
public void TestPropertyDeclarations ()
{
Assert.AreEqual ("DebuggerTooltipTests.Abc.StaticProperty", ResolveExpression (document, content, GetBasicOffset ("StaticProperty")));
- Assert.AreEqual ("this.Text", ResolveExpression (document, content, GetBasicOffset ("Text")));
+ Assert.AreEqual ("Text", ResolveExpression (document, content, GetBasicOffset ("Text")));
}
[Test]
diff --git a/main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs b/main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs
index ac7b5d0d40..a0b75b1cd6 100644
--- a/main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs
@@ -25,18 +25,20 @@
// THE SOFTWARE.
using System;
using NUnit.Framework;
-using MonoDevelop.Ide.CodeCompletion;
-using ICSharpCode.NRefactory.CSharp;
using System.Text;
-using ICSharpCode.NRefactory.Editor;
-using MonoDevelop.SourceEditor.JSon;
-using Mono.TextEditor;
+using MonoDevelop.JSon;
+using UnitTests;
+using ICSharpCode.NRefactory6.CSharp;
+using MonoDevelop.CSharpBinding;
+using MonoDevelop.CSharpBinding.Tests;
namespace MonoDevelop.SourceEditor
{
[TestFixture]
- public class JSonIndentEngineTests
+ public class JSonIndentEngineTests : TestBase
{
+ const string indentString = " ";
+
public static IDocumentIndentEngine CreateEngine (string text)
{
var sb = new StringBuilder ();
@@ -50,11 +52,18 @@ namespace MonoDevelop.SourceEditor
sb.Append (ch);
}
- var data = new TextEditorData ();
- data.Text = sb.ToString ();
- var csi = new JSonIndentEngine (data);
+ var tww = new TestWorkbenchWindow ();
+ var content = new TestViewContent ();
+ tww.ViewContent = content;
+ content.ContentName = "/a.json";
+ content.Data.MimeType = "application/json";
+
+ content.Data.Text = sb.ToString ();
+ var doc = new MonoDevelop.Ide.Gui.Document (tww);
+
+ var csi = new JSonIndentEngine (content.Data, doc);
var result = new CacheIndentEngine (csi);
- result.Update (offset);
+ result.Update (content.Data, offset);
return result;
}
@@ -66,8 +75,8 @@ namespace MonoDevelop.SourceEditor
{
$
");
- Assert.AreEqual ("\t", engine.ThisLineIndent);
- Assert.AreEqual ("\t", engine.NextLineIndent);
+ Assert.AreEqual (indentString, engine.ThisLineIndent);
+ Assert.AreEqual (indentString, engine.NextLineIndent);
}
[Test]
@@ -79,8 +88,8 @@ $
""foo"":""bar"",
$
");
- Assert.AreEqual ("\t", engine.ThisLineIndent);
- Assert.AreEqual ("\t", engine.NextLineIndent);
+ Assert.AreEqual (indentString, engine.ThisLineIndent);
+ Assert.AreEqual (indentString, engine.NextLineIndent);
}
[Test]
@@ -92,16 +101,16 @@ $
""test"":[
$
");
- Assert.AreEqual ("\t\t", engine.ThisLineIndent);
- Assert.AreEqual ("\t\t", engine.NextLineIndent);
+ Assert.AreEqual (indentString + indentString, engine.ThisLineIndent);
+ Assert.AreEqual (indentString + indentString, engine.NextLineIndent);
}
[Test]
public void TestWindowsEOL ()
{
var engine = CreateEngine ("\r\n{\r\n$\r\n");
- Assert.AreEqual ("\t", engine.ThisLineIndent);
- Assert.AreEqual ("\t", engine.NextLineIndent);
+ Assert.AreEqual (indentString, engine.ThisLineIndent);
+ Assert.AreEqual (indentString, engine.NextLineIndent);
}
}
}
diff --git a/main/tests/UnitTests/TestBase.cs b/main/tests/UnitTests/TestBase.cs
index 50d9e04926..6770a3133a 100644
--- a/main/tests/UnitTests/TestBase.cs
+++ b/main/tests/UnitTests/TestBase.cs
@@ -42,7 +42,7 @@ namespace UnitTests
[TestFixtureSetUp]
- public virtual void Setup ()
+ public void Simulate ()
{
if (firstRun) {
string rootDir = Path.Combine (Util.TestsRootDir, "config");
@@ -62,12 +62,13 @@ namespace UnitTests
}
}
- static void InternalSetup (string rootDir)
+ protected virtual void InternalSetup (string rootDir)
{
Util.ClearTmpDir ();
Environment.SetEnvironmentVariable ("MONO_ADDINS_REGISTRY", rootDir);
Environment.SetEnvironmentVariable ("XDG_CONFIG_HOME", rootDir);
Runtime.Initialize (true);
+ Xwt.Application.Initialize ();
Gtk.Application.Init ();
TypeSystemService.TrackFileChanges = true;
DesktopService.Initialize ();
diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj
index b9b03e3275..99c65bfb52 100644
--- a/main/tests/UnitTests/UnitTests.csproj
+++ b/main/tests/UnitTests/UnitTests.csproj
@@ -62,6 +62,24 @@
<HintPath>..\..\external\guiunit\bin\net_4_0\GuiUnit.exe</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Collections.Immutable">
+ <HintPath>..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reflection.Metadata">
+ <HintPath>..\..\packages\System.Reflection.Metadata.1.0.18-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.CodeAnalysis">
+ <HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.CodeAnalysis.Desktop">
+ <HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.CodeAnalysis.Workspaces">
+ <HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop">
+ <HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\core\MonoDevelop.Core\MonoDevelop.Core.csproj">
@@ -203,6 +221,11 @@
<Project>{A7A4246D-CEC4-42DF-A3C1-C31B9F51C4EC}</Project>
<Name>MonoDevelop.NUnit</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\external\NRefactory6\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory6.CSharp.csproj">
+ <Project>{7E891659-45F3-42B5-B940-A728780CCAE9}</Project>
+ <Name>ICSharpCode.NRefactory6.CSharp</Name>
+ <Private>False</Private>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Util.cs" />
@@ -220,17 +243,12 @@
<Compile Include="MonoDevelop.VersionControl.Views\EditorCompareWidgetBaseTest.cs" />
<Compile Include="MonoDevelop.CSharpBinding\TestWorkbenchWindow.cs" />
<Compile Include="MonoDevelop.CSharpBinding\TestViewContent.cs" />
- <Compile Include="MonoDevelop.CSharpBinding\MemberTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding\FindMemberVisitorTests.cs" />
- <Compile Include="MonoDevelop.CSharpBinding\ProjectDomTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding\TestDocument.cs" />
<Compile Include="MonoDevelop.CSharpBinding\FoldingParserTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding\CSharpTextEditorIndentationTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding\OnTheFlyFormatterTests.cs" />
<Compile Include="MonoDevelop.Ide.Gui\CompletionListWindowTests.cs" />
- <Compile Include="MonoDevelop.CSharpBinding.Refactoring\ResolveNamespaceTests.cs" />
- <Compile Include="MonoDevelop.Ide.FindInFiles\MemberCollectorTests.cs" />
- <Compile Include="MonoDevelop.Ide.FindInFiles\SearchCollectorTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding.Refactoring\GenerateNewMemberTests.cs" />
<Compile Include="MonoDevelop.SourceEditor\SourceEditorTests.cs" />
<Compile Include="MonoDevelop.Projects\FileServiceTests.cs" />
@@ -238,20 +256,10 @@
<Compile Include="MonoDevelop.Core\BacktrackingStringMatcherTests.cs" />
<Compile Include="MonoDevelop.Ide.Gui\SearchPopupWindowTests.cs" />
<Compile Include="MonoDevelop.Core\LaneStringMatcherTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\IssueGroupTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\MockGroupingProvider.cs" />
- <Compile Include="MonoDevelop.Refactoring\GroupingProviderTestBase.cs" />
- <Compile Include="MonoDevelop.Refactoring\CategoryGroupingProviderTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\ProviderGroupingProviderTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\SeverityGroupingProviderTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding\AutomaticBracketInsertionTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding\NamedArgumentCompletionTests.cs" />
<Compile Include="MonoDevelop.SourceEditor\DebugTooltipTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding\UnitTesteditorIntegrationTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\AnalysisJobQueueTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\SimpleAnalysisJobTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\ProjectGroupingProviderTests.cs" />
- <Compile Include="MonoDevelop.Refactoring\FileGroupingProviderTests.cs" />
<Compile Include="MonoDevelop.Ide.Gui\LogViewTests.cs" />
<Compile Include="MonoDevelop.SourceEditor\JSonIndentEngineTests.cs" />
<Compile Include="MonoDevelop.Projects\SharedAssetsProjectTests.cs" />
@@ -271,19 +279,43 @@
<Compile Include="MonoDevelop.Ide.Templates\FileTemplateParserTests.cs" />
<Compile Include="MonoDevelop.Ide.Templates\ProjectCreateInformationTests.cs" />
<Compile Include="MonoDevelop.Projects\PolicyTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\TextSourceTestBase.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\ReadonlyTextDocumentTestBase.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\TextDocumentTestBase.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\Tests\StringTextSource_Tests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\TextEditorTestBase.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\Tests\SimpleReadonlyDocument_Tests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\Tests\MonoTextEditorImplementationTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\Commands\CodeCommentTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\TextEditorProjectionTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\SimpleBracketMatcherTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\Commands\SortSelectedLinesTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\md.targets" />
<ItemGroup>
<None Include="Makefile.am" />
- <None Include="MonoDevelop.Projects\CompletionDatabaseTests.cs" />
- <None Include="MonoDevelop.Projects\DomPersistenceTests.cs" />
- <None Include="MonoDevelop.Projects\DomCompilationUnitTests.cs" />
- <None Include="MonoDevelop.Projects\DomTests.cs" />
+ <None Include="MonoDevelop.AspNet\AspNetCompletionTests.cs" />
+ <None Include="MonoDevelop.AspNet\AspNetTesting.cs" />
+ <None Include="MonoDevelop.Refactoring\IssueGroupTests.cs" />
+ <None Include="MonoDevelop.Refactoring\MockGroupingProvider.cs" />
+ <None Include="MonoDevelop.Refactoring\GroupingProviderTestBase.cs" />
+ <None Include="MonoDevelop.Refactoring\CategoryGroupingProviderTests.cs" />
+ <None Include="MonoDevelop.Refactoring\ProviderGroupingProviderTests.cs" />
+ <None Include="MonoDevelop.Refactoring\SeverityGroupingProviderTests.cs" />
+ <None Include="MonoDevelop.Refactoring\AnalysisJobQueueTests.cs" />
+ <None Include="MonoDevelop.Refactoring\SimpleAnalysisJobTests.cs" />
+ <None Include="MonoDevelop.Refactoring\ProjectGroupingProviderTests.cs" />
+ <None Include="MonoDevelop.Refactoring\FileGroupingProviderTests.cs" />
+ <None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="MonoDevelop.Refactoring\" />
+ <Folder Include="MonoDevelop.Xml.StateEngine\" />
<Folder Include="MonoDevelop.Ide.Templates\" />
+ <Folder Include="MonoDevelop.Ide.Editor\" />
+ <Folder Include="MonoDevelop.Ide.Editor\Tests\" />
+ <Folder Include="MonoDevelop.Ide.Editor\Commands\" />
</ItemGroup>
</Project>
diff --git a/main/tests/UnitTests/packages.config b/main/tests/UnitTests/packages.config
new file mode 100644
index 0000000000..f8f771207f
--- /dev/null
+++ b/main/tests/UnitTests/packages.config
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.CodeAnalysis.Common" version="1.0.0-rc1" targetFramework="net45" />
+ <package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0-rc1" targetFramework="net45" />
+ <package id="System.Collections.Immutable" version="1.1.33-beta" targetFramework="net45" />
+ <package id="System.Reflection.Metadata" version="1.0.18-beta" targetFramework="net45" />
+</packages> \ No newline at end of file