Ejemplo n.º 1
0
        public void Can_Use_Fluent_Member_Set_Property()
        {
            var date1 = new DateTime(2012, 6, 2);
            var date2 = new DateTime(2012, 6, 3);

            Klass.Reset();
            var statements = new List <Tuple <string, Type, object, string> >()
            {
                // INSTANCE PROPS -----------------------------------------------------------------------------------
                // Static prop get
                TestCase("result", typeof(double), 124, "klass Prop1 = 124;                 result = klass Prop1;"),
                TestCase("result", typeof(string), "fluent2", "klass Prop2 = 'fluent2';           result = klass Prop2;"),
                TestCase("result", typeof(bool), false, "klass Prop3 = false;               result = klass Prop3;"),
                TestCase("result", typeof(double), date1, "klass Prop4 = new Date(2012,6,2);  result = klass Prop4;"),

                // Static prop get fluent
                TestCase("result", typeof(double), 124, "Prop1 klass = 124;                 result = klass Prop1;"),
                TestCase("result", typeof(string), "fluent2", "Prop2 klass = 'fluent2';           result = klass Prop2;"),
                TestCase("result", typeof(bool), false, "Prop3 klass = false;               result = klass Prop3;"),
                TestCase("result", typeof(double), date1, "Prop4 klass = new Date(2012,6,2);  result = klass Prop4;"),


                // STATIC PROPS -----------------------------------------------------------------------------------
                // Static prop get
                TestCase("result", typeof(double), 1235, "Klass KProp1 = 1235;               result = Klass KProp1;"),
                TestCase("result", typeof(string), "Fluent2", "Klass KProp2 = 'Fluent2';          result = Klass KProp2;"),
                TestCase("result", typeof(bool), false, "Klass KProp3 = false;              result = Klass KProp3;"),
                TestCase("result", typeof(double), date2, "Klass KProp4 = new Date(2012,6,3); result = Klass KProp4;"),

                // Static prop get fluent
                TestCase("result", typeof(double), 1235, "KProp1 Klass = 1235;               result = Klass KProp1;"),
                TestCase("result", typeof(string), "Fluent2", "KProp2 Klass = 'Fluent2';          result = Klass KProp2;"),
                TestCase("result", typeof(bool), false, "KProp3 Klass = false;              result = Klass KProp3;"),
                TestCase("result", typeof(double), date2, "KProp4 Klass = new Date(2012,6,3); result = Klass KProp4;"),
            };

            Parse(statements, true, i =>
            {
                i.Context.Plugins.RegisterAll();
                i.Context.Types.Register(typeof(Klass), null);
                var ltype = Lang.Helpers.LangTypeHelper.ConvertToLangTypeClass(typeof(Klass));
                i.Context.Symbols.Global.DefineVariable("klass", ltype);
                i.Context.Memory.SetValue("klass", new LClass(new Klass()));
            });
        }
Ejemplo n.º 2
0
        public void Can_Use_Fluent_Member_Method_Calls()
        {
            var date = new DateTime(2012, 6, 1);

            Klass.Reset();
            var statements = new List <Tuple <string, Type, object, string> >()
            {
                // INSTANCE PROPS -----------------------------------------------------------------------------------
                // Static prop get
                TestCase("result", typeof(double), 12, "var result = klass Method1 12, 'fs', true, new Date(2012, 6, 1);"),
                TestCase("result", typeof(string), "fs", "var result = klass Method2 12, 'fs', true, new Date(2012, 6, 1);"),
                TestCase("result", typeof(bool), true, "var result = klass Method3 12, 'fs', true, new Date(2012, 6, 1);"),
                TestCase("result", typeof(double), date, "var result = klass Method4 12, 'fs', true, new Date(2012, 6, 1);"),

                // Static prop get fluent
                TestCase("result", typeof(double), 12, "var result = Method1 klass $12, 'fs', on, 6/1/2012;"),
                TestCase("result", typeof(string), "fs", "var result = Method2 klass $12, 'fs', on, 6/1/2012;"),
                TestCase("result", typeof(bool), true, "var result = Method3 klass $12, 'fs', on, 6/1/2012;"),
                TestCase("result", typeof(double), date, "var result = Method4 klass $12, 'fs', on, 6/1/2012;"),


                // STATIC PROPS -----------------------------------------------------------------------------------
                // Static prop get
                TestCase("result", typeof(double), 12, "var result = Klass KMethod1 12, 'fs', true, new Date(2012, 6, 1);"),
                TestCase("result", typeof(string), "fs", "var result = Klass KMethod2 12, 'fs', true, new Date(2012, 6, 1);"),
                TestCase("result", typeof(bool), true, "var result = Klass KMethod3 12, 'fs', true, new Date(2012, 6, 1);"),
                TestCase("result", typeof(double), date, "var result = Klass KMethod4 12, 'fs', true, new Date(2012, 6, 1);"),

                // Static prop get fluent
                TestCase("result", typeof(double), 12, "var result = KMethod1 Klass $12, 'fs', on, 6/1/2012;"),
                TestCase("result", typeof(string), "fs", "var result = KMethod2 Klass $12, 'fs', on, 6/1/2012;"),
                TestCase("result", typeof(bool), true, "var result = KMethod3 Klass $12, 'fs', on, 6/1/2012;"),
                TestCase("result", typeof(double), date, "var result = KMethod4 Klass $12, 'fs', on, 6/1/2012;"),
            };

            Parse(statements, true, i =>
            {
                i.Context.Plugins.RegisterAll();
                i.Context.Types.Register(typeof(Klass), null);
                var ltype = Lang.Helpers.LangTypeHelper.ConvertToLangTypeClass(typeof(Klass));
                i.Context.Symbols.Global.DefineVariable("klass", ltype);
                i.Context.Memory.SetValue("klass", new LClass(new Klass()));
            });
        }