diff options
Diffstat (limited to 'main/tests/UnitTests/MonoDevelop.Ide.FindInFiles')
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs | 129 | ||||
-rwxr-xr-x | main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs | 6 |
2 files changed, 69 insertions, 66 deletions
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs index 0100ae6584..2b86670596 100644 --- a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs +++ b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/MemberCollectorTests.cs @@ -28,7 +28,7 @@ using System.Linq; using System.Collections.Generic; using NUnit.Framework; using MonoDevelop.Projects; -using ICSharpCode.NRefactory.TypeSystem;
+using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp.TypeSystem; @@ -42,44 +42,46 @@ namespace MonoDevelop.Ide.FindInFiles { IAssembly GenerateAssembly(Project project, string code) { - project.Files.Add (new ProjectFile ("test.cs", BuildAction.Compile)); var wrapper = TypeSystemService.LoadProject (project); TypeSystemService.ParseFile ("test.cs", "text/x-csharp", code, wrapper); wrapper.RequestLoad (); do { System.Threading.Thread.Sleep (10); - } while (wrapper.InLoad); - return wrapper.Compilation.MainAssembly; - }
-
- List<IMember> CollectMembers (string code, string typeName, Predicate<IUnresolvedMember> filter1, Predicate<IMember> filter2,
- bool includeOverloads, bool matchDeclaringType)
- {
+ } 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));
- return MemberCollector.CollectMembers (solution, members.First (), ReferenceFinder.RefactoryScope.Solution,
- includeOverloads, matchDeclaringType).ToList ();
+ + 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,
+ 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,
+ { + 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,
+ 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); } @@ -118,7 +120,7 @@ namespace MonoDevelop.Ide.FindInFiles return m => m.Name == memberName && m.DeclaringType.Name == declaringType && (filter == null || filter (m)); } - [Test]
+ [Test] public void TestMethodOverrides () { var code = @" @@ -144,7 +146,7 @@ class D : A TestCollectMembersForAllTypes (code, memberName, types); } - [Test]
+ [Test] public void TestEventOverrides () { var code = @" @@ -198,7 +200,7 @@ class D : A TestCollectMembersForAllTypes (code, memberName, types); } - [Test]
+ [Test] public void TestSingleInterfaceImpl () { var code = @" @@ -326,7 +328,7 @@ class C : IB TestCollectMembers (code, "IB", memberName, expected3); } - [Test]
+ [Test] public void TestMethodOverloads () { var code = @" @@ -357,7 +359,7 @@ struct B } } - [Test]
+ [Test] public void TestIncludeOverloads () { var code = @" @@ -395,7 +397,7 @@ class D : A } - [Test]
+ [Test] public void TestExcludeOverloads () { var code = @" @@ -441,7 +443,7 @@ class D : A } - [Test]
+ [Test] public void TestInterfacePlusOverrides () { string code = @" @@ -509,37 +511,38 @@ class D : B, IA, IB { } 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}); - }
-
- [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);
- }
-
+ 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 () { diff --git a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs index 8ab87831c8..1277e03676 100755 --- a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs +++ b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/SearchCollectorTests.cs @@ -97,7 +97,7 @@ namespace project1 { { } }"; var project1 = new UnknownProject { FileName = "projectc1.csproj" }; - var project2 = new DotNetAssemblyProject { FileName = "projectc2.csproj" }; + var project2 = new MonoDevelop.CSharp.Project.CSharpProject { FileName = "projectc2.csproj" }; project2.References.Add (new MonoDevelop.Projects.ProjectReference (project1)); var solution = new Solution (); @@ -148,7 +148,7 @@ namespace project1 { } }"; var project1 = new UnknownProject { FileName = "project1.csproj" }; - var project2 = new DotNetAssemblyProject { FileName = "project2.csproj" }; + var project2 = new MonoDevelop.CSharp.Project.CSharpProject { FileName = "project2.csproj" }; var solution = new Solution (); solution.RootFolder.AddItem (project1); solution.RootFolder.AddItem (project2); @@ -183,7 +183,7 @@ namespace project1 { var projects = new List<Project> (); var solution = new Solution (); for (int i = 0; i < 3; i++) { - var project = new DotNetAssemblyProject { FileName = String.Format ("projectx{0}.csproj", 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))); |