예제 #1
0
        public void ExpressionTree()
        {
            IParserContext context = new ParserContext();

            ExpressionWithContext expr = new ExpressionWithContext(context);

            expr.Expression = Exp.Add(TokenPosition.Unknown, Exp.Value(TokenPosition.Unknown, 4), Exp.Value(TokenPosition.Unknown, 5));

            Assert.AreEqual(9, expr.Evaluate().Value);
            Assert.AreEqual(typeof(int), expr.Evaluate().Type);

            expr.Expression = Exp.Add(TokenPosition.Unknown, Exp.Add(TokenPosition.Unknown, Exp.Value(TokenPosition.Unknown, 4), Exp.Value(TokenPosition.Unknown, (long)5)), Exp.Value(TokenPosition.Unknown, 6));

            Assert.AreEqual(15, expr.Evaluate().Value);
            Assert.AreEqual(typeof(long), expr.Evaluate().Type);

            expr.Expression = Exp.Op(TokenPosition.Unknown, "<<", Exp.Value(TokenPosition.Unknown, (long)4), Exp.Value(TokenPosition.Unknown, 2));

            Assert.AreEqual(16, expr.Evaluate().Value);
        }
        public void ExpressionTree()
        {
            IParserContext context = new ParserContext();

            ExpressionWithContext expr = new ExpressionWithContext(context);

            expr.Expression = Exp.Add(TokenPosition.Unknown, Exp.Value(TokenPosition.Unknown, 4), Exp.Value(TokenPosition.Unknown, 5));

            Assert.AreEqual(9, expr.Evaluate().Value);
            Assert.AreEqual(typeof(int), expr.Evaluate().Type);

            expr.Expression = Exp.Add(TokenPosition.Unknown, Exp.Add(TokenPosition.Unknown, Exp.Value(TokenPosition.Unknown, 4), Exp.Value(TokenPosition.Unknown, (long)5)), Exp.Value(TokenPosition.Unknown, 6));

            Assert.AreEqual(15, expr.Evaluate().Value);
            Assert.AreEqual(typeof(long), expr.Evaluate().Type);

            expr.Expression = Exp.Op(TokenPosition.Unknown, "<<", Exp.Value(TokenPosition.Unknown, (long)4), Exp.Value(TokenPosition.Unknown, 2));

            Assert.AreEqual(16, expr.Evaluate().Value);
        }