39 changed files with 1873 additions and 137 deletions
@ -0,0 +1,117 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveBuiltInRoundMethodTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("round", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"round\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsMethodGroupResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is MethodGroupResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultMethodNameIsRound() |
||||||
|
{ |
||||||
|
Assert.AreEqual("round", MethodResolveResult.Name); |
||||||
|
} |
||||||
|
|
||||||
|
MethodGroupResolveResult MethodResolveResult { |
||||||
|
get { return (MethodGroupResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultContainingTypeHasTwoRoundMethods() |
||||||
|
{ |
||||||
|
List<IMethod> exitMethods = GetRoundMethods(); |
||||||
|
Assert.AreEqual(2, exitMethods.Count); |
||||||
|
} |
||||||
|
|
||||||
|
List<IMethod> GetRoundMethods() |
||||||
|
{ |
||||||
|
return GetRoundMethods(-1); |
||||||
|
} |
||||||
|
|
||||||
|
List<IMethod> GetRoundMethods(int parameterCount) |
||||||
|
{ |
||||||
|
List<IMethod> methods = MethodResolveResult.ContainingType.GetMethods(); |
||||||
|
return PythonCompletionItemsHelper.FindAllMethodsFromCollection("round", parameterCount, methods.ToArray()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BothRoundMethodsArePublic() |
||||||
|
{ |
||||||
|
foreach (IMethod method in GetRoundMethods()) { |
||||||
|
Assert.IsTrue(method.IsPublic); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BothRoundMethodsHaveClassWithNameOfSys() |
||||||
|
{ |
||||||
|
foreach (IMethod method in GetRoundMethods()) { |
||||||
|
Assert.AreEqual("__builtin__", method.DeclaringType.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void OneRoundMethodHasTwoParameters() |
||||||
|
{ |
||||||
|
int parameterCount = 2; |
||||||
|
Assert.AreEqual(1, GetRoundMethods(parameterCount).Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RoundMethodParameterNameIsNumber() |
||||||
|
{ |
||||||
|
IParameter parameter = GetFirstRoundMethodParameter(); |
||||||
|
Assert.AreEqual("number", parameter.Name); |
||||||
|
} |
||||||
|
|
||||||
|
IParameter GetFirstRoundMethodParameter() |
||||||
|
{ |
||||||
|
int parameterCount = 1; |
||||||
|
List<IMethod> methods = GetRoundMethods(parameterCount); |
||||||
|
IMethod method = methods[0]; |
||||||
|
return method.Parameters[0]; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RoundMethodParameterReturnTypeIsDouble() |
||||||
|
{ |
||||||
|
IParameter parameter = GetFirstRoundMethodParameter(); |
||||||
|
Assert.AreEqual("Double", parameter.ReturnType.Name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RoundMethodParameterConvertedToStringUsingAmbienceReturnsDoubleNumberString() |
||||||
|
{ |
||||||
|
IAmbience ambience = new CSharpAmbience(); |
||||||
|
string text = ambience.Convert(GetFirstRoundMethodParameter()); |
||||||
|
Assert.AreEqual("double number", text); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that the expression "Console.WriteLine" is correctly
|
||||||
|
/// resolved.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class ResolveConsoleWriteLineTests : ResolveTestsBase |
||||||
|
{ |
||||||
|
MockClass systemConsoleClass; |
||||||
|
|
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
systemConsoleClass = new MockClass(projectContent, "System.Console"); |
||||||
|
projectContent.SetClassToReturnFromGetClass("Console", systemConsoleClass); |
||||||
|
return new ExpressionResult("Console.WriteLine", new DomRegion(2, 2), null, null); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System\r\n" + |
||||||
|
"Console.WriteLine\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultExists() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(resolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the class name used in IProjectContent.GetClass call.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void GetClassName() |
||||||
|
{ |
||||||
|
Assert.AreEqual("Console", projectContent.GetClassName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void MethodNameResolveIsWriteLine() |
||||||
|
{ |
||||||
|
MethodGroupResolveResult methodResolveResult = (MethodGroupResolveResult)resolveResult; |
||||||
|
Assert.AreEqual("WriteLine", methodResolveResult.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveExitMethodFromSysImportExitAsMyExitTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("myexit", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from sys import exit as myexit\r\n" + |
||||||
|
"myexit\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsMethodGroupResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is MethodGroupResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultMethodNameIsExit() |
||||||
|
{ |
||||||
|
Assert.AreEqual("exit", MethodResolveResult.Name); |
||||||
|
} |
||||||
|
|
||||||
|
MethodGroupResolveResult MethodResolveResult { |
||||||
|
get { return (MethodGroupResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveFooWindowsWithImportSystemAsFooTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
MockProjectContent referencedContent = new MockProjectContent(); |
||||||
|
List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>(); |
||||||
|
referencedContent.AddExistingNamespaceContents("System.Windows.Forms", namespaceItems); |
||||||
|
projectContent.ReferencedContents.Add(referencedContent); |
||||||
|
|
||||||
|
return new ExpressionResult("Foo.Windows"); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System as Foo\r\n" + |
||||||
|
"Foo.Windows\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
NamespaceResolveResult NamespaceResolveResult { |
||||||
|
get { return resolveResult as NamespaceResolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultHasSystemWindowsNamespace() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System.Windows", NamespaceResolveResult.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that the PythonResolver resolves "from System" to
|
||||||
|
/// a namespace.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class ResolveFromImportTestFixture |
||||||
|
{ |
||||||
|
PythonResolver resolver; |
||||||
|
MockProjectContent mockProjectContent; |
||||||
|
PythonImportModuleResolveResult resolveResult; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
resolver = new PythonResolver(); |
||||||
|
|
||||||
|
mockProjectContent = new MockProjectContent(); |
||||||
|
DefaultCompilationUnit cu = new DefaultCompilationUnit(mockProjectContent); |
||||||
|
cu.FileName = @"C:\Projects\Test\test.py"; |
||||||
|
ParseInformation parseInfo = new ParseInformation(cu); |
||||||
|
|
||||||
|
string python = "from System"; |
||||||
|
PythonExpressionFinder finder = new PythonExpressionFinder(); |
||||||
|
ExpressionResult expressionResult = finder.FindExpression(python, python.Length); |
||||||
|
resolveResult = resolver.Resolve(expressionResult, parseInfo, python) as PythonImportModuleResolveResult; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultFound() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(resolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceName() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System", resolveResult.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveFromMathImportedMathModuleCompletionItemsTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
List<ICompletionEntry> GetCompletionResults() |
||||||
|
{ |
||||||
|
return resolveResult.GetCompletionData(projectContent); |
||||||
|
} |
||||||
|
|
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
string code = GetPythonScript(); |
||||||
|
PythonExpressionFinder finder = new PythonExpressionFinder(); |
||||||
|
return finder.FindExpression(code, code.Length); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return "from math import"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CompletionResultsContainCosMethodFromMathModule() |
||||||
|
{ |
||||||
|
IMethod method = PythonCompletionItemsHelper.FindMethodFromCollection("cos", GetCompletionResults()); |
||||||
|
Assert.IsNotNull(method); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ExpressionResultContextShowItemReturnsTrueForIMethod() |
||||||
|
{ |
||||||
|
MockProjectContent projectContent = new MockProjectContent(); |
||||||
|
DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent); |
||||||
|
DefaultClass c = new DefaultClass(unit, "MyClass"); |
||||||
|
DefaultMethod method = new DefaultMethod(c, "Test"); |
||||||
|
|
||||||
|
Assert.IsTrue(expressionResult.Context.ShowEntry(method)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveFromSystemImportEverythingTests : ResolveTestsBase |
||||||
|
{ |
||||||
|
MockClass consoleClass; |
||||||
|
|
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
consoleClass = new MockClass(projectContent, "System.Console"); |
||||||
|
projectContent.SetClassToReturnFromGetClass("System.Console", consoleClass); |
||||||
|
|
||||||
|
List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>(); |
||||||
|
projectContent.AddExistingNamespaceContents("System", namespaceItems); |
||||||
|
|
||||||
|
return new ExpressionResult("Console", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from System import *\r\n" + |
||||||
|
"Console\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultResolvedClassIsConsoleClass() |
||||||
|
{ |
||||||
|
Assert.AreEqual(consoleClass, TypeResolveResult.ResolvedClass); |
||||||
|
} |
||||||
|
|
||||||
|
TypeResolveResult TypeResolveResult { |
||||||
|
get { return (TypeResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ProjectContentNamespaceExistsReturnsTrueForSystem() |
||||||
|
{ |
||||||
|
Assert.IsTrue(projectContent.NamespaceExists("System")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,101 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Given code:
|
||||||
|
///
|
||||||
|
/// a = Class1()
|
||||||
|
///
|
||||||
|
/// Check that the type of "a" can be obtained by the resolver.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
[Ignore("Disabled local variable resolution for SD 3.0")] |
||||||
|
public class ResolveLocalClassInstanceTests |
||||||
|
{ |
||||||
|
PythonResolver resolver; |
||||||
|
ICSharpCode.Scripting.Tests.Utils.MockProjectContent mockProjectContent; |
||||||
|
LocalResolveResult resolveResult; |
||||||
|
MockClass testClass; |
||||||
|
ICompilationUnit compilationUnit; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
resolver = new PythonResolver(); |
||||||
|
|
||||||
|
mockProjectContent = new ICSharpCode.Scripting.Tests.Utils.MockProjectContent(); |
||||||
|
testClass = new MockClass(mockProjectContent, "Test.Test1"); |
||||||
|
mockProjectContent.ClassesInProjectContent.Add(testClass); |
||||||
|
mockProjectContent.SetClassToReturnFromGetClass("Test.Test1", testClass); |
||||||
|
|
||||||
|
compilationUnit = new DefaultCompilationUnit(mockProjectContent); |
||||||
|
compilationUnit.FileName = @"C:\Projects\Test\test.py"; |
||||||
|
ParseInformation parseInfo = new ParseInformation(compilationUnit); |
||||||
|
|
||||||
|
string python = |
||||||
|
"a = Test1()\r\n" + |
||||||
|
"a"; |
||||||
|
ExpressionResult expressionResult = new ExpressionResult("a", new DomRegion(2, 1), null, null); |
||||||
|
resolveResult = resolver.Resolve(expressionResult, parseInfo, python) as LocalResolveResult; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetTypeOfInstance() |
||||||
|
{ |
||||||
|
string code = "a = Class1()"; |
||||||
|
PythonVariableResolver resolver = new PythonVariableResolver(); |
||||||
|
Assert.AreEqual("Class1", resolver.Resolve("a", @"C:\Projects\Test\Test.py", code)); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that the NameExpression in the resolver is reset so the second assignment
|
||||||
|
/// does not override the first.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void DifferentTypeCreatedLast() |
||||||
|
{ |
||||||
|
string code = "a = Class1()\r\n" + |
||||||
|
"b = Class2()"; |
||||||
|
PythonVariableResolver resolver = new PythonVariableResolver(); |
||||||
|
Assert.AreEqual("Class1", resolver.Resolve("a", @"C:\Projects\Test\Test.py", code)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void StringAssignmentShouldNotResolve() |
||||||
|
{ |
||||||
|
string code = "a = \"test\""; |
||||||
|
PythonVariableResolver resolver = new PythonVariableResolver(); |
||||||
|
Assert.AreEqual(null, resolver.Resolve("a", @"C:\Projects\Test\Test.py", code)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NullCodeShouldNotResolve() |
||||||
|
{ |
||||||
|
PythonVariableResolver resolver = new PythonVariableResolver(); |
||||||
|
Assert.AreEqual(null, resolver.Resolve("a", @"C:\Projects\Test\Test.py", null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsLocalResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(resolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultVariableName() |
||||||
|
{ |
||||||
|
Assert.AreEqual(resolveResult.VariableName, "a"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveMethodFromUnknownImportAllTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("methodcall", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from unknown import *\r\n" + |
||||||
|
"methodcall\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsNull() |
||||||
|
{ |
||||||
|
Assert.IsNull(resolveResult); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveMethodWhenFromImportIsUnknownTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("methodcall", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from unknown import methodcall\r\n" + |
||||||
|
"methodcall\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsNull() |
||||||
|
{ |
||||||
|
Assert.IsNull(resolveResult); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveMethodWhenImportIsUnknownTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("unknown.methodcall", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from unknown import methodcall\r\n" + |
||||||
|
"unknown.methodcall\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsNull() |
||||||
|
{ |
||||||
|
Assert.IsNull(resolveResult); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,136 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSysModuleExitMethodTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("sys.exit", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import sys\r\n" + |
||||||
|
"sys.exit\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsMethodGroupResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is MethodGroupResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultMethodNameIsExit() |
||||||
|
{ |
||||||
|
Assert.AreEqual("exit", MethodResolveResult.Name); |
||||||
|
} |
||||||
|
|
||||||
|
MethodGroupResolveResult MethodResolveResult { |
||||||
|
get { return (MethodGroupResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultContainingTypeHasTwoExitMethods() |
||||||
|
{ |
||||||
|
List<IMethod> exitMethods = GetExitMethods(); |
||||||
|
Assert.AreEqual(2, exitMethods.Count); |
||||||
|
} |
||||||
|
|
||||||
|
List<IMethod> GetExitMethods() |
||||||
|
{ |
||||||
|
return GetExitMethods(-1); |
||||||
|
} |
||||||
|
|
||||||
|
List<IMethod> GetExitMethods(int parameterCount) |
||||||
|
{ |
||||||
|
List<IMethod> methods = MethodResolveResult.ContainingType.GetMethods(); |
||||||
|
return PythonCompletionItemsHelper.FindAllMethodsFromCollection("exit", parameterCount, methods.ToArray()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BothExitMethodsArePublic() |
||||||
|
{ |
||||||
|
foreach (IMethod method in GetExitMethods()) { |
||||||
|
Assert.IsTrue(method.IsPublic); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BothExitMethodsHaveClassWithNameOfSys() |
||||||
|
{ |
||||||
|
foreach (IMethod method in GetExitMethods()) { |
||||||
|
Assert.AreEqual("sys", method.DeclaringType.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void OneExitMethodHasOneParameter() |
||||||
|
{ |
||||||
|
int parameterCount = 1; |
||||||
|
Assert.AreEqual(1, GetExitMethods(parameterCount).Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ExitMethodParameterNameIsCode() |
||||||
|
{ |
||||||
|
IParameter parameter = GetFirstExitMethodParameter(); |
||||||
|
Assert.AreEqual("code", parameter.Name); |
||||||
|
} |
||||||
|
|
||||||
|
IParameter GetFirstExitMethodParameter() |
||||||
|
{ |
||||||
|
int parameterCount = 1; |
||||||
|
List<IMethod> methods = GetExitMethods(parameterCount); |
||||||
|
IMethod method = methods[0]; |
||||||
|
return method.Parameters[0]; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ExitMethodParameterReturnTypeIsObject() |
||||||
|
{ |
||||||
|
IParameter parameter = GetFirstExitMethodParameter(); |
||||||
|
Assert.AreEqual("Object", parameter.ReturnType.Name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ExitMethodParameterConvertedToStringUsingAmbienceReturnsObjectCodeString() |
||||||
|
{ |
||||||
|
IAmbience ambience = new CSharpAmbience(); |
||||||
|
string text = ambience.Convert(GetFirstExitMethodParameter()); |
||||||
|
Assert.AreEqual("object code", text); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ExitMethodReturnTypeConvertedToStringUsingAmbienceReturnsVoid() |
||||||
|
{ |
||||||
|
IAmbience ambience = new CSharpAmbience(); |
||||||
|
List<IMethod> methods = GetExitMethods(); |
||||||
|
IReturnType returnType = methods[0].ReturnType; |
||||||
|
string text = ambience.Convert(returnType); |
||||||
|
Assert.AreEqual("void", text); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void MethodGroupContainingTypeHasTwoExitMethods() |
||||||
|
{ |
||||||
|
IReturnType returnType = MethodResolveResult.ContainingType; |
||||||
|
List<IMethod> methods = PythonCompletionItemsHelper.FindAllMethodsFromCollection("exit", returnType.GetMethods()); |
||||||
|
Assert.AreEqual(2, methods.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSysModuleImportedAsMySysTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("mysys", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import sys as mysys\r\n" + |
||||||
|
"mysys\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultContainsExitMethod() |
||||||
|
{ |
||||||
|
List<ICompletionEntry> items = GetCompletionItems(); |
||||||
|
IMethod method = PythonCompletionItemsHelper.FindMethodFromCollection("exit", items); |
||||||
|
Assert.IsNotNull(method); |
||||||
|
} |
||||||
|
|
||||||
|
List<ICompletionEntry> GetCompletionItems() |
||||||
|
{ |
||||||
|
return resolveResult.GetCompletionData(projectContent); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSysModuleUnknownMethodTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("sys.unknown", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import sys\r\n" + |
||||||
|
"sys.unknown\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsNull() |
||||||
|
{ |
||||||
|
Assert.IsNull(resolveResult); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,105 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests the PythonResolver correctly resolves the expression:
|
||||||
|
/// "System.Console"
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemConsoleTestFixture |
||||||
|
{ |
||||||
|
PythonResolver resolver; |
||||||
|
ICSharpCode.Scripting.Tests.Utils.MockProjectContent mockProjectContent; |
||||||
|
ResolveResult resolveResult; |
||||||
|
MockClass testClass; |
||||||
|
ICompilationUnit compilationUnit; |
||||||
|
MockClass systemConsoleClass; |
||||||
|
ResolveResult invalidMostRecentCompilationUnitResolveResult; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
resolver = new PythonResolver(); |
||||||
|
mockProjectContent = new ICSharpCode.Scripting.Tests.Utils.MockProjectContent(); |
||||||
|
|
||||||
|
systemConsoleClass = new MockClass(mockProjectContent, "System.Console"); |
||||||
|
mockProjectContent.ClassToReturnFromGetClass = systemConsoleClass; |
||||||
|
|
||||||
|
compilationUnit = CreateCompilationUnit(mockProjectContent); |
||||||
|
ParseInformation parseInfo = new ParseInformation(compilationUnit); |
||||||
|
|
||||||
|
string python = GetPythonScript(); |
||||||
|
ExpressionResult expressionResult = new ExpressionResult("System.Console", new DomRegion(3, 2), null, null); |
||||||
|
resolveResult = resolver.Resolve(expressionResult, parseInfo, python); |
||||||
|
|
||||||
|
// Check that the best compilation unit is used and the resolve
|
||||||
|
// still works.
|
||||||
|
invalidMostRecentCompilationUnitResolveResult = resolver.Resolve(expressionResult, parseInfo, python); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultExists() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(resolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTypeResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsInstanceOf(typeof(TypeResolveResult), resolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolvedClass() |
||||||
|
{ |
||||||
|
TypeResolveResult typeResolveResult = resolveResult as TypeResolveResult; |
||||||
|
Assert.AreEqual(systemConsoleClass, typeResolveResult.ResolvedClass); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetClassName() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System.Console", mockProjectContent.GetClassName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolvedClassWithInvalidMostRecentCompilationUnit() |
||||||
|
{ |
||||||
|
TypeResolveResult typeResolveResult = invalidMostRecentCompilationUnitResolveResult as TypeResolveResult; |
||||||
|
Assert.AreEqual(systemConsoleClass, typeResolveResult.ResolvedClass); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the Python script that will be used for testing.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual string GetPythonScript() |
||||||
|
{ |
||||||
|
return "import System\r\n" + |
||||||
|
"class Test:\r\n" + |
||||||
|
"\tdef __init__(self):\r\n" + |
||||||
|
"\t\tSystem.Console\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a compilation unit with one class called Test.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual ICompilationUnit CreateCompilationUnit(IProjectContent projectContent) |
||||||
|
{ |
||||||
|
ICompilationUnit compilationUnit = new DefaultCompilationUnit(projectContent); |
||||||
|
testClass = new MockClass(projectContent, "Test"); |
||||||
|
compilationUnit.Classes.Add(testClass); |
||||||
|
return compilationUnit; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that the PythonResolver resolves "import System" to
|
||||||
|
/// a namespace.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemImportTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
string code = GetPythonScript(); |
||||||
|
PythonExpressionFinder finder = new PythonExpressionFinder(); |
||||||
|
return finder.FindExpression(code, code.Length); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return "import System"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultFound() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(resolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceName() |
||||||
|
{ |
||||||
|
PythonImportModuleResolveResult importResolveResult = (PythonImportModuleResolveResult)resolveResult; |
||||||
|
Assert.AreEqual("System", importResolveResult.Name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ExpressionResultContextShowItemReturnsTrueForNamespaceEntry() |
||||||
|
{ |
||||||
|
NamespaceEntry entry = new NamespaceEntry("abc"); |
||||||
|
Assert.IsTrue(expressionResult.Context.ShowEntry(entry)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ExpressionResultContextShowItemReturnsFalseForNull() |
||||||
|
{ |
||||||
|
Assert.IsFalse(expressionResult.Context.ShowEntry(null)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemImportedAsMySystemTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>(); |
||||||
|
DefaultClass consoleClass = new DefaultClass(compilationUnit, "System.Console"); |
||||||
|
namespaceItems.Add(consoleClass); |
||||||
|
projectContent.AddExistingNamespaceContents("System", namespaceItems); |
||||||
|
|
||||||
|
return new ExpressionResult("MySystem", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System as MySystem\r\n" + |
||||||
|
"MySystem.\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultContainsConsoleClass() |
||||||
|
{ |
||||||
|
List<ICompletionEntry> items = GetCompletionItems(); |
||||||
|
IClass consoleClass = PythonCompletionItemsHelper.FindClassFromCollection("Console", items); |
||||||
|
Assert.IsNotNull(consoleClass); |
||||||
|
} |
||||||
|
|
||||||
|
List<ICompletionEntry> GetCompletionItems() |
||||||
|
{ |
||||||
|
return resolveResult.GetCompletionData(projectContent); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultNameIsSystem() |
||||||
|
{ |
||||||
|
NamespaceResolveResult namespaceResolveResult = resolveResult as NamespaceResolveResult; |
||||||
|
Assert.AreEqual("System", namespaceResolveResult.Name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void MockProjectContentSystemNamespaceContentsIncludesConsoleClass() |
||||||
|
{ |
||||||
|
List<ICompletionEntry> items = projectContent.GetNamespaceContents("System"); |
||||||
|
IClass consoleClass = PythonCompletionItemsHelper.FindClassFromCollection("Console", items); |
||||||
|
Assert.IsNotNull(consoleClass); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void MockProjectContentNamespaceExistsReturnsTrueForSystem() |
||||||
|
{ |
||||||
|
Assert.IsTrue(projectContent.NamespaceExists("System")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests the PythonResolver correctly resolves the expression:
|
||||||
|
/// "System"
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemNamespaceTestFixture |
||||||
|
{ |
||||||
|
PythonResolver resolver; |
||||||
|
MockProjectContent mockProjectContent; |
||||||
|
NamespaceResolveResult resolveResult; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
resolver = new PythonResolver(); |
||||||
|
mockProjectContent = new MockProjectContent(); |
||||||
|
mockProjectContent.AddExistingNamespaceContents("System", new List<ICompletionEntry>()); |
||||||
|
|
||||||
|
string python = |
||||||
|
"import System\r\n" + |
||||||
|
"class Test:\r\n" + |
||||||
|
" def __init__(self):\r\n" + |
||||||
|
" System.\r\n"; |
||||||
|
|
||||||
|
PythonParser parser = new PythonParser(); |
||||||
|
string fileName = @"C:\Projects\Test\test.py"; |
||||||
|
DefaultCompilationUnit cu = parser.Parse(mockProjectContent, fileName, python) as DefaultCompilationUnit; |
||||||
|
ParseInformation parseInfo = new ParseInformation(cu); |
||||||
|
|
||||||
|
ExpressionResult expressionResult = new ExpressionResult("System", new DomRegion(4, 2), null, null); |
||||||
|
resolveResult = resolver.Resolve(expressionResult, parseInfo, python) as NamespaceResolveResult; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceExistsCalled() |
||||||
|
{ |
||||||
|
Assert.IsTrue(mockProjectContent.NamespaceExistsCalled); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceSearchedFor() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System", mockProjectContent.NamespacePassedToNamespaceExistsMethod); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultHasSystemNamespace() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System", resolveResult.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemNamespaceWithMissingImportTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
MockClass systemConsoleClass = new MockClass(projectContent, "System.Console"); |
||||||
|
List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>(); |
||||||
|
namespaceItems.Add(systemConsoleClass); |
||||||
|
projectContent.AddExistingNamespaceContents("System", namespaceItems); |
||||||
|
|
||||||
|
return new ExpressionResult("System", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return "System\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsNullSinceSystemNamespaceIsNotImported() |
||||||
|
{ |
||||||
|
Assert.IsNull(resolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ProjectContentNamespaceExistsReturnsTrueForSystemNamespace() |
||||||
|
{ |
||||||
|
Assert.IsTrue(projectContent.NamespaceExists("System")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemWindowsFormsWithImportSystemTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
MockProjectContent referencedContent = new MockProjectContent(); |
||||||
|
List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>(); |
||||||
|
referencedContent.AddExistingNamespaceContents("System.Windows.Forms", namespaceItems); |
||||||
|
projectContent.ReferencedContents.Add(referencedContent); |
||||||
|
|
||||||
|
return new ExpressionResult("System.Windows.Forms"); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System\r\n" + |
||||||
|
"System.Windows.Forms\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
NamespaceResolveResult NamespaceResolveResult { |
||||||
|
get { return resolveResult as NamespaceResolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultHasSystemNamespace() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System.Windows.Forms", NamespaceResolveResult.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemWindowsWithImportSystemTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
MockProjectContent referencedContent = new MockProjectContent(); |
||||||
|
List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>(); |
||||||
|
referencedContent.AddExistingNamespaceContents("System.Windows.Forms", namespaceItems); |
||||||
|
projectContent.ReferencedContents.Add(referencedContent); |
||||||
|
|
||||||
|
return new ExpressionResult("System.Windows"); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System\r\n" + |
||||||
|
"System.Windows\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
NamespaceResolveResult NamespaceResolveResult { |
||||||
|
get { return resolveResult as NamespaceResolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultHasSystemWindowsNamespace() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System.Windows", NamespaceResolveResult.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveSystemWithImportSystemWindowsTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("System"); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System.Windows\r\n" + |
||||||
|
"System\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
NamespaceResolveResult NamespaceResolveResult { |
||||||
|
get { return resolveResult as NamespaceResolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NamespaceResolveResultHasSystemNamespace() |
||||||
|
{ |
||||||
|
Assert.AreEqual("System", NamespaceResolveResult.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,63 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveTanMethodFromMathImportAllTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("tan", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from sys import *\r\n" + |
||||||
|
"from math import *\r\n" + |
||||||
|
"from socket import *\r\n" + |
||||||
|
"\r\n" + |
||||||
|
"tan\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsMethodGroupResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is MethodGroupResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultMethodNameIsTan() |
||||||
|
{ |
||||||
|
Assert.AreEqual("tan", MethodResolveResult.Name); |
||||||
|
} |
||||||
|
|
||||||
|
MethodGroupResolveResult MethodResolveResult { |
||||||
|
get { return (MethodGroupResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultContainingTypeHasOneTanMethods() |
||||||
|
{ |
||||||
|
List<IMethod> tanMethods = GetTanMethods(); |
||||||
|
Assert.AreEqual(1, tanMethods.Count); |
||||||
|
} |
||||||
|
|
||||||
|
List<IMethod> GetTanMethods() |
||||||
|
{ |
||||||
|
List<IMethod> methods = MethodResolveResult.ContainingType.GetMethods(); |
||||||
|
return PythonCompletionItemsHelper.FindAllMethodsFromCollection("tan", -1, methods.ToArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveTanMethodFromMathImportCosAndTanTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
return new ExpressionResult("tan", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from math import cos, tan\r\n" + |
||||||
|
"tan\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsMethodGroupResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is MethodGroupResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultMethodNameIsTan() |
||||||
|
{ |
||||||
|
Assert.AreEqual("tan", MethodResolveResult.Name); |
||||||
|
} |
||||||
|
|
||||||
|
MethodGroupResolveResult MethodResolveResult { |
||||||
|
get { return (MethodGroupResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultContainingTypeHasOneTanMethods() |
||||||
|
{ |
||||||
|
List<IMethod> tanMethods = GetTanMethods(); |
||||||
|
Assert.AreEqual(1, tanMethods.Count); |
||||||
|
} |
||||||
|
|
||||||
|
List<IMethod> GetTanMethods() |
||||||
|
{ |
||||||
|
List<IMethod> methods = MethodResolveResult.ContainingType.GetMethods(); |
||||||
|
return PythonCompletionItemsHelper.FindAllMethodsFromCollection("tan", -1, methods.ToArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
public abstract class ResolveTestsBase |
||||||
|
{ |
||||||
|
protected ICompilationUnit compilationUnit; |
||||||
|
protected MockProjectContent projectContent; |
||||||
|
protected PythonResolver resolver; |
||||||
|
protected ResolveResult resolveResult; |
||||||
|
protected ParseInformation parseInfo; |
||||||
|
protected ExpressionResult expressionResult; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void InitBase() |
||||||
|
{ |
||||||
|
projectContent = new MockProjectContent(); |
||||||
|
PythonParser parser = new PythonParser(); |
||||||
|
string fileName = @"C:\projects\test\test.py"; |
||||||
|
compilationUnit = parser.Parse(projectContent, fileName, GetPythonScript()); |
||||||
|
parseInfo = new ParseInformation(compilationUnit); |
||||||
|
|
||||||
|
resolver = new PythonResolver(); |
||||||
|
|
||||||
|
expressionResult = GetExpressionResult(); |
||||||
|
resolveResult = resolver.Resolve(expressionResult, parseInfo, GetPythonScript()); |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract ExpressionResult GetExpressionResult(); |
||||||
|
|
||||||
|
protected abstract string GetPythonScript(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveTextBoxFromSystemWindowsFormsImportTextBoxTests : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
MockClass textBoxClass = new MockClass(projectContent, "System.Windows.Forms.TextBox"); |
||||||
|
projectContent.SetClassToReturnFromGetClass("System.Windows.Forms.TextBox", textBoxClass); |
||||||
|
|
||||||
|
return new ExpressionResult("TextBox", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from System.Windows.Forms import TextBox\r\n" + |
||||||
|
"TextBox\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsTypeResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is TypeResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultResolveClassNameIsTextBox() |
||||||
|
{ |
||||||
|
Assert.AreEqual("TextBox", TypeResolveResult.ResolvedClass.Name); |
||||||
|
} |
||||||
|
|
||||||
|
TypeResolveResult TypeResolveResult { |
||||||
|
get { return (TypeResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveTextBoxFromSystemWindowsFormsImportedAsFooTests : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
MockClass textBoxClass = new MockClass(projectContent, "System.Windows.Forms.TextBox"); |
||||||
|
projectContent.SetClassToReturnFromGetClass("System.Windows.Forms.TextBox", textBoxClass); |
||||||
|
|
||||||
|
return new ExpressionResult("Foo.TextBox", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System.Windows.Forms as Foo\r\n" + |
||||||
|
"Foo.TextBox\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsTypeResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is TypeResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultResolveClassNameIsTextBox() |
||||||
|
{ |
||||||
|
Assert.AreEqual("TextBox", TypeResolveResult.ResolvedClass.Name); |
||||||
|
} |
||||||
|
|
||||||
|
TypeResolveResult TypeResolveResult { |
||||||
|
get { return (TypeResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolveTextBoxFromSystemWindowsFormsImportedAsMyTextBoxTests : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
MockClass textBoxClass = new MockClass(projectContent, "System.Windows.Forms.TextBox"); |
||||||
|
projectContent.SetClassToReturnFromGetClass("System.Windows.Forms.TextBox", textBoxClass); |
||||||
|
|
||||||
|
return new ExpressionResult("MyTextBox", ExpressionContext.Default); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"from System.Windows.Forms import TextBox as MyTextBox\r\n" + |
||||||
|
"MyTextBox\r\n" + |
||||||
|
"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultIsTypeResolveResult() |
||||||
|
{ |
||||||
|
Assert.IsTrue(resolveResult is TypeResolveResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultResolveClassNameIsTextBox() |
||||||
|
{ |
||||||
|
Assert.AreEqual("TextBox", TypeResolveResult.ResolvedClass.Name); |
||||||
|
} |
||||||
|
|
||||||
|
TypeResolveResult TypeResolveResult { |
||||||
|
get { return (TypeResolveResult)resolveResult; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests the PythonResolver does not return a namespace resolve result for
|
||||||
|
/// an unknown namespace.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class ResolveUnknownNamespaceTestFixture : ResolveTestsBase |
||||||
|
{ |
||||||
|
protected override ExpressionResult GetExpressionResult() |
||||||
|
{ |
||||||
|
projectContent.AddExistingNamespaceContents("System", new List<ICompletionEntry>()); |
||||||
|
|
||||||
|
return new ExpressionResult("Unknown", new DomRegion(3, 2), null, null); |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetPythonScript() |
||||||
|
{ |
||||||
|
return |
||||||
|
"import System\r\n" + |
||||||
|
"class Test:\r\n" + |
||||||
|
" def __init__(self):\r\n" + |
||||||
|
" Unknown\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ResolveResultDoesNotExist() |
||||||
|
{ |
||||||
|
Assert.IsNull(resolveResult); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue