public void Dlr_Number()
        {
            object one_hundred = Engine.Execute(@"
class Number
    def initialize(v)
        @val = v
    end
    
    def +(other)
        @val + other
    end
    
    def -(other)
        @val - other
    end
    
    def *(other)
        @val * other
    end
    
    def /(other)
        @val / other
    end

    def -@
        -@val
    end  

    def ~
        ~@val
    end  
end

Number.new(100)
");

            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Add, one_hundred, 1), 100 + 1);
            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Subtract, one_hundred, 1), 100 - 1);
            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Multiply, one_hundred, 2), 2 * 100);
            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Divide, one_hundred, 2), 100 / 2);
            AreEqual(MyUnaryOperationBinder.Invoke(ExpressionType.Negate, one_hundred), -100);
            AreEqual(MyUnaryOperationBinder.Invoke(ExpressionType.OnesComplement, one_hundred), ~100);
            AreEqual(MyUnaryOperationBinder.Invoke(ExpressionType.Increment, one_hundred), 100 + 1);
            AreEqual(MyUnaryOperationBinder.Invoke(ExpressionType.Decrement, one_hundred), 100 - 1);

#if !CLR2
            dynamic number = one_hundred;
            number--;
            Assert(number == 99);
            number++;
            Assert(number == 100);
#endif
        }
Esempio n. 2
0
        public void Dlr_Number()
        {
            var    scope       = CreateInteropScope();
            object one_hundred = scope.GetVariable("number");

            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Add, one_hundred, 1), 100 + 1);
            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Subtract, one_hundred, 1), 100 - 1);
            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Multiply, one_hundred, 2), 2 * 100);
            AreEqual(MyBinaryOperationBinder.Invoke(ExpressionType.Divide, one_hundred, 2), 100 / 2);
            AreEqual(MyUnaryOperationBinder.Invoke(ExpressionType.Negate, one_hundred), -100);
            AreEqual(MyUnaryOperationBinder.Invoke(ExpressionType.OnesComplement, one_hundred), ~100);
        }