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);
        }
예제 #2
0
        private Expression MatchExpressions(IEnumerable <Expression> match, IEnumerable <Expression> test)
        {
            if (match.Count() != test.Count())
            {
                return(new BoolLiteral(false));
            }

            IEnumerable <LogicalBinaryOperationExpression> comparisons = match.Zip(test, (m, t) => new LogicalBinaryOperationExpression
            {
                Left     = m,
                Right    = t,
                Operator = TigerOperator.Equal
            });

            var result = new LogicalBinaryOperationExpression
            {
                Left     = new BoolLiteral(true),
                Right    = new BoolLiteral(true),
                Operator = TigerOperator.AndAlso
            };

            LogicalBinaryOperationExpression temp = result;

            foreach (LogicalBinaryOperationExpression operation in comparisons)
            {
                temp.Left = operation;
                var next = new LogicalBinaryOperationExpression
                {
                    Left     = new BoolLiteral(true),
                    Right    = new BoolLiteral(true),
                    Operator = TigerOperator.AndAlso
                };
                temp.Right = next;
                temp       = next;
            }

            return(result);
        }
        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);
        }
        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 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);
        }
        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);
        }
        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 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);
        }