Exemplo n.º 1
0
        public void TestOverloadedMethodCallResolutionWithCallingObject()
        {
            File.Copy(@"..\..\TestInputs\csharp_overload_callingobj.cs", Path.Combine(TestDir, "csharp_overload_callingobj.cs"));
            File.Copy(@"..\..\TestInputs\csharp_overload_calls.cs", Path.Combine(TestDir, "csharp_overload_calls.cs"));
            using (var project = new DataProject <CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                project.Update();

                var query = new StatementForLocationQuery <MethodDefinition>(project.WorkingSet, Timeout.Infinite);

                var startOffoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 11, 25);
                var startOffoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 13, 25);

                var startOfRunFoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 5, 25);
                var startOfRunFoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 7, 25);

                var foo0 = query.Execute(startOffoo0);
                Assert.AreEqual("foo", foo0.Name);
                Assert.AreEqual(0, foo0.Parameters.Count);

                var foo1 = query.Execute(startOffoo1);
                Assert.AreEqual("foo", foo1.Name);
                Assert.AreEqual(1, foo1.Parameters.Count);

                var runFoo0 = query.Execute(startOfRunFoo0);
                Assert.AreEqual("runFoo0", runFoo0.Name);

                var runFoo1 = query.Execute(startOfRunFoo1);
                Assert.AreEqual("runFoo1", runFoo1.Name);

                Assert.That(runFoo0.ContainsCallTo(foo0));
                Assert.That(!runFoo0.ContainsCallTo(foo1));

                Assert.That(runFoo1.ContainsCallTo(foo1));
                Assert.That(!runFoo1.ContainsCallTo(foo0));

                var callNoParams = runFoo0.FindExpressions <MethodCall>(true).FirstOrDefault();
                var matches      = callNoParams.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo0, matches[0]);

                var callWithParam = runFoo1.FindExpressions <MethodCall>(true).FirstOrDefault();
                matches = callWithParam.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo1, matches[0]);
            }
        }
Exemplo n.º 2
0
        public void TestFindScopeForAdjacentMethods()
        {
            File.Copy(@"..\..\TestInputs\adjacent_methods.cpp", Path.Combine(TestDir, "adjacent_methods.cpp"));

            using (var dataProj = new DataProject <CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodDefinition    mainMethod;
                MethodDefinition    fooMethod;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    mainMethod = globalScope.GetDescendants <MethodDefinition>().First(md => md.Name == "main");
                    fooMethod  = globalScope.GetDescendants <MethodDefinition>().First(md => md.Name == "Foo");
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query    = new StatementForLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "adjacent_methods.cpp"));

                var startOfMain    = new SourceLocation(testFile, 1, 1);
                var locationInMain = new SourceLocation(testFile, 1, 11);
                Assert.That(mainMethod.PrimaryLocation.Contains(startOfMain));
                Assert.That(mainMethod.PrimaryLocation.Contains(locationInMain));

                Assert.AreSame(mainMethod, query.Execute(startOfMain));
                Assert.AreSame(mainMethod, query.Execute(locationInMain));

                var startOfFoo    = new SourceLocation(testFile, 3, 1);
                var locationInFoo = new SourceLocation(testFile, 3, 11);
                Assert.That(fooMethod.PrimaryLocation.Contains(startOfFoo));
                Assert.That(fooMethod.PrimaryLocation.Contains(locationInFoo));

                Assert.AreSame(fooMethod, query.Execute(startOfFoo));
                Assert.AreSame(fooMethod, query.Execute(locationInFoo));

                var lineBetweenMethods = new SourceLocation(testFile, 2, 1);
                Assert.That(mainMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.IsFalse(fooMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.AreSame(mainMethod, query.Execute(lineBetweenMethods));
            }
        }
Exemplo n.º 3
0
        public void TestFindScopeForAdjacentMethods() {
            File.Copy(@"..\..\TestInputs\adjacent_methods.cpp", Path.Combine(TestDir, "adjacent_methods.cpp"));

            using(var dataProj = new DataProject<CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodDefinition mainMethod;
                MethodDefinition fooMethod;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    mainMethod = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "main");
                    fooMethod = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "Foo");
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query = new StatementForLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "adjacent_methods.cpp"));

                var startOfMain = new SourceLocation(testFile, 1, 1);
                var locationInMain = new SourceLocation(testFile, 1, 11);
                Assert.That(mainMethod.PrimaryLocation.Contains(startOfMain));
                Assert.That(mainMethod.PrimaryLocation.Contains(locationInMain));

                Assert.AreSame(mainMethod, query.Execute(startOfMain));
                Assert.AreSame(mainMethod, query.Execute(locationInMain));

                var startOfFoo = new SourceLocation(testFile, 3, 1);
                var locationInFoo = new SourceLocation(testFile, 3, 11);
                Assert.That(fooMethod.PrimaryLocation.Contains(startOfFoo));
                Assert.That(fooMethod.PrimaryLocation.Contains(locationInFoo));

                Assert.AreSame(fooMethod, query.Execute(startOfFoo));
                Assert.AreSame(fooMethod, query.Execute(locationInFoo));

                var lineBetweenMethods = new SourceLocation(testFile, 2, 1);
                Assert.That(mainMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.IsFalse(fooMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.AreSame(mainMethod, query.Execute(lineBetweenMethods));
            }
        }
Exemplo n.º 4
0
        public void TestOverloadedMethodCallResolutionWithCallingObject() {
            File.Copy(@"..\..\TestInputs\csharp_overload_callingobj.cs", Path.Combine(TestDir, "csharp_overload_callingobj.cs"));
            File.Copy(@"..\..\TestInputs\csharp_overload_calls.cs", Path.Combine(TestDir, "csharp_overload_calls.cs"));
            using(var project = new DataProject<CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                project.Update();

                var query = new StatementForLocationQuery<MethodDefinition>(project.WorkingSet, Timeout.Infinite);

                var startOffoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 11, 25);
                var startOffoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 13, 25);

                var startOfRunFoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 5, 25);
                var startOfRunFoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 7, 25);

                var foo0 = query.Execute(startOffoo0);
                Assert.AreEqual("foo", foo0.Name);
                Assert.AreEqual(0, foo0.Parameters.Count);

                var foo1 = query.Execute(startOffoo1);
                Assert.AreEqual("foo", foo1.Name);
                Assert.AreEqual(1, foo1.Parameters.Count);

                var runFoo0 = query.Execute(startOfRunFoo0);
                Assert.AreEqual("runFoo0", runFoo0.Name);

                var runFoo1 = query.Execute(startOfRunFoo1);
                Assert.AreEqual("runFoo1", runFoo1.Name);

                Assert.That(runFoo0.ContainsCallTo(foo0));
                Assert.That(!runFoo0.ContainsCallTo(foo1));

                Assert.That(runFoo1.ContainsCallTo(foo1));
                Assert.That(!runFoo1.ContainsCallTo(foo0));

                var callNoParams = runFoo0.FindExpressions<MethodCall>(true).FirstOrDefault();
                var matches = callNoParams.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo0, matches[0]);

                var callWithParam = runFoo1.FindExpressions<MethodCall>(true).FirstOrDefault();
                matches = callWithParam.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo1, matches[0]);
            }
        }