Skip to content

Commit

Permalink
add namespace conflict tests for short name replacer and node to code (
Browse files Browse the repository at this point in the history
  • Loading branch information
aparajit-pratap authored Apr 28, 2020
1 parent 13eb6b2 commit 415fa68
Show file tree
Hide file tree
Showing 5 changed files with 354 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/DynamoCoreTests/NodeToCodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,36 @@ public void TestShortestQualifiedNameReplacer7()
Assert.AreEqual("Autodesk.Point.ByCoordinates(1, 2, 3)", expr2.RightNode.ToString());
}

[Test]
public void TestShortestQualifiedNameReplacerWithClassConflicts()
{
string libraryPath = "FFITarget.dll";
if (!CurrentDynamoModel.EngineController.LibraryServices.IsLibraryLoaded(libraryPath))
{
CurrentDynamoModel.EngineController.LibraryServices.ImportLibrary(libraryPath);
}

OpenModel(@"core\node2code\ShortenNodeNameWithClassConflicts.dyn");
var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;
var engine = CurrentDynamoModel.EngineController;

var result = engine.ConvertNodesToCode(nodes, nodes);
result = NodeToCodeCompiler.ConstantPropagationForTemp(result, Enumerable.Empty<string>());
NodeToCodeCompiler.ReplaceWithShortestQualifiedName(engine.LibraryServices.LibraryManagementCore.ClassTable, result.AstNodes);
Assert.IsNotNull(result);
Assert.IsNotNull(result.AstNodes);

var asts = result.AstNodes.ToList();
Assert.AreEqual(6, asts.Count);

Assert.IsTrue(asts.Any(x => (x as BinaryExpressionNode).RightNode.ToString() == "Revit.Elements.Parameter.Parameter()"));
Assert.IsTrue(asts.Any(x => (x as BinaryExpressionNode).RightNode.ToString() == "RevitFamily.Parameter.Parameter()"));
Assert.IsTrue(asts.Any(x => (x as BinaryExpressionNode).RightNode.ToString() == "archilab.Parameter.Parameter()"));
Assert.IsTrue(asts.Any(x => (x as BinaryExpressionNode).RightNode.ToString() == "RevitProject.Parameter.Parameter()"));
Assert.IsTrue(asts.Any(x => (x as BinaryExpressionNode).RightNode.ToString() == "Revit.Elements.Category.Category()"));
Assert.IsTrue(asts.Any(x => (x as BinaryExpressionNode).RightNode.ToString() == "Rhythm.Category.Category()"));
}

[Test]
public void TestShortestQualifiedNameReplacerTypedIdentiferFFITarget()
{
Expand Down
1 change: 1 addition & 0 deletions test/Engine/FFITarget/FFITarget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="GlobalClass.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="NamespaceConflictResolution.cs" />
<Compile Include="ReferenceThisTest.cs" />
<Compile Include="ReplicationTest.cs" />
<Compile Include="TestCSharpAttribute.cs" />
Expand Down
53 changes: 53 additions & 0 deletions test/Engine/FFITarget/NamespaceConflictResolution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

namespace Revit
{
namespace Elements
{
public class Category
{
}

public class Parameter
{ }
}

}

namespace Rhythm
{
namespace Revit.Elements
{
public class Category
{

}
}

}

namespace archilab
{
namespace Revit.Elements
{
public class Parameter
{
}
}
}

namespace Orchid
{
namespace RevitProject.Parameters
{
public class Parameter
{
}
}

namespace RevitFamily
{
public class Parameter
{
}
}
}
36 changes: 36 additions & 0 deletions test/Engine/ProtoTest/NameSpaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,42 @@ public void GetShortestUniqueNamespaces_FromNamespaceList()
Assert.AreEqual("Rhino.Point", shortNamespaces[namespaceList[1]]);
}

[Test]
[Category("UnitTests")]
public void GetShortestUniqueNamespaces_FromNamespaceList2()
{
var namespaceList = new List<Symbol>
{
new Symbol("Revit.Elements.Parameter"),
new Symbol("archilab.Revit.Elements.Parameter"),
new Symbol("Orchid.RevitProject.Parameters.Parameter"),
new Symbol("Orchid.RevitFamily.Parameter")
};
var shortNamespaces = Symbol.GetShortestUniqueNames(namespaceList);

Assert.AreEqual(4, shortNamespaces.Count);
Assert.AreEqual("Revit.Elements.Parameter", shortNamespaces[namespaceList[0]]);
Assert.AreEqual("archilab.Parameter", shortNamespaces[namespaceList[1]]);
Assert.AreEqual("RevitProject.Parameter", shortNamespaces[namespaceList[2]]);
Assert.AreEqual("RevitFamily.Parameter", shortNamespaces[namespaceList[3]]);
}

[Test]
[Category("UnitTests")]
public void GetShortestUniqueNamespaces_FromNamespaceList3()
{
var namespaceList = new List<Symbol>
{
new Symbol("Revit.Elements.Category"),
new Symbol("Rhythm.Revit.Elements.Category"),
};
var shortNamespaces = Symbol.GetShortestUniqueNames(namespaceList);

Assert.AreEqual(2, shortNamespaces.Count);
Assert.AreEqual("Revit.Elements.Category", shortNamespaces[namespaceList[0]]);
Assert.AreEqual("Rhythm.Category", shortNamespaces[namespaceList[1]]);
}

[Test]
[Category("UnitTests")]
public void GetShortestUniqueNamespaces_FromComplexNamespaceList()
Expand Down
234 changes: 234 additions & 0 deletions test/core/node2code/ShortenNodeNameWithClassConflicts.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
{
"Uuid": "2c283a25-3fd1-423a-bee1-1d2d1adefa7f",
"IsCustomNode": false,
"Description": null,
"Name": "ShortenNodeNameWithClassConflicts",
"ElementResolver": {
"ResolutionMap": {
"Revit.Elements.Parameter": {
"Key": "Revit.Elements.Parameter",
"Value": "FFITarget.dll"
},
"Revit.Elements.Category": {
"Key": "Revit.Elements.Category",
"Value": "FFITarget.dll"
}
}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "Rhythm.Revit.Elements.Category.Category",
"Id": "ed60b21eca3b4dd88708a2c104ec807f",
"Inputs": [],
"Outputs": [
{
"Id": "33ba6a986fd74a899d29af4c89325400",
"Name": "Category",
"Description": "Category",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Category.Category ( ): Category"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "Revit.Elements.Category.Category",
"Id": "69f31a43573d4996aefee5b9cac9f0e2",
"Inputs": [],
"Outputs": [
{
"Id": "898e809407e6455496a24919b6022dee",
"Name": "Category",
"Description": "Category",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Category.Category ( ): Category"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "Orchid.RevitProject.Parameters.Parameter.Parameter",
"Id": "4e010045d0e048a099ac4b6b2fddeea0",
"Inputs": [],
"Outputs": [
{
"Id": "17aeabd663e3460ebd2d5edbc4c6aead",
"Name": "Parameter",
"Description": "Parameter",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Parameter.Parameter ( ): Parameter"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "archilab.Revit.Elements.Parameter.Parameter",
"Id": "ad625791d42d4965acec8f02852af98d",
"Inputs": [],
"Outputs": [
{
"Id": "826e490b9ddd4783b58dca500063cec2",
"Name": "Parameter",
"Description": "Parameter",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Parameter.Parameter ( ): Parameter"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "Orchid.RevitFamily.Parameter.Parameter",
"Id": "8eefb20b94cb4f8aaf6187f18501aa15",
"Inputs": [],
"Outputs": [
{
"Id": "42d11c5cf3e14189a75734db9f6b61e6",
"Name": "Parameter",
"Description": "Parameter",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Parameter.Parameter ( ): Parameter"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "Revit.Elements.Parameter.Parameter",
"Id": "905b1b7f940a467e920783eb67b7dfdf",
"Inputs": [],
"Outputs": [
{
"Id": "ea6f151411744227ba30c5bed185e46a",
"Name": "Parameter",
"Description": "Parameter",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Parameter.Parameter ( ): Parameter"
}
],
"Connectors": [],
"Dependencies": [],
"NodeLibraryDependencies": [],
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.7.0.8460",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"NodeViews": [
{
"ShowGeometry": true,
"Name": "Category.Category",
"Id": "ed60b21eca3b4dd88708a2c104ec807f",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 615.0,
"Y": 617.0
},
{
"ShowGeometry": true,
"Name": "Category.Category",
"Id": "69f31a43573d4996aefee5b9cac9f0e2",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 591.0,
"Y": 503.0
},
{
"ShowGeometry": true,
"Name": "Parameter.Parameter",
"Id": "4e010045d0e048a099ac4b6b2fddeea0",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 268.0,
"Y": 406.0
},
{
"ShowGeometry": true,
"Name": "Parameter.Parameter",
"Id": "ad625791d42d4965acec8f02852af98d",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 205.0,
"Y": 286.0
},
{
"ShowGeometry": true,
"Name": "Parameter.Parameter",
"Id": "8eefb20b94cb4f8aaf6187f18501aa15",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 188.0,
"Y": 162.0
},
{
"ShowGeometry": true,
"Name": "Parameter.Parameter",
"Id": "905b1b7f940a467e920783eb67b7dfdf",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 155.0,
"Y": 25.0
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}

0 comments on commit 415fa68

Please sign in to comment.