Esempio n. 1
0
        public void ParseMethodBody()
        {
            TypeBodyParser parser = new TypeBodyParser();

            const string input = @"
                int GetValue(int someValue, System.Collections.Generic.Dictionary<int, UnityEngine.Vector3> dict) {
                    var f;
                    int localVar = 4;
                    string str;
                    return someValue;
                }
            ";

            TypeBodyNode astNode = parser.Parse(input, "", 0);

            Assert.AreEqual(1, astNode.nodes.size);
            MethodNode methodNode = (MethodNode)astNode.nodes[0];

            Assert.AreEqual(4, methodNode.body.statements.size);
            Assert.IsInstanceOf <LocalVariableNode>(methodNode.body.statements[0]);
            Assert.IsInstanceOf <LocalVariableNode>(methodNode.body.statements[1]);
            Assert.IsInstanceOf <LocalVariableNode>(methodNode.body.statements[2]);
            Assert.IsInstanceOf <ReturnStatementNode>(methodNode.body.statements[3]);
            LocalVariableNode   f        = (LocalVariableNode)methodNode.body.statements[0];
            LocalVariableNode   localVar = (LocalVariableNode)methodNode.body.statements[1];
            LocalVariableNode   str      = (LocalVariableNode)methodNode.body.statements[2];
            ReturnStatementNode retn     = (ReturnStatementNode)methodNode.body.statements[3];

            Assert.AreEqual("f", f.name);
            Assert.AreEqual(default, f.typeLookup.typeName);
Esempio n. 2
0
        public void ParseFieldWithAttribute()
        {
            TypeBodyParser parser = new TypeBodyParser();

            const string input = @"
                [Required]
                System.Collections.Generic.List<UnityEngine.Vector3> v2;

                [Attr0]
                [Attr1]
                int value;
                string str;

            ";

            TypeBodyNode astNode = parser.Parse(input, "", 0);
            LightList <AttributeNode> attributes = ((FieldNode)astNode.nodes[0]).attributes;

            Assert.AreEqual(3, astNode.nodes.size);
            Assert.AreEqual(1, attributes.size);
            Assert.AreEqual("v2", ((FieldNode)astNode.nodes[0]).name);
            Assert.AreEqual("Required", attributes[0].typeLookup.typeName);
            attributes = ((FieldNode)astNode.nodes[1]).attributes;
            Assert.AreEqual(2, attributes.size);
            Assert.AreEqual("Attr0", attributes[0].typeLookup.typeName);
            Assert.AreEqual("Attr1", attributes[1].typeLookup.typeName);

            Assert.AreEqual("value", ((FieldNode)astNode.nodes[1]).name);
            Assert.AreEqual("str", ((FieldNode)astNode.nodes[2]).name);
        }
Esempio n. 3
0
        public void ParseField()
        {
            TypeBodyParser parser = new TypeBodyParser();

            const string input = @"
                int v0;
                string v1;
                System.Collections.Generic.List<UnityEngine.Vector3> v2;
            ";

            TypeBodyNode astNode = parser.Parse(input, "", 0);

            Assert.AreEqual(3, astNode.nodes.size);
            Assert.AreEqual("v0", ((FieldNode)astNode.nodes[0]).name);
            Assert.AreEqual("v1", ((FieldNode)astNode.nodes[1]).name);
            Assert.AreEqual("v2", ((FieldNode)astNode.nodes[2]).name);
        }
Esempio n. 4
0
        public void ParseMethod_Args0()
        {
            TypeBodyParser parser = new TypeBodyParser();

            const string input = @"
                int GetValue() {
                    return someValue;
                }
            ";

            TypeBodyNode astNode = parser.Parse(input, "", 0);

            Assert.AreEqual(1, astNode.nodes.size);
            MethodNode methodNode = astNode.nodes[0] as MethodNode;

            Assert.AreEqual("GetValue", methodNode.name);
            Assert.AreEqual("int", methodNode.returnTypeLookup.typeName);
            Assert.AreEqual(0, methodNode.signatureList.Length);
        }
Esempio n. 5
0
        public void ParseMethod_Args2()
        {
            TypeBodyParser parser = new TypeBodyParser();

            const string input = @"
                int GetValue(int someValue, System.Collections.Generic.Dictionary<int, UnityEngine.Vector3> dict) {
                    return someValue;
                }
            ";

            TypeBodyNode astNode = parser.Parse(input, "", 0);

            Assert.AreEqual(1, astNode.nodes.size);
            MethodNode methodNode = astNode.nodes[0] as MethodNode;

            Assert.AreEqual("GetValue", methodNode.name);
            Assert.AreEqual("int", methodNode.returnTypeLookup.typeName);
            Assert.AreEqual(2, methodNode.signatureList.Length);
            Assert.AreEqual("int", methodNode.signatureList[0].type.Value.typeName);
            Assert.AreEqual("someValue", methodNode.signatureList[0].identifier);
            Assert.AreEqual("Dictionary", methodNode.signatureList[1].type.Value.typeName);
            Assert.AreEqual("dict", methodNode.signatureList[1].identifier);
        }