Base implementation of ScriptContext object
상속: IScriptContext
예제 #1
0
        public void SimpleFunctionScopeWithContract()
        {
            ScriptContext context = new ScriptContext();
              IScriptScope scope = context.Scope;
              Script.RunCode(@"
            a = 4; b = 2; c = 3;
            function test1(a,b)
              global(c)
              [
               pre(a>0);
               post();
               invariant();
              ]
            {
              c = a+b;
              a = 15;
            }

            test1(2,3);", context);

              Assert.AreEqual(scope, context.Scope);
              Assert.AreEqual(5, context.GetItem("c", true));
              Assert.AreEqual(4, context.GetItem("a", true));
              Assert.AreEqual(2, context.GetItem("b", true));
        }
예제 #2
0
        public void BaseOperatorIs()
        {
            ScriptContext context = new ScriptContext();

              Script.RunCode(@"
            a = 4;
            result =  a is int;
            ", context);

              Assert.AreEqual(true, context.GetItem("result", true));
        }
예제 #3
0
        public void BaseOperatorsUnary()
        {
            ScriptContext context = new ScriptContext();
              Script.RunCode(@"
            a = 4; b = 2;
            a++;
            b--;
            ", context);

              Assert.AreEqual(5, context.GetItem("a", true));
              Assert.AreEqual(1, context.GetItem("b", true));
        }
예제 #4
0
        public void ArithmeticExpressions()
        {
            IScriptContext context = new ScriptContext();
              object result =
             Script.RunCode(
             @"
              a=1.0;
              b = 2.0;
              c = 3.0;
              d = 2.0;
              e = 18.0;
              f = 6.0;

              p = 2.0; u = 3.0; v = 1.0; r = 2.0; s = 5.0; t = 12.0;

              // r1 = 9
              r1 = a + b + c*d;

              // r2 = -2.5
              r2 = a*(b - c/d )- e/f;

              //r3 = -4.5
              r3 = a*b*((c - d )*a - p*(u - v)*(r + s))/t;

              //r4 = 65536
              r4 = 2 * d^(c*5);

              //r5 = 2
              r5 = 5 % 3;

              v1 = -3;
            ",
             context);

              Assert.AreEqual(9.0, context.GetItem("r1", true));
              Assert.AreEqual(-2.5, context.GetItem("r2", true));
              Assert.AreEqual(-4.5, context.GetItem("r3", true));
              Assert.AreEqual((double)65536, context.GetItem("r4", true));
              Assert.AreEqual((Int32)2, context.GetItem("r5", true));
              Assert.AreEqual(-3, context.GetItem("v1", true));
        }
예제 #5
0
 /// <summary>
 /// Default constructor
 /// </summary>
 protected Script()
 {
     Context = new ScriptContext();
     Runtime.RuntimeHost.InitializeScript(Context);
 }
예제 #6
0
        public void DecimalPlusTests()
        {
            System.Int16 i16 = 10;
              System.Int32 i32 = 10;
              System.Int64 i64 = 10;
              System.Double d = 10;
              System.Single f = 10;
              System.Decimal dc = 2;
              object rez = null;

              IScriptContext context = new ScriptContext();
              context.SetItem("i16", i16);
              context.SetItem("i32", i32);
              context.SetItem("i64", i64);
              context.SetItem("d", d);
              context.SetItem("f", f);
              context.SetItem("dc", dc);

              rez = Script.RunCode(@"
            return i16 + dc;
              ", context);
              Assert.AreEqual(i16 + dc, rez);

              rez = Script.RunCode(@"
            return i32 + dc;
              ", context);
              Assert.AreEqual(i32 + dc, rez);

              rez = Script.RunCode(@"
            return i64 + dc;
              ", context);
              Assert.AreEqual(i64 + dc, rez);

              rez = Script.RunCode(@"
            return new decimal(f) + dc;
              ", context);
              Assert.AreEqual(new decimal(f) + dc, rez);

              rez = Script.RunCode(@"
            return new decimal(d) + dc;
              ", context);
              Assert.AreEqual(new decimal(d) + dc, rez);

              // Reverse

              rez = Script.RunCode(@"
            return  dc + i16;
              ", context);
              Assert.AreEqual(dc + i16, rez);

              rez = Script.RunCode(@"
            return dc + i32;
              ", context);
              Assert.AreEqual(dc + i32, rez);

              rez = Script.RunCode(@"
            return dc + i64;
              ", context);
              Assert.AreEqual(dc + i64, rez);

              rez = Script.RunCode(@"
            return dc + new decimal(f);
              ", context);
              Assert.AreEqual(dc + new decimal(f), rez);

              rez = Script.RunCode(@"
            return dc + new decimal(d);
              ", context);
              Assert.AreEqual(dc + new decimal(d), rez);
        }
예제 #7
0
        public void TestTypeExprGenerics()
        {
            RuntimeHost.AddType("Int", typeof(int));
              ScriptContext context = new ScriptContext();

              object rez = Script.RunCode("a = new List<|Int|>(); return a is List<|Int|>;", context);
              Assert.IsTrue((bool)rez);
        }
예제 #8
0
        public void TestTypeExpr()
        {
            RuntimeHost.AddType("Int", typeof(int));
              ScriptContext context = new ScriptContext();

              object rez = Script.RunCode("a = 2; return a is Int;", context);
              Assert.IsTrue((bool)rez);
        }