Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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();
        }