Beispiel #1
0
            public override bool Evaluate(InterpreterScope scope, out ExpressionBase result)
            {
                var left       = GetIntegerParameter(scope, "left", out result);
                var right      = GetIntegerParameter(scope, "right", out result);
                var mathematic = new MathematicExpression(left, MathematicOperation.Add, right);

                return(mathematic.ReplaceVariables(scope, out result));
            }
Beispiel #2
0
        public void TestAddStrings()
        {
            var left  = new StringConstantExpression("ban");
            var right = new StringConstantExpression("ana");
            var expr  = new MathematicExpression(left, MathematicOperation.Add, right);
            var scope = new InterpreterScope();

            ExpressionBase result;

            Assert.That(expr.ReplaceVariables(scope, out result), Is.True);
            Assert.That(result, Is.InstanceOf <StringConstantExpression>());
            Assert.That(((StringConstantExpression)result).Value, Is.EqualTo("banana"));
        }
Beispiel #3
0
        public void TestBitwiseAndZero()
        {
            var left  = new IntegerConstantExpression(0xCF);
            var right = new IntegerConstantExpression(0);
            var expr  = new MathematicExpression(left, MathematicOperation.BitwiseAnd, right);
            var scope = new InterpreterScope();

            ExpressionBase result;

            Assert.That(expr.ReplaceVariables(scope, out result), Is.True);
            Assert.That(result, Is.InstanceOf <IntegerConstantExpression>());
            Assert.That(((IntegerConstantExpression)result).Value, Is.EqualTo(0));
        }
Beispiel #4
0
        public void TestAddZero()
        {
            var left  = new FunctionCallExpression("byte", new[] { new IntegerConstantExpression(0) });
            var right = new IntegerConstantExpression(0);
            var expr  = new MathematicExpression(left, MathematicOperation.Add, right);
            var scope = new InterpreterScope();

            scope.Context = new TriggerBuilderContext();
            scope.AddFunction(new MemoryAccessorFunction("byte", FieldSize.Byte));

            ExpressionBase result;

            Assert.That(expr.ReplaceVariables(scope, out result), Is.True);
            Assert.That(result.ToString(), Is.EqualTo(left.ToString()));
        }
Beispiel #5
0
        public void TestModulusZero()
        {
            var left  = new FunctionCallExpression("byte", new[] { new IntegerConstantExpression(0) });
            var right = new IntegerConstantExpression(0);
            var expr  = new MathematicExpression(left, MathematicOperation.Modulus, right);
            var scope = new InterpreterScope();

            scope.Context = new TriggerBuilderContext();
            scope.AddFunction(new MemoryAccessorFunction("byte", FieldSize.Byte));

            ExpressionBase result;

            Assert.That(expr.ReplaceVariables(scope, out result), Is.False);
            Assert.That(((ParseErrorExpression)result).Message, Is.EqualTo("Division by zero"));
        }
Beispiel #6
0
        public void TestAddVariables()
        {
            var value1 = new IntegerConstantExpression(1);
            var value2 = new IntegerConstantExpression(2);
            var left   = new VariableExpression("left");
            var right  = new VariableExpression("right");
            var expr   = new MathematicExpression(left, MathematicOperation.Add, right);
            var scope  = new InterpreterScope();

            scope.AssignVariable(left, value1);
            scope.AssignVariable(right, value2);

            ExpressionBase result;

            Assert.That(expr.ReplaceVariables(scope, out result), Is.True);
            Assert.That(result, Is.InstanceOf <IntegerConstantExpression>());
            Assert.That(((IntegerConstantExpression)result).Value, Is.EqualTo(3));
        }