Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5392 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
40 changed files with 1636 additions and 361 deletions
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
/// <summary>
|
||||
/// Split up an expression into a member name and a type name.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// "myObject.Field" => "myObject" + "Field"
|
||||
/// "System.Console.WriteLine" => "System.Console" + "Console.WriteLine"
|
||||
/// </example>
|
||||
public class MemberName |
||||
{ |
||||
string name = String.Empty; |
||||
string type = String.Empty; |
||||
|
||||
public MemberName(string expression) |
||||
{ |
||||
Parse(expression); |
||||
} |
||||
|
||||
public MemberName(string typeName, string memberName) |
||||
{ |
||||
this.type = typeName; |
||||
this.name = memberName; |
||||
} |
||||
|
||||
void Parse(string expression) |
||||
{ |
||||
if (!String.IsNullOrEmpty(expression)) { |
||||
int index = expression.LastIndexOf('.'); |
||||
if (index > 0) { |
||||
type = expression.Substring(0, index); |
||||
name = expression.Substring(index + 1); |
||||
} else { |
||||
type = expression; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public string Name { |
||||
get { return name; } |
||||
} |
||||
|
||||
public bool HasName { |
||||
get { return !String.IsNullOrEmpty(name); } |
||||
} |
||||
|
||||
public string Type { |
||||
get { return type; } |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("Type: {0}, Member: {1}", type, name); |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
MemberName rhs = obj as MemberName; |
||||
if (rhs != null) { |
||||
return (name == rhs.name) && (type == rhs.type); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return name.GetHashCode() ^ type.GetHashCode(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonClassResolver |
||||
{ |
||||
public PythonClassResolver() |
||||
{ |
||||
} |
||||
|
||||
public ResolveResult Resolve(PythonResolverContext context, ExpressionResult expressionResult) |
||||
{ |
||||
IClass matchingClass = GetClass(context, expressionResult.Expression); |
||||
if (matchingClass != null) { |
||||
return CreateTypeResolveResult(matchingClass); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public IClass GetClass(PythonResolverContext context, string name) |
||||
{ |
||||
if (String.IsNullOrEmpty(name)) { |
||||
return null; |
||||
} |
||||
|
||||
IClass matchedClass = context.GetClass(name); |
||||
if (matchedClass != null) { |
||||
return matchedClass; |
||||
} |
||||
|
||||
return context.GetImportedClass(name); |
||||
} |
||||
|
||||
TypeResolveResult CreateTypeResolveResult(IClass c) |
||||
{ |
||||
return new TypeResolveResult(null, null, c); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonMethodResolver |
||||
{ |
||||
PythonClassResolver classResolver; |
||||
PythonStandardModuleResolver standardModuleResolver; |
||||
|
||||
public PythonMethodResolver(PythonClassResolver classResolver, PythonStandardModuleResolver standardModuleResolver) |
||||
{ |
||||
this.classResolver = classResolver; |
||||
this.standardModuleResolver = standardModuleResolver; |
||||
} |
||||
|
||||
public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult) |
||||
{ |
||||
MemberName memberName = new MemberName(expressionResult.Expression); |
||||
MethodGroupResolveResult resolveResult = GetDotNetMethodResolveResult(resolverContext, memberName); |
||||
if (resolveResult != null) { |
||||
return resolveResult; |
||||
} |
||||
return GetStandardModuleMethodResolveResult(resolverContext, memberName); |
||||
} |
||||
|
||||
MethodGroupResolveResult GetDotNetMethodResolveResult(PythonResolverContext resolverContext, MemberName memberName) |
||||
{ |
||||
IClass matchingClass = classResolver.GetClass(resolverContext, memberName.Type); |
||||
if (matchingClass != null) { |
||||
return CreateMethodGroupResolveResult(matchingClass, memberName.Name); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
MethodGroupResolveResult GetStandardModuleMethodResolveResult(PythonResolverContext resolverContext, MemberName memberName) |
||||
{ |
||||
if (!memberName.HasName) { |
||||
memberName = CreateBuiltinModuleMemberName(memberName.Type); |
||||
} |
||||
PythonStandardModuleType type = standardModuleResolver.GetStandardModuleType(resolverContext, memberName.Type); |
||||
if (type != null) { |
||||
return GetStandardModuleMethodResolveResult(type, memberName.Name); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
MemberName CreateBuiltinModuleMemberName(string memberName) |
||||
{ |
||||
return new MemberName(PythonStandardModuleResolver.PythonBuiltInModuleName, memberName); |
||||
} |
||||
|
||||
MethodGroupResolveResult GetStandardModuleMethodResolveResult(PythonStandardModuleType type, string methodName) |
||||
{ |
||||
PythonModuleCompletionItems completionItems = PythonModuleCompletionItemsFactory.Create(type); |
||||
MethodGroup methods = completionItems.GetMethods(methodName); |
||||
if (methods.Count > 0) { |
||||
return CreateMethodGroupResolveResult(methods); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
MethodGroupResolveResult CreateMethodGroupResolveResult(IClass c, string methodName) |
||||
{ |
||||
return new MethodGroupResolveResult(null, null, c.DefaultReturnType, methodName); |
||||
} |
||||
|
||||
MethodGroupResolveResult CreateMethodGroupResolveResult(MethodGroup methods) |
||||
{ |
||||
MethodGroup[] methodGroups = new MethodGroup[] { methods }; |
||||
IMethod method = methods[0]; |
||||
IReturnType returnType = new DefaultReturnType(method.DeclaringType); |
||||
return new MethodGroupResolveResult(null, null, returnType, method.Name, methodGroups); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonNamespaceResolver |
||||
{ |
||||
public PythonNamespaceResolver() |
||||
{ |
||||
} |
||||
|
||||
public ResolveResult Resolve(ExpressionResult expressionResult) |
||||
{ |
||||
if (IsNamespace(expressionResult)) { |
||||
PythonImportExpression importExpression = new PythonImportExpression(expressionResult.Expression); |
||||
PythonImportExpressionContext context = expressionResult.Context as PythonImportExpressionContext; |
||||
context.HasFromAndImport = importExpression.HasFromAndImport; |
||||
|
||||
return new PythonImportModuleResolveResult(importExpression); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
bool IsNamespace(ExpressionResult expressionResult) |
||||
{ |
||||
return expressionResult.Context is PythonImportExpressionContext; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,177 @@
@@ -0,0 +1,177 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonResolverContext |
||||
{ |
||||
ICompilationUnit mostRecentCompilationUnit; |
||||
ICompilationUnit bestCompilationUnit; |
||||
IProjectContent projectContent; |
||||
IClass callingClass; |
||||
|
||||
public PythonResolverContext(ParseInformation parseInfo) |
||||
{ |
||||
GetCompilationUnits(parseInfo); |
||||
GetProjectContent(); |
||||
} |
||||
|
||||
void GetCompilationUnits(ParseInformation parseInfo) |
||||
{ |
||||
mostRecentCompilationUnit = GetCompilationUnit(parseInfo, true); |
||||
bestCompilationUnit = GetCompilationUnit(parseInfo, false); |
||||
} |
||||
|
||||
void GetProjectContent() |
||||
{ |
||||
if (mostRecentCompilationUnit != null) { |
||||
projectContent = mostRecentCompilationUnit.ProjectContent; |
||||
} |
||||
} |
||||
|
||||
public ICompilationUnit MostRecentCompilationUnit { |
||||
get { return mostRecentCompilationUnit; } |
||||
} |
||||
|
||||
public IProjectContent ProjectContent { |
||||
get { return projectContent; } |
||||
} |
||||
|
||||
public bool HasProjectContent { |
||||
get { return projectContent != null; } |
||||
} |
||||
|
||||
public IClass CallingClass { |
||||
get { return callingClass; } |
||||
} |
||||
|
||||
public bool NamespaceExists(string name) |
||||
{ |
||||
return projectContent.NamespaceExists(name); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines the class and member at the specified
|
||||
/// line and column in the specified file.
|
||||
/// </summary>
|
||||
public bool GetCallingMember(DomRegion region) |
||||
{ |
||||
if (mostRecentCompilationUnit == null) { |
||||
return false; |
||||
} |
||||
|
||||
if (projectContent != null) { |
||||
callingClass = GetCallingClass(mostRecentCompilationUnit, bestCompilationUnit, region); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the compilation unit for the specified parse information.
|
||||
/// </summary>
|
||||
public ICompilationUnit GetCompilationUnit(ParseInformation parseInfo, bool mostRecent) |
||||
{ |
||||
if (parseInfo != null) { |
||||
if (mostRecent) { |
||||
return parseInfo.MostRecentCompilationUnit; |
||||
} |
||||
return parseInfo.BestCompilationUnit; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the calling class at the specified.
|
||||
/// </summary>
|
||||
IClass GetCallingClass(ICompilationUnit mostRecentCompilationUnit, ICompilationUnit bestCompilationUnit, DomRegion region) |
||||
{ |
||||
// Try the most recent compilation unit first
|
||||
IClass c = GetCallingClass(mostRecentCompilationUnit, region); |
||||
if (c != null) { |
||||
return c; |
||||
} |
||||
|
||||
// Try the best compilation unit.
|
||||
if (bestCompilationUnit != null && bestCompilationUnit.ProjectContent != null) { |
||||
IClass oldClass = GetCallingClass(bestCompilationUnit, region); |
||||
if (oldClass != null) { |
||||
return oldClass; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the calling class at the specified line and column.
|
||||
/// </summary>
|
||||
IClass GetCallingClass(ICompilationUnit compilationUnit, DomRegion region) |
||||
{ |
||||
if (compilationUnit.Classes.Count > 0) { |
||||
return compilationUnit.Classes[0]; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public IClass GetClass(string fullyQualifiedName) |
||||
{ |
||||
return projectContent.GetClass(fullyQualifiedName, 0); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns an array of the types that are imported by the
|
||||
/// current compilation unit.
|
||||
/// </summary>
|
||||
public ArrayList GetImportedTypes() |
||||
{ |
||||
ArrayList types = new ArrayList(); |
||||
CtrlSpaceResolveHelper.AddImportedNamespaceContents(types, mostRecentCompilationUnit, callingClass); |
||||
return types; |
||||
} |
||||
|
||||
public bool HasImport(string name) |
||||
{ |
||||
foreach (IUsing u in mostRecentCompilationUnit.UsingScope.Usings) { |
||||
foreach (string ns in u.Usings) { |
||||
if (name == ns) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Looks in the imported namespaces for a class that
|
||||
/// matches the class name. The class name searched for is not fully
|
||||
/// qualified.
|
||||
/// </summary>
|
||||
/// <param name="name">The unqualified class name.</param>
|
||||
public IClass GetImportedClass(string name) |
||||
{ |
||||
foreach (Object obj in GetImportedTypes()) { |
||||
IClass c = obj as IClass; |
||||
if ((c != null) && IsSameClassName(name, c.Name)) { |
||||
return c; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the two type names are the same.
|
||||
/// </summary>
|
||||
static bool IsSameClassName(string name1, string name2) |
||||
{ |
||||
return name1 == name2; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonStandardModuleResolveResult : ResolveResult |
||||
{ |
||||
PythonStandardModuleType standardModuleType; |
||||
|
||||
public PythonStandardModuleResolveResult(PythonStandardModuleType standardModuleType) |
||||
: base(null, null, null) |
||||
{ |
||||
this.standardModuleType = standardModuleType; |
||||
} |
||||
|
||||
public override ArrayList GetCompletionData(IProjectContent projectContent) |
||||
{ |
||||
PythonModuleCompletionItems completionItems = PythonModuleCompletionItemsFactory.Create(standardModuleType); |
||||
ArrayList items = new ArrayList(completionItems); |
||||
return items; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonStandardModuleResolver |
||||
{ |
||||
public const string PythonBuiltInModuleName = "__builtin__"; |
||||
PythonStandardModules standardPythonModules = new PythonStandardModules(); |
||||
|
||||
public PythonStandardModuleResolver() |
||||
{ |
||||
} |
||||
|
||||
public ResolveResult Resolve(PythonResolverContext resolverContext, ExpressionResult expressionResult) |
||||
{ |
||||
PythonStandardModuleType type = GetStandardModuleType(resolverContext, expressionResult.Expression); |
||||
if (type != null) { |
||||
return new PythonStandardModuleResolveResult(type); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public PythonStandardModuleType GetStandardModuleType(PythonResolverContext resolverContext, string name) |
||||
{ |
||||
if (resolverContext.HasImport(name) || IsBuiltInModule(name)) { |
||||
return standardPythonModules.GetModuleType(name); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
bool IsBuiltInModule(string name) |
||||
{ |
||||
return name == PythonBuiltInModuleName; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonStandardModuleType |
||||
{ |
||||
Type type; |
||||
string name; |
||||
|
||||
public PythonStandardModuleType(Type type, string name) |
||||
{ |
||||
this.type = type; |
||||
this.name = name; |
||||
} |
||||
|
||||
public Type Type { |
||||
get { return type; } |
||||
} |
||||
|
||||
public string Name { |
||||
get { return name; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using IronPython.Modules; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class GetMethodsFromSysLibraryTestFixture |
||||
{ |
||||
SysModuleCompletionItems completionItems; |
||||
MethodGroup exitMethodGroup; |
||||
MethodGroup displayHookMethodGroup; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
PythonStandardModuleType moduleType = new PythonStandardModuleType(typeof(SysModule), "sys"); |
||||
completionItems = new SysModuleCompletionItems(moduleType); |
||||
exitMethodGroup = completionItems.GetMethods("exit"); |
||||
displayHookMethodGroup = completionItems.GetMethods("displayhook"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoExitMethodsReturnedFromGetMethods() |
||||
{ |
||||
Assert.AreEqual(2, exitMethodGroup.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void FirstMethodNameIsExit() |
||||
{ |
||||
Assert.AreEqual("exit", exitMethodGroup[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void SecondMethodNameIsExit() |
||||
{ |
||||
Assert.AreEqual("exit", exitMethodGroup[1].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void FirstMethodHasReturnType() |
||||
{ |
||||
Assert.IsNotNull(exitMethodGroup[0].ReturnType); |
||||
} |
||||
|
||||
[Test] |
||||
public void SecondMethodHasReturnType() |
||||
{ |
||||
Assert.IsNotNull(exitMethodGroup[1].ReturnType); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExitMethodReturnsVoid() |
||||
{ |
||||
IMethod method = displayHookMethodGroup[0]; |
||||
Assert.AreEqual("Void", method.ReturnType.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void DisplayHookMethodDoesNotHaveCodeContextParameter() |
||||
{ |
||||
IMethod method = displayHookMethodGroup[0]; |
||||
IParameter parameter = method.Parameters[0]; |
||||
Assert.AreEqual("value", parameter.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void DisplayHookMethodReturnsVoid() |
||||
{ |
||||
IMethod method = displayHookMethodGroup[0]; |
||||
Assert.AreEqual("Void", method.ReturnType.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetDefaultEncodingMethodReturnsString() |
||||
{ |
||||
MethodGroup methodGroup = completionItems.GetMethods("getdefaultencoding"); |
||||
IMethod method = methodGroup[0]; |
||||
Assert.AreEqual("String", method.ReturnType.Name); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using IronPython.Modules; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Completion |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the documentation is taken from the Documentation attribute for the method/field in the
|
||||
/// python module classes.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class PythonSocketLibraryDocumentationTestFixture |
||||
{ |
||||
PythonModuleCompletionItems completionItems; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
PythonStandardModuleType moduleType = new PythonStandardModuleType(typeof(PythonSocket), "socket"); |
||||
completionItems = PythonModuleCompletionItemsFactory.Create(moduleType); |
||||
} |
||||
|
||||
[Test] |
||||
public void DocumentationForCreateConnectionMethodTakenFromDocumentationAttribute() |
||||
{ |
||||
string doc = |
||||
"Connect to *address* and return the socket object.\n" + |
||||
"\n" + |
||||
"Convenience function. Connect to *address* (a 2-tuple ``(host,\nport)``) and return the socket object. Passing the optional\n" + |
||||
"*timeout* parameter will set the timeout on the socket instance\nbefore attempting to connect. If no *timeout* is supplied, the\n" + |
||||
"global default timeout setting returned by :func:`getdefaulttimeout`\n" + |
||||
"is used.\n"; |
||||
|
||||
IMethod method = PythonCompletionItemsHelper.FindMethodFromCollection("create_connection", completionItems); |
||||
Assert.AreEqual(doc, method.Documentation); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Expressions |
||||
{ |
||||
[TestFixture] |
||||
public class FindExpressionOnLineWithSingleSpaceTestFixture |
||||
{ |
||||
ExpressionResult result; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
string text = " "; |
||||
PythonExpressionFinder expressionFinder = new PythonExpressionFinder(); |
||||
result = expressionFinder.FindExpression(text, 1); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpressionResultExpressionIsEmptyString() |
||||
{ |
||||
Assert.AreEqual(String.Empty, result.Expression); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Expressions |
||||
{ |
||||
[TestFixture] |
||||
public class FindExpressionWithImportOnPreviousLineTestFixture |
||||
{ |
||||
ExpressionResult result; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
string text = "import\r\n"; |
||||
PythonExpressionFinder expressionFinder = new PythonExpressionFinder(); |
||||
int offset = 8; // Cursor is just after \r\n on second line.
|
||||
result = expressionFinder.FindExpression(text, offset); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpressionResultExpressionIsEmptyString() |
||||
{ |
||||
Assert.AreEqual(String.Empty, result.Expression); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Resolver |
||||
{ |
||||
[TestFixture] |
||||
public class MemberNameTests |
||||
{ |
||||
[Test] |
||||
public void MemberNameIsEqualReturnsTrueWhenNameAndTypeAreSame() |
||||
{ |
||||
MemberName lhs = new MemberName("type", "member"); |
||||
MemberName rhs = new MemberName("type", "member"); |
||||
|
||||
Assert.IsTrue(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberNameIsEqualsReturnsFalseWhenMemberNameIsNull() |
||||
{ |
||||
MemberName lhs = new MemberName("type", "Member"); |
||||
Assert.IsFalse(lhs.Equals(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberNamePropertyReturnsMemberName() |
||||
{ |
||||
MemberName methodName = new MemberName("type", "method"); |
||||
Assert.AreEqual("method", methodName.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberNameTypePropertyReturnsType() |
||||
{ |
||||
MemberName methodName = new MemberName("type", "method"); |
||||
Assert.AreEqual("type", methodName.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberNameIsEqualReturnsFalseWhenMemberNameIsDifferent() |
||||
{ |
||||
MemberName lhs = new MemberName("type", "method1"); |
||||
MemberName rhs = new MemberName("type", "method2"); |
||||
|
||||
Assert.IsFalse(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberNameIsEqualReturnsFalseWhenTypeNameIsDifferent() |
||||
{ |
||||
MemberName lhs = new MemberName("type1", "method"); |
||||
MemberName rhs = new MemberName("type2", "method"); |
||||
|
||||
Assert.IsFalse(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberNameToStringShowsTypeNameAndMemberName() |
||||
{ |
||||
MemberName methodName = new MemberName("type", "method"); |
||||
string expectedText = "Type: type, Member: method"; |
||||
Assert.AreEqual(expectedText, methodName.ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateMemberNameWithNullStringReturnsMemberNameWithEmptyTypeAndMemberName() |
||||
{ |
||||
MemberName methodName = new MemberName(null); |
||||
MemberName expectedMemberName = new MemberName(String.Empty, String.Empty); |
||||
Assert.AreEqual(expectedMemberName, methodName); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateMemberNameWithEmptyStringReturnsMemberNameWithEmptyTypeAndMemberName() |
||||
{ |
||||
MemberName methodName = new MemberName(String.Empty); |
||||
MemberName expectedMemberName = new MemberName(String.Empty, String.Empty); |
||||
Assert.AreEqual(expectedMemberName, methodName); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateMemberNameWithSystemDotConsoleDotWriteLineReturnsMemberNameWriteLineAndTypeNameSystemDotConsole() |
||||
{ |
||||
MemberName methodName = new MemberName("System.Console.WriteLine"); |
||||
MemberName expectedMemberName = new MemberName("System.Console", "WriteLine"); |
||||
|
||||
Assert.AreEqual(expectedMemberName, methodName); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateMemberNameWithExpressionWithoutDotCharReturnsMemberNameOfEmptyStringAndExpressionAsTypeName() |
||||
{ |
||||
MemberName methodName = new MemberName("test"); |
||||
MemberName expectedMemberName = new MemberName("test", String.Empty); |
||||
Assert.AreEqual(expectedMemberName, methodName); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNameReturnsFalseForMemberNameWithEmptyStringForMemberName() |
||||
{ |
||||
MemberName memberName = new MemberName("System", String.Empty); |
||||
Assert.IsFalse(memberName.HasName); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNameReturnsTrueForMemberNameWithNonEmptyStringForMemberName() |
||||
{ |
||||
MemberName memberName = new MemberName("System", "Console"); |
||||
Assert.IsTrue(memberName.HasName); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
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 : ResolveTestFixtureBase |
||||
{ |
||||
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,140 @@
@@ -0,0 +1,140 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
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 : ResolveTestFixtureBase |
||||
{ |
||||
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,61 @@
@@ -0,0 +1,61 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Resolver |
||||
{ |
||||
[TestFixture] |
||||
public class ResolveSysModuleTestFixture : ResolveTestFixtureBase |
||||
{ |
||||
protected override ExpressionResult GetExpressionResult() |
||||
{ |
||||
return new ExpressionResult("sys", ExpressionContext.Default); |
||||
} |
||||
|
||||
protected override string GetPythonScript() |
||||
{ |
||||
return |
||||
"import sys\r\n" + |
||||
"sys\r\n" + |
||||
"\r\n"; |
||||
} |
||||
|
||||
[Test] |
||||
public void CompilationUnitHasSysModuleInUsingsCollection() |
||||
{ |
||||
Assert.AreEqual("sys", compilationUnit.UsingScope.Usings[0].Usings[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveResultContainsExitMethod() |
||||
{ |
||||
ArrayList items = GetCompletionItems(); |
||||
IMethod method = PythonCompletionItemsHelper.FindMethodFromCollection("exit", items); |
||||
Assert.IsNotNull(method); |
||||
} |
||||
|
||||
ArrayList GetCompletionItems() |
||||
{ |
||||
return resolveResult.GetCompletionData(projectContent); |
||||
} |
||||
|
||||
[Test] |
||||
public void MathModuleExpressionShouldNotHaveAnyCompletionItemsSinceMathModuleIsNotImported() |
||||
{ |
||||
ExpressionResult result = new ExpressionResult("math", ExpressionContext.Default); |
||||
resolveResult = resolver.Resolve(result, parseInfo, GetPythonScript()); |
||||
|
||||
Assert.IsNull(resolveResult); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
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 : ResolveTestFixtureBase |
||||
{ |
||||
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,44 @@
@@ -0,0 +1,44 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Resolver |
||||
{ |
||||
public abstract class ResolveTestFixtureBase |
||||
{ |
||||
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(); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue