public void Test_Translate_Constructor() { FunctionModel a = GraphModel.CreateFunction("A", Vector2.zero); // Debug.Log(...) MethodInfo logMethod = typeof(Debug).GetMethod(nameof(Debug.Log), new[] { typeof(object) }); Assume.That(logMethod, Is.Not.Null); FunctionCallNodeModel log = a.CreateStackedNode <FunctionCallNodeModel>("Log", 0, SpawnFlags.Default, n => n.MethodInfo = logMethod); // new Vector4(x, y) ConstructorInfo ctor = typeof(Vector4).GetConstructor(new[] { typeof(float), typeof(float) }); Assume.That(ctor, Is.Not.Null); FunctionCallNodeModel newV4 = GraphModel.CreateNode <FunctionCallNodeModel>("New Vector4", Vector2.left * 200, SpawnFlags.Default, n => n.MethodInfo = ctor); GraphModel.CreateEdge(log.GetParameterPorts().First(), newV4.OutputPort); var b = new RoslynTranslator(Stencil); var c = b.Translate(GraphModel, CompilationOptions.Default); SyntaxNode d = c.GetRoot(); StatementSyntax stmt = d.DescendantNodes().OfType <MethodDeclarationSyntax>().First(n => n.Identifier.ValueText == "A") .Body.Statements.First(); ExpressionSyntax arg = ((InvocationExpressionSyntax)((ExpressionStatementSyntax)stmt).Expression).ArgumentList.Arguments.Single().Expression; Assert.That(arg.ToFullString(), Is.EqualTo("new UnityEngine.Vector4(0F, 0F)")); }
public void MovingAReturnNodeToAVoidFunctionShouldRemoveItsValuePortType([Values] TestingMode mode) { var a = GraphModel.CreateFunction("A", Vector2.left); a.ReturnType = TypeHandle.Float; var ret = a.CreateStackedNode <ReturnNodeModel>(); var b = GraphModel.CreateFunction("B", Vector2.left); b.ReturnType = TypeHandle.Void; TestPrereqActionPostreq(mode, () => { RefreshReference(ref a); RefreshReference(ref b); RefreshReference(ref ret); Assert.That(ret.InputPort, Is.Not.Null); Assert.That(ret.InputPort.DataType, Is.EqualTo(TypeHandle.Float)); return(new MoveStackedNodesAction(new[] { ret }, b, 0)); }, () => { RefreshReference(ref a); RefreshReference(ref b); RefreshReference(ref ret); Assert.That(ret.InputPort, Is.Null); }); }
public void Test_CreateFunctionVariableDeclarationAction([Values] TestingMode mode) { var method = GraphModel.CreateFunction("TestFunction", Vector2.zero); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(0)); return(new CreateFunctionVariableDeclarationAction(method, "toto", typeof(int).GenerateTypeHandle(Stencil))); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(1)); }); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(1)); return(new CreateFunctionVariableDeclarationAction(method, "foo", typeof(float).GenerateTypeHandle(Stencil))); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(2)); }); }
public void NestedIfs() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c; CreateIfThenElseStacks(a, "b", "c", out b, out c); var d = GraphModel.CreateStack("d", Vector2.left); var e = GraphModel.CreateStack("e", Vector2.left); b.CreateStackedNode <Type0FakeNodeModel>("b"); c.CreateStackedNode <Type0FakeNodeModel>("c"); d.CreateStackedNode <Type0FakeNodeModel>("d"); e.CreateStackedNode <Type0FakeNodeModel>("e"); var cIfNode = c.CreateStackedNode <IfConditionNodeModel>("if_c"); GraphModel.CreateEdge(b.InputPorts[0], cIfNode.ThenPort); GraphModel.CreateEdge(d.InputPorts[0], cIfNode.ElsePort); GraphModel.CreateEdge(e.InputPorts[0], b.OutputPorts[0]); GraphModel.CreateEdge(e.InputPorts[0], d.OutputPorts[0]); // as C has an if node, a common descendant of (C,X) must be a descendant of (B,D,X), here E Assert.That(RoslynTranslator.FindCommonDescendant(a, a, c), Is.EqualTo(e)); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(e)); }
public void Test_DeleteElementsAction_MiniGraph([Values] TestingMode mode) { var method = GraphModel.CreateFunction("TestFunction", Vector2.zero); var node0 = method.CreateStackedNode <Type0FakeNodeModel>("Fake0", 0); var node1 = GraphModel.CreateNode <Type0FakeNodeModel>("Fake1", Vector2.zero); GraphModel.CreateEdge(node0.Input0, node1.Output0); TestPrereqActionPostreq(mode, () => { Assert.That(GetStackCount(), Is.EqualTo(1)); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); var n0 = GetStackedNode(0, 0) as Type0FakeNodeModel; var n1 = GetNode(1) as Type0FakeNodeModel; Assert.NotNull(n0); Assert.NotNull(n1); Assert.That(n0.Input0, Is.ConnectedTo(n1.Output0)); return(new DeleteElementsAction(method, node0, node1)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(0)); Assert.That(GetStackCount(), Is.EqualTo(0)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); }); }
public void TestFunctionMembers(string query, Type type, SpawnFlags mode) { var funcModel = GraphModel.CreateFunction("TestFunc", Vector2.zero); funcModel.CreateFunctionVariableDeclaration("var", typeof(int).GenerateTypeHandle(GraphModel.Stencil)); funcModel.CreateAndRegisterFunctionParameterDeclaration("par", typeof(string).GenerateTypeHandle(GraphModel.Stencil)); var db = new GraphElementSearcherDatabase(Stencil) .AddFunctionMembers(funcModel) .Build(); var results = db.Search(query, out _); Assert.AreEqual(1, results.Count); var item = (GraphNodeModelSearcherItem)results[0]; var data = (TypeSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.Variable, data.Target); Assert.AreEqual(Stencil.GenerateTypeHandle(type), data.Type); CreateNodesAndValidateGraphModel(item, mode, initialNodes => { var node = GraphModel.NodeModels.OfType <VariableNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count); Assert.AreEqual(type, node.DataType.Resolve(Stencil)); }); }
public void UnjoinedIfHasNoCommonDescendant() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c; CreateIfThenElseStacks(a, "b", "c", out b, out c); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.Null); }
void CreateStackAndLogs(out StackBaseModel stack, out FunctionCallNodeModel[] log, int logCount = 1) { stack = GraphModel.CreateFunction("F", Vector2.zero); log = new FunctionCallNodeModel[logCount]; for (int i = 0; i < logCount; i++) { log[i] = stack.CreateFunctionCallNode(k_LogMethodInfo); } }
public void Test_Translate_SimpleResizableMethod() { GraphModel.CreateFunction("A", Vector2.zero); var b = new RoslynTranslator(Stencil); var c = b.Translate(GraphModel, CompilationOptions.Default); var d = c.GetRoot(); Assert.That(d.DescendantNodes().OfType <MethodDeclarationSyntax>().Where(n => n.Identifier.ValueText == "A").ToArray().Length, Is.EqualTo(1)); Assert.That(d.DescendantNodes().OfType <ParameterSyntax>().ToArray().Length, Is.EqualTo(0)); }
public void NoLoopTest1() { var a = GraphModel.CreateFunction("A", Vector2.zero); CreateIfThenElseStacks(a, "b", "c", out var b, out var c); CreateIfThenElseStacks(b, "d", null, out var d, out _); GraphModel.CreateEdge(d.InputPorts[0], c.OutputPorts[0]); AssertTranslationDoesNotThrowsLoopDetectedException(); }
public void Test_RemoveSetPropertyMemberKeepsEdges([Values] TestingMode mode) { // test that removing a SetProperty member doesn't break the edge with it's Instance // i.e. here: check that removing Position keeps the link with Transform // |_TestFunction_____| // (Transform)---+-o Set Property | // | o Position | VariableDeclarationModel trDecl = GraphModel.CreateGraphVariableDeclaration("tr", typeof(Transform).GenerateTypeHandle(Stencil), true); IVariableModel trVar = GraphModel.CreateVariableNode(trDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); GraphModel.CreateEdge(setters.InstancePort, trVar.OutputPort); PropertyInfo propertyToAdd = typeof(Transform).GetProperty("position"); var newMember = new TypeMember { Path = new List <string> { propertyToAdd?.Name }, Type = propertyToAdd.GetUnderlyingType().GenerateTypeHandle(Stencil) }; setters.AddMember(newMember); TestPrereqActionPostreq(mode, () => { RefreshReference(ref method); RefreshReference(ref setters); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.InputsByDisplayOrder.Count, Is.EqualTo(2)); Assert.That(setters.Members.Count, Is.EqualTo(1)); return(new EditPropertyGroupNodeAction( EditPropertyGroupNodeAction.EditType.Remove, setters, newMember)); }, () => { RefreshReference(ref method); RefreshReference(ref setters); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.InputsByDisplayOrder.Count, Is.EqualTo(1)); Assert.That(setters.Members.Count, Is.EqualTo(0)); }); }
public void SimpleIf() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c, d; CreateIfThenElseStacks(a, "b", "c", out b, out c); JoinStacks(b, c, "d", out d); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(d)); }
public void Test_MoveVariableDeclarationAction([Values] TestingMode mode) { var function0 = GraphModel.CreateFunction("Function0", Vector2.zero); var function1 = GraphModel.CreateFunction("Function1", Vector2.zero); var declaration = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true); // Move from graph to function TestPrereqActionPostreq(mode, () => { Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(function0.FunctionVariableModels.Count(), Is.EqualTo(0)); Assert.That(function1.FunctionVariableModels.Count(), Is.EqualTo(0)); return(new MoveVariableDeclarationAction(declaration, function0)); }, () => { Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0)); Assert.That(function0.FunctionVariableModels.Count(), Is.EqualTo(1)); Assert.That(function1.FunctionVariableModels.Count(), Is.EqualTo(0)); }); // Move from function to function TestPrereqActionPostreq(mode, () => { Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0)); Assert.That(function0.FunctionVariableModels.Count(), Is.EqualTo(1)); Assert.That(function1.FunctionVariableModels.Count(), Is.EqualTo(0)); return(new MoveVariableDeclarationAction(declaration, function1)); }, () => { Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0)); Assert.That(function0.FunctionVariableModels.Count(), Is.EqualTo(0)); Assert.That(function1.FunctionVariableModels.Count(), Is.EqualTo(1)); }); // Move from function to graph TestPrereqActionPostreq(mode, () => { Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0)); Assert.That(function0.FunctionVariableModels.Count(), Is.EqualTo(0)); Assert.That(function1.FunctionVariableModels.Count(), Is.EqualTo(1)); return(new MoveVariableDeclarationAction(declaration, GraphModel)); }, () => { Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(function0.FunctionVariableModels.Count(), Is.EqualTo(0)); Assert.That(function1.FunctionVariableModels.Count(), Is.EqualTo(0)); }); }
public void IfNoThen() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c; CreateIfThenElseStacks(a, "b", "c", out b, out c); GraphModel.CreateEdge(b.InputPorts[0], c.OutputPorts[0]); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(b)); }
public void LoopTest1() { var a = GraphModel.CreateFunction("A", Vector2.zero); CreateIfThenElseStacks(a, "b", "c", out var b, out var c); CreateIfThenElseStacks(b, "d", "e", out var d, out var e); JoinStacks(d, e, "f", out var f); CreateIfThenElseStacks(f, "g", "h", out var g, out var h); GraphModel.CreateEdge(e.InputPorts[0], c.OutputPorts[0]); GraphModel.CreateEdge(c.InputPorts[0], g.OutputPorts[0]); AssertTranslationThrowsLoopDetectedException(); }
public void Test_DuplicateFunctionVariableDeclarationsAction([Values] TestingMode mode) { var method = GraphModel.CreateFunction("TestFunction", Vector2.zero); var declaration0 = method.CreateFunctionVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil)); var declaration1 = method.CreateFunctionVariableDeclaration("decl1", typeof(int).GenerateTypeHandle(Stencil)); var declaration2 = method.CreateAndRegisterFunctionParameterDeclaration("decl2", typeof(int).GenerateTypeHandle(Stencil)); var declaration3 = method.CreateAndRegisterFunctionParameterDeclaration("decl3", typeof(int).GenerateTypeHandle(Stencil)); TestPrereqActionPostreq(mode, () => { RefreshReference(ref method); Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(2)); Assert.That(method.FunctionParameterModels.Count(), Is.EqualTo(2)); return(new DuplicateFunctionVariableDeclarationsAction(method, new List <IVariableDeclarationModel>() { declaration0, declaration1 })); }, () => { RefreshReference(ref method); Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(4)); Assert.That(method.FunctionParameterModels.Count(), Is.EqualTo(2)); }); TestPrereqActionPostreq(mode, () => { RefreshReference(ref method); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(4)); Assert.That(method.FunctionParameterModels.Count(), Is.EqualTo(2)); return(new DuplicateFunctionVariableDeclarationsAction(method, new List <IVariableDeclarationModel>() { declaration2, declaration3 })); }, () => { RefreshReference(ref method); Assert.That(method.FunctionVariableModels.Count(), Is.EqualTo(4)); Assert.That(method.FunctionParameterModels.Count(), Is.EqualTo(4)); }); }
public void Test_Translate_DetectInfiniteLoop() { var function = GraphModel.CreateFunction("Function", Vector2.zero); var stack0 = GraphModel.CreateStack(string.Empty, Vector2.zero); var stack1 = GraphModel.CreateStack(string.Empty, Vector2.zero); GraphModel.CreateEdge(stack0.InputPorts[0], function.OutputPort); GraphModel.CreateEdge(stack0.InputPorts[0], stack1.OutputPorts[0]); GraphModel.CreateEdge(stack1.InputPorts[0], stack0.OutputPorts[0]); var b = new RoslynTranslator(Stencil); Assert.Throws <LoopDetectedException>(() => b.Translate(GraphModel, CompilationOptions.Default)); }
public void ThreeWayIf() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c, d, e, f; CreateIfThenElseStacks(a, "b", "c", out b, out c); CreateIfThenElseStacks(c, "d", "e", out d, out e); JoinStacks(d, e, "f", out f); GraphModel.CreateEdge(f.InputPorts[0], b.OutputPorts[0]); Assert.That(RoslynTranslator.FindCommonDescendant(a, d, e), Is.EqualTo(f)); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(f)); }
public void Test_Translate_UsingDirective() { var type = typeof(TestObject); var a = GraphModel.CreateFunction("A", Vector2.zero); var i = typeof(TestObject).GetMethod(nameof(TestObject.DoStuff)); a.CreateStackedNode <FunctionCallNodeModel>("Do", 0, SpawnFlags.Default, n => n.MethodInfo = i); var b = new RoslynTranslator(Stencil); var c = b.Translate(GraphModel, CompilationOptions.Default); var d = c.GetRoot(); var ud = d.DescendantNodes().OfType <UsingDirectiveSyntax>(); Assert.That(ud.Count(n => n.Name.ToString() == type.Namespace), Is.EqualTo(1)); }
public void Test_Translate_SimpleMethod2Params() { var a = GraphModel.CreateFunction("A", Vector2.zero); a.CreateFunctionVariableDeclaration("l", typeof(int).GenerateTypeHandle(GraphModel.Stencil)); a.CreateAndRegisterFunctionParameterDeclaration("a", typeof(int).GenerateTypeHandle(GraphModel.Stencil)); var b = new RoslynTranslator(Stencil); var c = b.Translate(GraphModel, CompilationOptions.Default); var d = c.GetRoot(); Assert.That(d.DescendantNodes().OfType <MethodDeclarationSyntax>().Where(n => n.Identifier.ValueText == "A").ToArray().Length, Is.EqualTo(1)); Assert.That(d.DescendantNodes().OfType <ParameterSyntax>().ToArray().Length, Is.EqualTo(1)); Assert.That(d.DescendantNodes().OfType <LocalDeclarationStatementSyntax>().ToArray().Length, Is.EqualTo(1)); }
public void TwoLevelIfs() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c, d, e, f, g, h, i, j; CreateIfThenElseStacks(a, "b", "c", out b, out c); CreateIfThenElseStacks(b, "d", "e", out d, out e); CreateIfThenElseStacks(c, "f", "g", out f, out g); JoinStacks(d, e, "h", out h); JoinStacks(f, g, "i", out i); JoinStacks(h, i, "h", out j); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(j)); Assert.That(RoslynTranslator.FindCommonDescendant(a, d, e), Is.EqualTo(h)); Assert.That(RoslynTranslator.FindCommonDescendant(a, f, g), Is.EqualTo(i)); Assert.That(RoslynTranslator.FindCommonDescendant(a, d, f), Is.EqualTo(j)); }
public void FourWayJoin() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c, d, e, f, g, h; CreateIfThenElseStacks(a, "b", "c", out b, out c); CreateIfThenElseStacks(b, "d", "e", out d, out e); CreateIfThenElseStacks(c, "f", "g", out f, out g); JoinStacks(d, e, "h", out h); GraphModel.CreateEdge(h.InputPorts[0], f.OutputPorts[0]); GraphModel.CreateEdge(h.InputPorts[0], g.OutputPorts[0]); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(h)); Assert.That(RoslynTranslator.FindCommonDescendant(a, d, e), Is.EqualTo(h)); Assert.That(RoslynTranslator.FindCommonDescendant(a, f, g), Is.EqualTo(h)); Assert.That(RoslynTranslator.FindCommonDescendant(a, d, f), Is.EqualTo(h)); }
public void IfNoThenElseIfNoThen() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c; CreateIfThenElseStacks(a, "b", "c", out b, out c); b.CreateStackedNode <Type0FakeNodeModel>("b"); c.CreateStackedNode <Type0FakeNodeModel>("c"); var cIfNode = c.CreateStackedNode <IfConditionNodeModel>("if_c"); GraphModel.CreateEdge(b.InputPorts[0], cIfNode.ThenPort); // as C has an if node with a disconnect else branch, B cannot be a descendant of both branches // so common(b,c) should return null Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.Null); }
public void Test_DisconnectSetPropertyKeepsPortType([Values] TestingMode mode) { VariableDeclarationModel trDecl = GraphModel.CreateGraphVariableDeclaration("tr", typeof(Transform).GenerateTypeHandle(Stencil), true); IVariableModel trVar = GraphModel.CreateVariableNode(trDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); GraphModel.CreateEdge(setters.InstancePort, trVar.OutputPort); setters.AddMember( new TypeMember { Path = new List <string> { "position" }, Type = Stencil.GenerateTypeHandle(typeof(Vector3)) } ); IConstantNodeModel constToken = GraphModel.CreateConstantNode("v3", typeof(Vector3).GenerateTypeHandle(Stencil), Vector2.left * 200); IEdgeModel edge = GraphModel.CreateEdge(setters.GetPortsForMembers().First(), constToken.OutputPort); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3))); return(new DeleteElementsAction(edge)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3))); }); }
public void Test_CreateSetPropertyGroupNodeAction([Values] TestingMode mode) { FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.NodeModels.Count(), Is.EqualTo(0)); return(new CreateSetPropertyGroupNodeAction(method, 0)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); }); }
public void ExtractTwoNodesConnectedToTheSameNodeDifferentPorts([Values] TestingMode mode) { var stack = GraphModel.CreateFunction("F", Vector2.zero); var set = stack.CreateStackedNode <SetVariableNodeModel>("set"); var varA = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero); var varB = GraphModel.CreateVariableNode(m_BDecl, Vector2.zero); GraphModel.CreateEdge(set.InstancePort, varA.OutputPort); GraphModel.CreateEdge(set.ValuePort, varB.OutputPort); Undo.IncrementCurrentGroup(); TestPrereqActionPostreq(mode, () => { Refresh(); set = stack.NodeModels.OfType <SetVariableNodeModel>().Single(); Assert.That(GraphModel.NodeModels.OfType <MacroRefNodeModel>().Count(), Is.Zero); Assert.That(set.InstancePort, Is.ConnectedTo(varA.OutputPort)); Assert.That(set.ValuePort, Is.ConnectedTo(varB.OutputPort)); return(new RefactorExtractMacroAction(new List <IGraphElementModel> { varA, varB }, Vector2.zero, null)); }, () => { Refresh(); var macroRef = GraphModel.NodeModels.OfType <MacroRefNodeModel>().Single(); Assert.That(macroRef, Is.Not.Null); var macroRefOutputPorts = macroRef.OutputVariablePorts.ToList(); Assert.That(macroRefOutputPorts.Count, Is.EqualTo(2)); Assert.That(macroRefOutputPorts[0], Is.ConnectedTo(set.InstancePort)); Assert.That(macroRefOutputPorts[1], Is.ConnectedTo(set.ValuePort)); Assert.That(macroRef.GraphAssetModel.GraphModel.Stencil, Is.TypeOf <MacroStencil>()); Assert.That(((MacroStencil)macroRef.GraphAssetModel.GraphModel.Stencil).ParentType, Is.EqualTo(GraphModel.Stencil.GetType())); }); void Refresh() { RefreshReference(ref stack); RefreshReference(ref set); RefreshReference(ref varA); RefreshReference(ref varB); } }
public void Test_DisconnectSetPropertyInstanceSetsRightPortType(TestingMode mode, int inputIndex, Type expectedPortType) { VariableDeclarationModel goDecl = GraphModel.CreateGraphVariableDeclaration("go", typeof(GameObject).GenerateTypeHandle(Stencil), true); IVariableModel goVar = GraphModel.CreateVariableNode(goDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); IEdgeModel edge = GraphModel.CreateEdge(setters.InstancePort, goVar.OutputPort); PropertyInfo propertyInfo = typeof(Transform).GetProperty("position"); var newMember = new TypeMember { Path = new List <string> { propertyInfo?.Name }, Type = typeof(Transform).GenerateTypeHandle(Stencil) }; setters.AddMember(newMember); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil))); return(new DeleteElementsAction(edge)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.InstancePort.DataType, Is.EqualTo(TypeHandle.Unknown)); Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil))); }); }
public void ChangingAFunctionReturnTypeToVoidShouldRemoveItsReturnNodeValueType([Values] TestingMode mode) { var a = GraphModel.CreateFunction("A", Vector2.left); a.ReturnType = TypeHandle.Float; var ret = a.CreateStackedNode <ReturnNodeModel>(); TestPrereqActionPostreq(mode, () => { RefreshReference(ref a); RefreshReference(ref ret); Assert.That(ret.InputPort, Is.Not.Null); Assert.That(ret.InputPort.DataType, Is.EqualTo(TypeHandle.Float)); return(new UpdateFunctionReturnTypeAction(a, TypeHandle.Void)); }, () => { RefreshReference(ref a); RefreshReference(ref ret); Assert.That(ret.InputPort, Is.Null); }); }
public IEnumerator Test_BlackboardLocalScopeShowsAllVariablesFromSelection() { Stencil stencil = GraphModel.Stencil; var functionModel = GraphModel.CreateFunction("function", new Vector2(200, 50)); var functionVariable = functionModel.CreateFunctionVariableDeclaration("l", typeof(int).GenerateTypeHandle(stencil)); var functionParameter = functionModel.CreateAndRegisterFunctionParameterDeclaration("a", typeof(int).GenerateTypeHandle(stencil)); var stackModel1 = GraphModel.CreateStack("stack1", new Vector2(200, 200)); var stack1Input = stackModel1.InputPorts[0]; var stack1Output = stackModel1.OutputPorts[0]; var stackModel2 = GraphModel.CreateStack("stack2", new Vector2(200, 400)); var stack2Input = stackModel2.InputPorts[0]; Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Store.Dispatch(new CreateEdgeAction(stack1Input, functionModel.OutputPort)); yield return(null); Store.Dispatch(new CreateEdgeAction(stack2Input, stack1Output)); yield return(null); GraphView.selection.Add(GetGraphElement(5)); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Blackboard blackboard = GraphView.UIController.Blackboard; var allVariables = GraphView.UIController.GetAllVariableDeclarationsFromSelection(GraphView.selection).ToList(); Assert.That(allVariables.Find(x => (VariableDeclarationModel)x.Item1 == functionVariable) != null); Assert.That(allVariables.Find(x => (VariableDeclarationModel)x.Item1 == functionParameter) != null); // Test assumes that section displays var blackboardVariableFields = blackboard.Query <BlackboardVariableField>().ToList(); Assert.That(blackboardVariableFields.Find(x => (VariableDeclarationModel)x.VariableDeclarationModel == functionVariable) != null); Assert.That(blackboardVariableFields.Find(x => (VariableDeclarationModel)x.VariableDeclarationModel == functionParameter) != null); }
// create a function bool IsIntEven(int i) // if ((i % 2) == 0) { return true; } else { return false; } // the goal is to have 2 different return nodes depending on a parameter FunctionModel CreateIsIntEvenFunction() { // define function FunctionModel method = GraphModel.CreateFunction("IsIntEven", Vector2.zero); method.ReturnType = typeof(bool).GenerateTypeHandle(GraphModel.Stencil); VariableDeclarationModel paramI = method.CreateAndRegisterFunctionParameterDeclaration("i", typeof(int).GenerateTypeHandle(GraphModel.Stencil)); // add if/then/else structure IfConditionNodeModel if0 = CreateIfThenElseStacks(method, out var then0, out var else0); // if (i % 2 == 0) var binOpNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Modulo, Vector2.zero); IVariableModel varI = GraphModel.CreateVariableNode(paramI, Vector2.left); var const2 = CreateConstantIntNode(2); GraphModel.CreateEdge(binOpNode.InputPortA, varI.OutputPort); GraphModel.CreateEdge(binOpNode.InputPortB, const2.OutputPort); var equalNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Equals, Vector2.zero); var const0 = CreateConstantIntNode(0); GraphModel.CreateEdge(equalNode.InputPortA, binOpNode.OutputPort); GraphModel.CreateEdge(equalNode.InputPortB, const0.OutputPort); GraphModel.CreateEdge(if0.IfPort, equalNode.OutputPort); // then return true var returnTrue = then0.CreateStackedNode <ReturnNodeModel>("return true"); var constTrue = CreateConstantBoolNode(true); GraphModel.CreateEdge(returnTrue.InputPort, constTrue.OutputPort); // else return false var returnFalse = else0.CreateStackedNode <ReturnNodeModel>("return false"); var constFalse = CreateConstantBoolNode(false); GraphModel.CreateEdge(returnFalse.InputPort, constFalse.OutputPort); return(method); }