Example #1
0
        public void LookupResolvedName_ForPartialNestedExpression_RewriteAst()
        {
            var astNodes = CoreUtils.BuildASTList(core, "p = Autodesk.Point.ByCoordinates(Autodesk.Point.ByCoordinates(x, y, z).X, y, z).X;");

            var elementResolver = new ElementResolver();

            elementResolver.AddToResolutionMap("Autodesk.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            var newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p = Autodesk.DS.Geometry.Point.ByCoordinates(Autodesk.DS.Geometry.Point.ByCoordinates(x, y, z).X, y, z).X;\n", newNodes.ElementAt(0).ToString());

            /////////////////////////////////////
            astNodes = CoreUtils.BuildASTList(core, "p = Autodesk.DS.Point.ByCoordinates(Autodesk.Point.ByCoordinates(x, y, z).X, y, z).X;");

            elementResolver = new ElementResolver();
            elementResolver.AddToResolutionMap("Autodesk.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");
            elementResolver.AddToResolutionMap("Autodesk.DS.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p = Autodesk.DS.Geometry.Point.ByCoordinates(Autodesk.DS.Geometry.Point.ByCoordinates(x, y, z).X, y, z).X;\n", newNodes.ElementAt(0).ToString());

            //////////////////////////////////////
            astNodes = CoreUtils.BuildASTList(core, "p = Autodesk.DS.Geometry.Point.ByCoordinates(Autodesk.Point.ByCoordinates(x, y, z).X, y, z).X;");

            elementResolver = new ElementResolver();
            elementResolver.AddToResolutionMap("Autodesk.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");
            elementResolver.AddToResolutionMap("Autodesk.DS.Geometry.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p = Autodesk.DS.Geometry.Point.ByCoordinates(Autodesk.DS.Geometry.Point.ByCoordinates(x, y, z).X, y, z).X;\n", newNodes.ElementAt(0).ToString());
        }
Example #2
0
        public void LookupResolvedName_ForAssociativeBlock_RewriteAst()
        {
            var code =
                "c = [Associative]" +
                "{" +
                "   a = [1, 2, 3, 4];" +
                "   b = Autodesk.Point.ByCoordinates(a);" +
                "   return = b;" +
                "}";

            var elementResolver = new ElementResolver();

            elementResolver.AddToResolutionMap("Autodesk.Point", "Autodesk.DesignScript.Geometry.Point",
                                               "Protogeometry.dll");

            var astNodes = CoreUtils.BuildASTList(core, code);
            var newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes).ToList();

            var lbn = ((BinaryExpressionNode)newNodes[0]).RightNode as LanguageBlockNode;

            Assert.IsNotNull(lbn);

            var cbn = lbn.CodeBlockNode as CodeBlockNode;

            Assert.IsNotNull(cbn);

            Assert.AreEqual("b = Autodesk.DesignScript.Geometry.Point.ByCoordinates(a);\n",
                            cbn.Body[1].ToString());
        }
Example #3
0
        public void LookupResolvedName_ForPartialTypedIdentifier_RewriteAst()
        {
            var astNodes = CoreUtils.BuildASTList(core, "p : Autodesk.Point;");

            var elementResolver = new ElementResolver();

            elementResolver.AddToResolutionMap("Autodesk.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            var newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p : Autodesk.DS.Geometry.Point", newNodes.ElementAt(0).ToString());

            astNodes = CoreUtils.BuildASTList(core, "p : Autodesk.DS.Point;");

            elementResolver = new ElementResolver();
            elementResolver.AddToResolutionMap("Autodesk.DS.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p : Autodesk.DS.Geometry.Point", newNodes.ElementAt(0).ToString());

            astNodes = CoreUtils.BuildASTList(core, "p : Autodesk.DS.Geometry.Point;");

            elementResolver = new ElementResolver();
            elementResolver.AddToResolutionMap("Autodesk.DS.Geometry.Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p : Autodesk.DS.Geometry.Point", newNodes.ElementAt(0).ToString());
        }
Example #4
0
        public void LookupResolvedName_FromElementResolver_RewriteAst()
        {
            var astNodes = CoreUtils.BuildASTList(core, "p = Point.ByCoordinates(0,0,0);");

            var elementResolver = new ElementResolver();

            elementResolver.AddToResolutionMap("Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            var newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p = Autodesk.DS.Geometry.Point.ByCoordinates(0, 0, 0);\n", newNodes.ElementAt(0).ToString());
        }
Example #5
0
        public void LookupResolvedName_FromElementResolver_RewriteAst2()
        {
            // TODO pratapa: Return to fix test with Dictionary.ValueAtKey method

            var astNodes = CoreUtils.BuildASTList(core, "p = Geometry.Point.ByCoordinates(0,0,0)[0];");

            var elementResolver = new ElementResolver();

            elementResolver.AddToResolutionMap("Point", "Autodesk.DS.Geometry.Point", "Protogeometry.dll");

            var newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("p = Autodesk.DS.Geometry.Point.ByCoordinates(0, 0, 0)[0];\n", newNodes.ElementAt(0).ToString());
        }
Example #6
0
        public void LookupResolvedName_ForFunctionDefinition_RewriteAst()
        {
            var code =
                "def foo()" +
                "{" +
                "   return = Autodesk.DesignScript.Geometry.Point.ByCoordinates();" +
                "}" +
                "a = foo();";

            var elementResolver = new ElementResolver();

            elementResolver.AddToResolutionMap("Point", "Autodesk.DesignScript.Geometry.Point", "Protogeometry.dll");

            var astNodes = CoreUtils.BuildASTList(core, code);
            var newNodes = ElementRewriter.RewriteElementNames(core.ClassTable, elementResolver, astNodes).ToList();

            Assert.AreEqual("return = Autodesk.DesignScript.Geometry.Point.ByCoordinates();\n",
                            ((FunctionDefinitionNode)newNodes[0]).FunctionBody.ToString());
        }