Пример #1
0
        public void nil_is_false()
        {
            // nil
            var       target = new ToBooleanExpression(new NullLiteralExpression());
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <bool>();

            Assert.IsFalse(result);
        }
Пример #2
0
        public void if_then_expression_infers_type_when_one_value_is_nil()
        {
            // nil && 1
            var target = new IfThenElseExpression
            {
                Test = new BoolLiteral(true),
                Then = new StringLiteralExpression("\"abc\""),
                Else = new NullLiteralExpression(),
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <string>();

            Assert.AreEqual("abc", result);
        }
Пример #3
0
        public void if_then_expression_infers_type_and_returns_nil_of_that_type()
        {
            // nil && 1
            var target = new IfThenElseExpression
            {
                Test = new BoolLiteral(false),
                Then = new StringLiteralExpression("\"abc\""),
                Else = new NullLiteralExpression(),
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <string>();

            Assert.AreEqual(null, result);
        }
Пример #4
0
        public void compare_integer_with_string()
        {
            // "abc" = "abc"
            var target = new LogicalBinaryOperationExpression
            {
                Left     = new IntLiteralExpression(1),
                Right    = new StringLiteralExpression("abc"),
                Operator = TigerOperator.Equal
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <bool>();

            Assert.IsFalse(result);
        }
Пример #5
0
        public void valid_equals_comparison_using_strings()
        {
            // "abc" = "abc"
            var target = new LogicalBinaryOperationExpression
            {
                Left     = new StringLiteralExpression("abc"),
                Right    = new StringLiteralExpression("abc"),
                Operator = TigerOperator.Equal
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <bool>();

            Assert.IsTrue(result);
        }
Пример #6
0
        public void nil_equals_integer()
        {
            // nil = 1
            var target = new LogicalBinaryOperationExpression
            {
                Left     = new NullLiteralExpression(),
                Right    = new IntLiteralExpression(1),
                Operator = TigerOperator.Equal
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <bool>();

            Assert.IsFalse(result);
        }
Пример #7
0
        public void nil_and_also_integer()
        {
            // nil && 1
            var target = new LogicalBinaryOperationExpression
            {
                Left     = new ToBooleanExpression(new NullLiteralExpression()),
                Right    = new ToBooleanExpression(new IntLiteralExpression(1)),
                Operator = TigerOperator.AndAlso
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <bool>();

            Assert.IsFalse(result);
        }
Пример #8
0
        public void integer_or_else_nil()
        {
            // 1 || nil
            var target = new LogicalBinaryOperationExpression
            {
                Left     = new ToBooleanExpression(new IntLiteralExpression(1)),
                Right    = new ToBooleanExpression(new NullLiteralExpression()),
                Operator = TigerOperator.OrElse
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <bool>();

            Assert.IsTrue(result);
        }
Пример #9
0
        public void variable_initialization_with_undefined_function()
        {
            // let var x:=Foo() in x and
            var target = new LetInExpression
            {
                VariableDeclarations = new List <VariableDeclarationBase>
                {
                    new VariableDeclarationExpression
                    {
                        VariableName =
                            new MemberIdentifierNode {
                            Name = "x"
                        },
                        VariableTypeName = new TypeReferenceNode(),
                        Value            = new FunctionInvokeExpression
                        {
                            FunctionName =
                                new IdentifierNode
                            {
                                Name = "Foo"
                            }
                        }
                    }
                },
                Body = new ListSemiExpression
                {
                    new VariableAccessExpression {
                        VariableName = "x"
                    }
                }
            };
            AstHelper helper = Mother.CreateRuntime();

            try
            {
                target.Compile(helper);
            }
            catch (SemanticException e)
            {
                var error = e.Errors.First() as FunctionNotDefinedError;
                Assert.IsNotNull(error);
            }
        }
Пример #10
0
        public void logical_binary_comparation_nil_with_string()
        {
            // nil=(nil="pepe")
            var target = new LogicalBinaryOperationExpression
            {
                Left  = new NullLiteralExpression(),
                Right = new LogicalBinaryOperationExpression
                {
                    Left     = new NullLiteralExpression(),
                    Right    = new StringLiteralExpression("pepe"),
                    Operator = TigerOperator.Equal
                },
                Operator = TigerOperator.Equal
            };
            AstHelper helper = Mother.CreateRuntime();

            var result = target.Compile(helper).Eval <bool>();

            Assert.IsFalse(result);
        }
        public void simple_match_expression()
        {
            var target = new MatchExpression
            {
                new GuardNode
                {
                    Test   = new[] { new BoolLiteral(true), },
                    Result = new BoolLiteral(true)
                },
                new GuardNode
                {
                    Test   = new[] { new BoolLiteral(false), },
                    Result = new BoolLiteral(false)
                }
            };

            target.Match = new[] { new BoolLiteral(true), };

            Mother.Test(target.Compile(Mother.CreateRuntime()), true);
        }
Пример #12
0
        public void simple_function_call()
        {
            // Foo()
            var target = new FunctionInvokeExpression
            {
                FunctionName = new IdentifierNode {
                    Name = "Foo"
                }
            };
            AstHelper helper = Mother.CreateRuntime();

            try
            {
                target.Compile(helper);
            }
            catch (SemanticException e)
            {
                var error = e.Errors.First() as FunctionNotDefinedError;
                Assert.IsNotNull(error);
            }
        }
Пример #13
0
        public void variable_declaration_without_type_equals_null()
        {
            // let var x:=nil in x and
            var target = new LetInExpression
            {
                VariableDeclarations = new List <VariableDeclarationBase>
                {
                    new VariableDeclarationExpression
                    {
                        VariableName =
                            new MemberIdentifierNode {
                            Name = "x"
                        },
                        VariableTypeName = new TypeReferenceNode(),
                        Value            = new NullLiteralExpression()
                    }
                },
                Body = new ListSemiExpression
                {
                    new VariableAccessExpression {
                        VariableName = "x"
                    }
                }
            };
            AstHelper helper = Mother.CreateRuntime();

            try
            {
                target.Compile(helper);
            }
            catch (SemanticException e)
            {
                var error = e.Errors.First() as CanNotInferTypeError;
                Assert.IsNotNull(error);
                Assert.Pass();
            }
            Assert.Fail();
        }
Пример #14
0
        public void nil_equals_nil()
        {
            // nil = nil
            var target = new LogicalBinaryOperationExpression
            {
                Left     = new NullLiteralExpression(),
                Right    = new NullLiteralExpression(),
                Operator = TigerOperator.Equal
            };
            AstHelper helper = Mother.CreateRuntime();

            try
            {
                target.Compile(helper);
            }
            catch (SemanticException e)
            {
                var error = e.Errors.First() as CanNotInferTypeError;
                Assert.IsNotNull(error);
                Assert.Pass();
            }
            Assert.Fail();
        }
        public void field_not_defined()
        {
            var target = new FieldAccessExpression
            {
                FieldName = new IdentifierNode {
                    Name = "Foo"
                },
                Target = new StringLiteralExpression("abc")
            };
            AstHelper helper = Mother.CreateRuntime();

            try
            {
                target.Compile(helper);
            }
            catch (SemanticException e)
            {
                var error = e.Errors.First() as FieldNotFoundError;
                Assert.IsNotNull(error);
                Assert.Pass();
            }
            Assert.Fail();
        }