public void BinaryExpresionOperation(string program, ExpressionType operation)
        {
            TigerParser       parser            = Mother.CreateParser(program);
            ProgramExpression rootAstExpression = parser.parse();
            Expression        expression        = rootAstExpression.Compile();

            Assert.IsInstanceOf <BinaryExpression>(expression);
            var binary = expression as BinaryExpression;

            Assert.AreEqual(binary.NodeType, operation);
        }
Пример #2
0
        public void ConstantExpression_stringValue(string str)
        {
            TigerParser parser = Mother.CreateParser(str);

            Expression expression = parser.parse().Compile();

            Assert.IsInstanceOf <ConstantExpression>(expression);
            var constant = expression as ConstantExpression;

            Assert.IsInstanceOf <string>(constant.Value);
            Assert.AreEqual(constant.Value, str.Substring(1, str.Length - 2));
        }
Пример #3
0
        public void ConstantExpression_intValue(int number)
        {
            TigerParser parser = Mother.CreateParser(number.ToString());

            Expression expression = parser.parse().Compile();

            Assert.IsInstanceOf <ConstantExpression>(expression);
            var constant = expression as ConstantExpression;

            Assert.IsInstanceOf <int>(constant.Value);
            Assert.AreEqual((int)constant.Value, number);
        }
        public void calls_function_in_runtime()
        {
            string program = "Calc()";

            TigerParser parser            = Mother.CreateParser(program);
            var         runtime           = new AstHelper(null);
            Expression <Func <int> > calc = () => 1;

            runtime.Functions.Add("Calc", new FunctionReference(calc, typeof(int)));
            Expression result = parser.parse().Compile(runtime);

            Mother.Test(result, 1);
        }