示例#1
0
        public void BooleanNot()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(false).BooleanNot()));
            var result = (bool)method.Invoke(null, null);

            Assert.IsTrue(result);
        }
示例#2
0
        public void AddDoubleAndInt()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(5.1d).Add(4)));
            var result = (double)method.Invoke(null, null);

            Assert.IsTrue(Math.Abs(9.1d - result) < .0001d);
        }
示例#3
0
        public void GreaterThan()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(5).GreaterThan(4)));
            var result = (bool)method.Invoke(null, null);

            Assert.IsTrue(result);
        }
示例#4
0
        public void LessThanOrEqualWhenLess()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(5).LessThanOrEqual(6)));
            var result = (bool)method.Invoke(null, null);

            Assert.IsTrue(result);
        }
示例#5
0
        public void ShiftRight()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(4).ShiftRight(2)));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(1, result);
        }
示例#6
0
        public void NotEqualsTrue()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(4).NotEqualTo(5)));
            var result = (bool)method.Invoke(null, null);

            Assert.IsTrue(result);
        }
示例#7
0
        public void BitwiseOr()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(1 | 2).BitwiseOr(4 | 8)));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(15, result);
        }
示例#8
0
        public void Modulus()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(7).Modulus(3)));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(1, result);
        }
示例#9
0
        public void Subtract()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(7).Subtract(3)));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(4, result);
        }
示例#10
0
        public void Plus()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(123).Plus()));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(result, 123);
        }
示例#11
0
        public void BitwiseNot()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(34754935).BitwiseNot()));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(result, ~34754935);
        }
示例#12
0
        public void AddTwoInts()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(5).Add(4)));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(9, result);
        }
示例#13
0
        public void CastFloatToInt()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(4.5F).Cast(typeof(int))));
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(4, result);
        }
示例#14
0
        public void AddTwoFloats()
        {
            var method = CreateMethod(block => block.Return(EmitAst.Literal(5.1f).Add(4.2f)));
            var result = (float)method.Invoke(null, null);

            Assert.IsTrue(Math.Abs(9.3f - result) < .0001f);
        }
示例#15
0
        public void CastLongToInt()
        {
            var expected = 2342332342342334L;
            var method   = CreateMethod(block => block.Return(EmitAst.Literal(2342332342342334L).Cast(typeof(int))));
            var result   = (int)method.Invoke(null, null);

            Assert.AreEqual((int)expected, result);
        }
示例#16
0
        public void CastIntToLong()
        {
            var expected = 234233L;
            var method   = CreateMethod(block => block.Return(EmitAst.Literal(234233).Cast(typeof(long))));
            var result   = (long)method.Invoke(null, null);

            Assert.AreEqual(expected, result);
        }
示例#17
0
        public void CastIntToDouble()
        {
            var expected = 1233223523532D;
            var method   = CreateMethod(block => block.Return(EmitAst.Literal(1233223523532).Cast(typeof(double))));
            var result   = (double)method.Invoke(null, null);

            Assert.AreEqual(expected, result);
        }
示例#18
0
        public void CastIntToFloat()
        {
            var expected = 123F;
            var method   = CreateMethod(block => block.Return(EmitAst.Literal(123).Cast(typeof(float))));
            var result   = (float)method.Invoke(null, null);

            Assert.AreEqual(expected, result);
        }
示例#19
0
        public void CastIntToShort()
        {
            var expected = 1254323423;
            var method   = CreateMethod(block => block.Return(EmitAst.Literal(1254323423).Cast(typeof(short))));
            var result   = (short)method.Invoke(null, null);

            Assert.AreEqual((short)expected, result);
        }
示例#20
0
        public void CastIntToByte()
        {
            var expected = 12543;
            var method   = CreateMethod(block => block.Return(EmitAst.Literal(12543).Cast(typeof(byte))));
            var result   = (byte)method.Invoke(null, null);

            Assert.AreEqual((byte)expected, result);
        }
示例#21
0
        public void ForLoop()
        {
            var method = CreateMethod(block =>
            {
                var otherVariable = block.Declare(typeof(int));
                block.Express(otherVariable.Assign(EmitAst.Literal(1)));
                var variable = EmitAst.Declare(typeof(int));
                block.Statements.Add(EmitAst.For(variable, EmitAst.LessThan(variable, EmitAst.Literal(5)), variable.AddAssign(1).Express(), otherVariable.AddAssign(1).Express()));
                block.Return(otherVariable);
            });
            var result = (int)method.Invoke(null, null);

            Assert.AreEqual(6, result);
        }