13 changed files with 221 additions and 185 deletions
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Resolver |
||||
{ |
||||
[TestFixture] |
||||
public class PythonLocalVariableResolverTests |
||||
{ |
||||
string typeName; |
||||
|
||||
void Resolve(string variableName, string code) |
||||
{ |
||||
PythonLocalVariableResolver resolver = new PythonLocalVariableResolver(); |
||||
typeName = resolver.Resolve(variableName, code); |
||||
} |
||||
|
||||
[Test] |
||||
public void Resolve_InstanceCreatedInCode_ReturnsInstanceType() |
||||
{ |
||||
string code = "a = Class1()"; |
||||
Resolve("a", code); |
||||
|
||||
Assert.AreEqual("Class1", typeName); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the NameExpression in the resolver is reset so the second assignment
|
||||
/// does not override the first.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void Resolve_TwoInstancesCreatedInCode_ReturnsFirstInstanceType() |
||||
{ |
||||
string code = |
||||
"a = Class1()\r\n" + |
||||
"b = Class2()"; |
||||
|
||||
Resolve("a", code); |
||||
|
||||
Assert.AreEqual("Class1", typeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Resolve_VariableIsAssignedToString_ReturnsNull() |
||||
{ |
||||
string code = "a = \"test\""; |
||||
Resolve("a", code); |
||||
|
||||
Assert.IsNull(typeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Resolve_CodeIsNull_ReturnsNull() |
||||
{ |
||||
Resolve("a", null); |
||||
Assert.IsNull(typeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Resolve_InstanceCreatedWithNamespace_ReturnsFullyQualifiedTypeName() |
||||
{ |
||||
string code = "a = Test.Class1()"; |
||||
Resolve("a", code); |
||||
Assert.AreEqual("Test.Class1", typeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Resolve_InstanceCreatedWithTwoPartsToNamespace_ReturnsFullyQualifiedTypeName() |
||||
{ |
||||
string code = "a = Root.Test.Class1()"; |
||||
Resolve("a", code); |
||||
Assert.AreEqual("Root.Test.Class1", typeName); |
||||
} |
||||
} |
||||
} |
@ -1,41 +0,0 @@
@@ -1,41 +0,0 @@
|
||||
// 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>
|
||||
/// Given code:
|
||||
///
|
||||
/// a = Test.Class1()
|
||||
///
|
||||
/// Where Test is the namespace of the class, check that the type of "a" can be obtained
|
||||
/// by the resolver.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ResolveClassInstanceWithNamespaceTestFixture |
||||
{ |
||||
[Test] |
||||
public void GetTypeOfInstance() |
||||
{ |
||||
string code = "a = Test.Class1()"; |
||||
PythonVariableResolver resolver = new PythonVariableResolver(); |
||||
Assert.AreEqual("Test.Class1", resolver.Resolve("a", @"C:\Projects\Test\Test.py", code)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetTypeOfInstanceWithTwoNamespaces() |
||||
{ |
||||
string code = "a = Root.Test.Class1()"; |
||||
PythonVariableResolver resolver = new PythonVariableResolver(); |
||||
Assert.AreEqual("Root.Test.Class1", resolver.Resolve("a", @"C:\Projects\Test\Test.py", code)); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue