Esempio n. 1
0
 public void TypeCheck_Visit_AddNullFunctionInvocationToInteger()
 {
     Assert.Throws <Exception>(() =>
     {
         AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode6);
         TestDelegate(ast);
     });
 }
Esempio n. 2
0
        public void LinkChecker_Visit_ThrowOnInvalidExitLink()
        {
            AbstractSyntaxTree ast         = TestAstBuilder.BuildAst(TestCode1_1, TestCode1_2);
            LinkChecker        linkChecker = new LinkChecker(ast);

            void TestDelegate() => linkChecker.Visit(ast.Root.GameObjects["SampleScreen1"]);

            Assert.Throws <Exception>(TestDelegate);
        }
Esempio n. 3
0
 public void LinkChecker_Visit_InValidMemberAccessThrows()
 {
     Assert.Throws <Exception>(() =>
     {
         AbstractSyntaxTree ast  = TestAstBuilder.BuildAst(TestCode3_3, TestCode3_2);
         LinkChecker linkChecker = new LinkChecker(ast);
         linkChecker.Visit(ast.Root.GameObjects["SampleScreen1"]);
     });
 }
Esempio n. 4
0
        public void TypeCheck_Visit_MemberAccessNotFoundIfNotDeclared()
        {
            Assert.Throws <Exception>(() =>
            {
                AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode3);

                TestDelegate(ast);
            });
        }
Esempio n. 5
0
        public void TypeCheck_Visit_ArrayPlusIntegerFails()
        {
            Assert.Throws <Exception>(() =>
            {
                AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode2);

                TestDelegate(ast);
            });
        }
Esempio n. 6
0
        public void TypeCheck_Visit_NullFunctionExpressionPlusIntegerThrows()
        {
            Assert.Throws <Exception>(() =>
            {
                AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode8);

                TestDelegate(ast);
            });
        }
Esempio n. 7
0
        public void TypeCheck_Visit_ExitCannotBeUsedInExpressions()
        {
            Assert.Throws <Exception>(() =>
            {
                AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode4_3, TestCode4_4);

                TestDelegate(ast);
            });
        }
Esempio n. 8
0
        public void TypeCheck_Visit_AllScopesAccountedFor()
        {
            AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode);
            TypeChecker        tc  = new TypeChecker();

            foreach (GameObjectNode gameObjectNode in ast.Root.GameObjects.Values)
            {
                tc.Visit(gameObjectNode);
            }

            // Expect four scopes and one top symbol table
            Assert.That(EnvironmentStore.TopSymbolTablesCount == 1, "EnvironmentStore.TopSymbolTables.Count == 1");
            Assert.That(tc.EnvironmentStack.Count == 4, "tc.EnvironmentStack.Count == 4");
        }
Esempio n. 9
0
        public void TypeCheck_Visit_AssignNullFunctionToVariableAllowed()
        {
            AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode7);

            Assert.DoesNotThrow(() => TestDelegate(ast));

            List <string> variablePath = new List <string>()
            {
                "SampleScreen1", "Map", "x"
            };

            ValueNode value = EnvironmentStore.AccessMember(variablePath).ValueNode;

            Assert.That(value == null);
        }
Esempio n. 10
0
        public void LinkChecker_Visit_ValidMemberAccessSucceeds()
        {
            AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode3_1, TestCode3_2);

            void TestDelegate()
            {
                foreach (GameObjectNode gameObject in ast.Root.GameObjects.Values)
                {
                    new TypeChecker().Visit(gameObject);
                }

                foreach (GameObjectNode gameObject in ast.Root.GameObjects.Values)
                {
                    new LinkChecker(ast).Visit(gameObject);
                }
            }

            Assert.DoesNotThrow(TestDelegate);
        }
Esempio n. 11
0
        public void TypeCheck_Visit_IntegerPlusFloatSucceeds()
        {
            AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode9);

            Assert.DoesNotThrow(() => TestDelegate(ast));

            List <string> variablePathX = new List <string>()
            {
                "SampleScreen1", "Map", "x"
            };
            List <string> variablePathY = new List <string>()
            {
                "SampleScreen1", "Map", "y"
            };

            ValueNode valueX = EnvironmentStore.AccessMember(variablePathX).ValueNode;
            ValueNode valueY = EnvironmentStore.AccessMember(variablePathY).ValueNode;

            Assert.That(valueX != null, "valueX != null");
            Assert.That(valueX is FloatValueNode {
                Value: 2.5f
            }, "valueX != null");
Esempio n. 12
0
        public void ASTBuilder_Visit_NonExistingFunctionCallThrows()
        {
            void TestDelegate() => TestAstBuilder.BuildAst(TestCode1);

            Assert.Throws <Exception>(TestDelegate);
        }
Esempio n. 13
0
        public void TypeCheck_Visit_MemberAccessValidExpressionSucceeds()
        {
            AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode4_1, TestCode4_2);

            Assert.DoesNotThrow(() => TestDelegate(ast));
        }