Esempio n. 1
0
 public void AlreadyCompiled()
 {
     var e = new CompilingExpressionEvaluator<object, object, object>("AlreadyCompiled", " null ");
        Assert.IsFalse(CompilingExpressionEvaluator<object, object, object>.IsScopeAlreadyCompiled("AlreadyCompiled"));
        e.Compile();
        Assert.IsTrue(CompilingExpressionEvaluator<object, object, object>.IsScopeAlreadyCompiled("AlreadyCompiled"));
        Assert.AreEqual(null,  e.Evaluate(null, null));
 }
Esempio n. 2
0
        public void AlreadyCompiled()
        {
            var e = new CompilingExpressionEvaluator <object, object, object>("AlreadyCompiled", " null ");

            Aver.IsFalse(CompilingExpressionEvaluator <object, object, object> .IsScopeAlreadyCompiled("AlreadyCompiled"));
            e.Compile();
            Aver.IsTrue(CompilingExpressionEvaluator <object, object, object> .IsScopeAlreadyCompiled("AlreadyCompiled"));
            Aver.IsNull(e.Evaluate(null, null));
        }
Esempio n. 3
0
        public void BasicArithmetic()
        {
            if (CompilingExpressionEvaluator<object, int, int>.IsScopeAlreadyCompiled("BasicArithmetic")) return;

               var e = new CompilingExpressionEvaluator<object, int, int>("BasicArithmetic", "2 + 2 - 4 + arg");
               Assert.AreEqual(5,  e.Evaluate(null, 5));
               Assert.AreEqual(3,  e.Evaluate(null, 3));
               Assert.AreEqual(179,  e.Evaluate(null, 179));
               Assert.AreEqual(12,  e.Evaluate(null, 12));
        }
Esempio n. 4
0
        public void Strings()
        {
            if (CompilingExpressionEvaluator <string, bool, DateTime> .IsScopeAlreadyCompiled("Strings"))
            {
                return;
            }

            var e = new CompilingExpressionEvaluator <string, bool, DateTime>("Strings", " ctx.Contains(\"da\")? arg.Year==2013 : arg.Year==1900 ");

            Aver.IsTrue(e.Evaluate("da", DateTime.Parse("1/1/2013")));
            Aver.IsFalse(e.Evaluate("net", DateTime.Parse("1/1/2013")));
            Aver.IsTrue(e.Evaluate("kaka", DateTime.Parse("1/1/1900")));
        }
Esempio n. 5
0
        public void BasicArithmetic()
        {
            if (CompilingExpressionEvaluator <object, int, int> .IsScopeAlreadyCompiled("BasicArithmetic"))
            {
                return;
            }

            var e = new CompilingExpressionEvaluator <object, int, int>("BasicArithmetic", "2 + 2 - 4 + arg");

            Aver.AreEqual(5, e.Evaluate(null, 5));
            Aver.AreEqual(3, e.Evaluate(null, 3));
            Aver.AreEqual(179, e.Evaluate(null, 179));
            Aver.AreEqual(12, e.Evaluate(null, 12));
        }
Esempio n. 6
0
        public void InContext()
        {
            if (CompilingExpressionEvaluator<Dictionary<string, int>, int, int>.IsScopeAlreadyCompiled("InContext")) return;

               var e = new CompilingExpressionEvaluator<Dictionary<string, int>, int, int>("InContext", " ctx[\"A\"] + arg - ctx[\"B\"] ");

               var c = new Dictionary<string, int>();
               c.Add("A", 10);
               c.Add("B", -5);
               Assert.AreEqual(20,  e.Evaluate(c, 5));

               c["B"] = 100;

               Assert.AreEqual(13 - 100,  e.Evaluate(c, 3));
        }
Esempio n. 7
0
        public void InContext()
        {
            if (CompilingExpressionEvaluator <Dictionary <string, int>, int, int> .IsScopeAlreadyCompiled("InContext"))
            {
                return;
            }

            var e = new CompilingExpressionEvaluator <Dictionary <string, int>, int, int>("InContext", " ctx[\"A\"] + arg - ctx[\"B\"] ");

            var c = new Dictionary <string, int>();

            c.Add("A", 10);
            c.Add("B", -5);
            Aver.AreEqual(20, e.Evaluate(c, 5));

            c["B"] = 100;

            Aver.AreEqual(13 - 100, e.Evaluate(c, 3));
        }
Esempio n. 8
0
        public void Many()
        {
            if (CompilingExpressionEvaluator <int, int, int> .IsScopeAlreadyCompiled("Many"))
            {
                return;
            }

            var lst = new List <CompilingExpressionEvaluator <int, int, int> >();

            for (var i = 0; i < 100; i++)
            {
                lst.Add(new CompilingExpressionEvaluator <int, int, int>("Many", " ctx + arg +" + i.ToString()));
            }

            for (var i = 0; i < 100; i++)
            {
                var expr = lst[i];
                Aver.AreEqual(i, expr.Evaluate(-i, i));
            }
        }
Esempio n. 9
0
        public void Strings()
        {
            if (CompilingExpressionEvaluator<string, bool, DateTime>.IsScopeAlreadyCompiled("Strings")) return;

               var e = new CompilingExpressionEvaluator<string, bool, DateTime>("Strings", " ctx.Contains(\"da\")? arg.Year==2013 : arg.Year==1900 ");
               Assert.IsTrue(e.Evaluate("da", DateTime.Parse("1/1/2013")));
               Assert.IsFalse(e.Evaluate("net", DateTime.Parse("1/1/2013")));
               Assert.IsTrue(e.Evaluate("kaka", DateTime.Parse("1/1/1900")));
        }