Exemplo n.º 1
0
        public void detectArgumentTest2()
        {
            IPM pm = new PM(" solution (1.5, -1.5, 1.5f, -1.5f, 1.5d, -1.5d) ");

            Assert.AreEqual(pm.Is(LevelType.Method, "solution"), true);
            Assert.AreEqual(pm.Levels[0].Args.Length, 6);

            Argument[] args = pm.Levels[0].Args;
            Assert.AreEqual(args[0].type, ArgumentType.Double);
            Assert.AreEqual(args[0].data, 1.5d);

            Assert.AreEqual(args[1].type, ArgumentType.Double);
            Assert.AreEqual(args[1].data, -1.5d);

            Assert.AreEqual(args[2].type, ArgumentType.Float);
            Assert.AreEqual(args[2].data, 1.5f);

            Assert.AreEqual(args[3].type, ArgumentType.Float);
            Assert.AreEqual(args[3].data, -1.5f);

            Assert.AreEqual(args[4].type, ArgumentType.Double);
            Assert.AreEqual(args[4].data, 1.5d);

            Assert.AreEqual(args[5].type, ArgumentType.Double);
            Assert.AreEqual(args[5].data, -1.5d);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handler for current data
        /// </summary>
        /// <param name="data">mixed data</param>
        /// <returns>prepared and evaluated data</returns>
        public override string parse(string data)
        {
            var point       = entryPoint(data);
            string subtype  = point.Key;
            string request  = point.Value;

            Log.Trace("`{0}`: subtype - `{1}`, request - `{2}`", ToString(), subtype, request);

            IPM pm = new PM(request, msbuild);
            switch(subtype) {
                case "gnt": {
                    return stGNT(pm);
                }
            }

            throw new SubtypeNotFoundException("Subtype `{0}` is not found", subtype);
        }
Exemplo n.º 3
0
        /// <summary>
        /// To pack string argument in object.
        /// </summary>
        /// <param name="arg">Argument for packing.</param>
        /// <returns></returns>
        public static object packArgument(object arg)
        {
            if (arg == null)
            {
                return(null);
            }

            if (!(arg is string) || String.IsNullOrWhiteSpace((string)arg))
            {
                return(arg);
            }

            SNode.IPM      pm    = new SNode.PM(String.Format("_({0})", arg));
            SNode.Argument first = pm.FirstLevel.Args[0];

            if (first.type != SNode.ArgumentType.Object)
            {
                return(arg);
            }
            return(extract((SNode.Argument[])first.data));
        }
Exemplo n.º 4
0
        public void detectArgumentTest1()
        {
            IPM pm = new PM("solution(\"str data\", 'str data2', 12, -12, 1.5, -1.5, STDOUT, TestEnum.SpecialType, mixed * data, true)");

            Assert.AreEqual(pm.Is(LevelType.Method, "solution"), true);
            Assert.AreEqual(pm.Levels[0].Args.Length, 10);

            Argument[] args = pm.Levels[0].Args;
            Assert.AreEqual(args[0].type, ArgumentType.StringDouble);
            Assert.AreEqual(args[0].data, "str data");

            Assert.AreEqual(args[1].type, ArgumentType.StringSingle);
            Assert.AreEqual(args[1].data, "str data2");

            Assert.AreEqual(args[2].type, ArgumentType.Integer);
            Assert.AreEqual(args[2].data, 12);

            Assert.AreEqual(args[3].type, ArgumentType.Integer);
            Assert.AreEqual(args[3].data, -12);

            Assert.AreEqual(args[4].type, ArgumentType.Double);
            Assert.AreEqual(args[4].data, 1.5);

            Assert.AreEqual(args[5].type, ArgumentType.Double);
            Assert.AreEqual(args[5].data, -1.5);

            Assert.AreEqual(args[6].type, ArgumentType.EnumOrConst);
            Assert.AreEqual(args[6].data, "STDOUT");

            Assert.AreEqual(args[7].type, ArgumentType.EnumOrConst);
            Assert.AreEqual(args[7].data, "TestEnum.SpecialType");

            Assert.AreEqual(args[8].type, ArgumentType.Mixed);
            Assert.AreEqual(args[8].data, "mixed * data");

            Assert.AreEqual(args[9].type, ArgumentType.Boolean);
            Assert.AreEqual(args[9].data, true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// To pack string argument in object.
        /// </summary>
        /// <param name="arg">Argument for packing.</param>
        /// <returns></returns>
        public static object packArgument(object arg)
        {
            if(arg == null) {
                return null;
            }

            if(!(arg is string) || String.IsNullOrWhiteSpace((string)arg)) {
                return arg;
            }

            SNode.IPM pm            = new SNode.PM(String.Format("_({0})", arg));
            SNode.Argument first    = pm.FirstLevel.Args[0];

            if(first.type != SNode.ArgumentType.Object) {
                return arg;
            }
            return extract((SNode.Argument[])first.data);
        }
Exemplo n.º 6
0
        public void pinToTest1()
        {
            IPM pm = new PM("left.solution.right");

            Assert.AreEqual(4, pm.Levels.Count);

            pm.pinTo(1);
            Assert.AreEqual(3, pm.Levels.Count);

            Assert.AreEqual(pm.Is(0, LevelType.Property, "solution"), true);
            Assert.AreEqual(pm.Is(1, LevelType.Property, "right"), true);
            Assert.AreEqual(pm.Is(2, LevelType.RightOperandEmpty, null), true);

            pm.pinTo(2);
            Assert.AreEqual(pm.Is(0, LevelType.RightOperandEmpty, null), true);
        }
Exemplo n.º 7
0
        public void ItTest2()
        {
            IPM pm = new PM("solution.m1().Prop1.right");

            Assert.AreEqual(true, pm.It(LevelType.Property, "solution"));
            Assert.AreEqual(true, pm.Is(LevelType.Method, "m1"));
            Assert.AreEqual(false, pm.It(LevelType.Property, "Prop1"));
            Assert.AreEqual(true, pm.It(1, LevelType.Property, "Prop1"));
            Assert.AreEqual(true, pm.It(LevelType.Property, "right"));
        }
Exemplo n.º 8
0
        public void IsTest3()
        {
            IPM pm = new PM("solution.m1(')', '(', \"(\").m2(123, \" -> )\").right");

            Assert.AreEqual(pm.Is(0, LevelType.Property, "solution"), true);
            Assert.AreEqual(pm.Is(1, LevelType.Method, "m1"), true);
            Assert.AreEqual(pm.Is(2, LevelType.Method, "m2"), true);
            Assert.AreEqual(pm.Is(3, LevelType.Property, "right"), true);
            Assert.AreEqual(pm.Is(4, LevelType.RightOperandEmpty), true);
        }
Exemplo n.º 9
0
        public void IsRightTest2()
        {
            IPM pm = new PM("pname.m1(): mixed data");

            Assert.AreEqual(true, pm.It(LevelType.Property, "pname"));
            Assert.AreEqual(true, pm.It(LevelType.Method, "m1"));
            Assert.AreEqual(false, pm.IsRight(LevelType.RightOperandEmpty));
            Assert.AreEqual(true, pm.IsRight(LevelType.RightOperandColon));
            Assert.AreEqual(false, pm.IsRight(LevelType.RightOperandStd));
        }
Exemplo n.º 10
0
        public void IsMethodWithArgsTest1()
        {
            IPM pm = new PM("solution(\"str data\", 12, true).data.right(false, 1).end()");

            Assert.AreEqual(true, pm.IsMethodWithArgs("solution", ArgumentType.StringDouble, ArgumentType.Integer, ArgumentType.Boolean));
            Assert.AreEqual(false, pm.IsMethodWithArgs(1, "data"));
            Assert.AreEqual(true, pm.IsMethodWithArgs(2, "right", ArgumentType.Boolean, ArgumentType.Integer));
            Assert.AreEqual(true, pm.IsMethodWithArgs(3, "end"));
        }
Exemplo n.º 11
0
        public void IsDataTest1()
        {
            IPM pm = new PM("pname . m1(true, 123).right = true");

            Assert.AreEqual(true, pm.IsData("pname"));
            Assert.AreEqual(false, pm.IsData("pname "));
            pm.pinTo(1);

            Assert.AreEqual(true, pm.IsData("m1"));
            pm.pinTo(1);

            Assert.AreEqual(true, pm.IsData("right"));
            pm.pinTo(1);

            Assert.AreEqual(true, pm.IsData(" true"));
        }
Exemplo n.º 12
0
 public void FinalEmptyIsTest5()
 {
     IPM pm = new PM("left.solution(\"m(1)\", \"m()\", ')', \")\", \"(\")");
     Assert.AreEqual(pm.Is(0, LevelType.Property, "left"), true);
     Assert.AreEqual(pm.FinalEmptyIs(1, LevelType.Method, "solution"), true);
 }
Exemplo n.º 13
0
        public void FinalEmptyIsTest2()
        {
            try {
                IPM pm = new PM("solution.right = ");
                Assert.AreEqual(pm.FinalEmptyIs(1, LevelType.Property, "right"), true);
                Assert.Fail("1");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(NotSupportedOperationException), ex.GetType().ToString()); }

            try {
                IPM pm = new PM("solution.right : ");
                Assert.AreEqual(pm.FinalEmptyIs(1, LevelType.Property, "right"), true);
                Assert.Fail("2");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(NotSupportedOperationException), ex.GetType().ToString()); }

            try {
                IPM pm = new PM("solution.right . prop");
                Assert.AreEqual(pm.FinalEmptyIs(1, LevelType.Property, "right"), true);
                Assert.Fail("3");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(NotSupportedOperationException), ex.GetType().ToString()); }

            try {
                IPM pm = new PM("solution.right mixed data");
                Assert.AreEqual(pm.FinalEmptyIs(1, LevelType.Property, "right"), true);
                Assert.Fail("4");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(NotSupportedOperationException), ex.GetType().ToString()); }
        }
Exemplo n.º 14
0
 public void FinalEmptyIsTest1()
 {
     IPM pm = new PM("solution.right ");
     Assert.AreEqual(pm.FinalEmptyIs(1, LevelType.Property, "right"), true);
     Assert.AreEqual(pm.FinalEmptyIs(2, LevelType.RightOperandEmpty), true);
 }
Exemplo n.º 15
0
        public void detectTest9()
        {
            IPM pm = new PM("left.solution(\" test , args\", 123, true, ' n1 , n2 ').right");

            Assert.AreEqual(pm.Levels[0].Type, LevelType.Property);
            Assert.AreEqual(pm.Levels[0].Data, "left");

            Assert.AreEqual(pm.Levels[1].Type, LevelType.Method);
            Assert.AreEqual(pm.Levels[1].Args.Length, 4);
            Assert.AreEqual(pm.Levels[1].Args[0].type, ArgumentType.StringDouble);
            Assert.AreEqual(pm.Levels[1].Args[0].data, " test , args");
            Assert.AreEqual(pm.Levels[1].Args[1].type, ArgumentType.Integer);
            Assert.AreEqual(pm.Levels[1].Args[1].data, 123);
            Assert.AreEqual(pm.Levels[1].Args[2].type, ArgumentType.Boolean);
            Assert.AreEqual(pm.Levels[1].Args[2].data, true);
            Assert.AreEqual(pm.Levels[1].Args[3].type, ArgumentType.StringSingle);
            Assert.AreEqual(pm.Levels[1].Args[3].data, " n1 , n2 ");
            Assert.AreEqual(pm.Levels[1].Data, "solution");

            Assert.AreEqual(pm.Levels[2].Type, LevelType.Property);
            Assert.AreEqual(pm.Levels[2].Data, "right");

            Assert.AreEqual(pm.Levels[3].Type, LevelType.RightOperandEmpty);
        }
Exemplo n.º 16
0
        public void getRightOperandTest2()
        {
            IPM pm = new PM("pname = true ");

            Assert.AreEqual(true, pm.It(LevelType.Property, "pname"));
            Assert.AreEqual(true, pm.IsRight(LevelType.RightOperandStd));
            Assert.AreEqual(" true ", pm.Levels[0].Data);

            pm = new PM("m(): mixed\ndata ");

            Assert.AreEqual(true, pm.It(LevelType.Method, "m"));
            Assert.AreEqual(true, pm.IsRight(LevelType.RightOperandColon));
            Assert.AreEqual(" mixed\ndata ", pm.Levels[0].Data);
        }
Exemplo n.º 17
0
 public void FinalIsTest1()
 {
     IPM pm = new PM("left.solution.right");
     Assert.AreEqual(pm.Levels.Count, 4);
     Assert.AreEqual(pm.FinalIs(2, LevelType.Property, "right"), true);
     Assert.AreEqual(pm.FinalIs(3, LevelType.RightOperandEmpty), true);
 }
Exemplo n.º 18
0
        public void IsDataTest2()
        {
            IPM pm = new PM("pname = true");

            Assert.AreEqual(false, pm.IsData("property1", "property2", "property2", "property3"));
            Assert.AreEqual(true, pm.IsData("property1", "property2", "pname", "property3"));
        }
Exemplo n.º 19
0
        public void FinalIsTest2()
        {
            try {
                IPM pm = new PM("left.solution.right");
                Assert.AreEqual(pm.FinalIs(1, LevelType.Property, "solution"), true);
                Assert.Fail("1");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(NotSupportedOperationException), ex.GetType().ToString()); }

            try {
                IPM pm = new PM("left.solution.right");
                Assert.AreEqual(pm.FinalIs(LevelType.Property, "left"), true);
                Assert.Fail("2");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(NotSupportedOperationException), ex.GetType().ToString()); }
        }
Exemplo n.º 20
0
        public void IsRightTest1()
        {
            IPM pm = new PM("pname = true");

            Assert.AreEqual(true, pm.It(LevelType.Property, "pname"));
            Assert.AreEqual(false, pm.IsRight(LevelType.RightOperandEmpty));
            Assert.AreEqual(false, pm.IsRight(LevelType.RightOperandColon));
            Assert.AreEqual(true, pm.IsRight(LevelType.RightOperandStd));
        }
Exemplo n.º 21
0
 public void FinalIsTest3()
 {
     IPM pm = new PM("left.solution.right");
     Assert.AreEqual(pm.Is(0, LevelType.Property, "right"), false);
     Assert.AreEqual(pm.FinalIs(1, LevelType.Property, "right"), false);
     Assert.AreEqual(pm.Is(2, LevelType.Property, "right"), true);
 }
Exemplo n.º 22
0
        public void IsTest1()
        {
            IPM pm = new PM("solution=left.right");

            Assert.AreEqual(pm.Is(100, LevelType.Property, "solution"), false);
            Assert.AreEqual(pm.Is(-1, LevelType.Property, "solution"), false);
            Assert.AreEqual(pm.Is(0, LevelType.Property, "solution"), true);
            Assert.AreEqual(pm.Is(1, LevelType.RightOperandStd, "left.right"), true);
        }
Exemplo n.º 23
0
 public void FinalIsTest5()
 {
     IPM pm = new PM("left.solution(\" (a, b) \").right");
     Assert.AreEqual(pm.Is(0, LevelType.Property, "left"), true);
     Assert.AreEqual(pm.Is(1, LevelType.Method, "solution"), true);
     Assert.AreEqual(pm.FinalIs(2, LevelType.Property, "right"), true);
 }
Exemplo n.º 24
0
        public void ItTest1()
        {
            IPM pm = new PM("solution.m1().right");

            Assert.AreEqual(true, pm.It(LevelType.Property, "solution"));
            Assert.AreEqual(true, pm.It(LevelType.Method, "m1"));
            Assert.AreEqual(false, pm.It(LevelType.Property, "notRealProperty"));
            Assert.AreEqual(true, pm.It(LevelType.Property, "right"));
            Assert.AreEqual(true, pm.It(LevelType.RightOperandEmpty));

            Assert.AreEqual(0, pm.Levels.Count);
            Assert.AreEqual(false, pm.It(LevelType.RightOperandEmpty));
            Assert.AreEqual(false, pm.Is(0, LevelType.RightOperandEmpty));
        }
Exemplo n.º 25
0
        public void FirstLevelTest1()
        {
            IPM pm = new PM("left.solution.right");

            Assert.AreEqual(pm.FirstLevel.Data, pm.Levels[0].Data);
            Assert.AreEqual(pm.FirstLevel.Type, pm.Levels[0].Type);

            pm.pinTo(2);
            Assert.AreEqual(pm.FirstLevel.Data, pm.Levels[0].Data);
            Assert.AreEqual(pm.FirstLevel.Type, pm.Levels[0].Type);
        }
Exemplo n.º 26
0
        public void detectArgumentTest3()
        {
            IPM pm = new PM(" m77(\"guid\", 12, {\"p1\", {4, \"test\", 8, 'y'}, true}, {false, 'p2'}) ");

            Assert.AreEqual(pm.Is(LevelType.Method, "m77"), true);

            Argument[] args = pm.Levels[0].Args;
            Assert.AreEqual(args.Length, 4);

            Assert.AreEqual(args[0].type, ArgumentType.StringDouble);
            Assert.AreEqual(args[0].data, "guid");

            Assert.AreEqual(args[1].type, ArgumentType.Integer);
            Assert.AreEqual(args[1].data, 12);

            Assert.AreEqual(args[2].type, ArgumentType.Object);
            {
                Argument[] args2 = (Argument[])args[2].data;
                Assert.AreEqual(args2.Length, 3);

                Assert.AreEqual(args2[0].type, ArgumentType.StringDouble);
                Assert.AreEqual(args2[0].data, "p1");

                Assert.AreEqual(args2[1].type, ArgumentType.Object);
                {
                    Argument[] args21 = (Argument[])args2[1].data;
                    Assert.AreEqual(args21.Length, 4);

                    Assert.AreEqual(args21[0].type, ArgumentType.Integer);
                    Assert.AreEqual(args21[0].data, 4);

                    Assert.AreEqual(args21[1].type, ArgumentType.StringDouble);
                    Assert.AreEqual(args21[1].data, "test");

                    Assert.AreEqual(args21[2].type, ArgumentType.Integer);
                    Assert.AreEqual(args21[2].data, 8);

                    Assert.AreEqual(args21[3].type, ArgumentType.Char);
                    Assert.AreEqual(args21[3].data, 'y');
                }

                Assert.AreEqual(args2[2].type, ArgumentType.Boolean);
                Assert.AreEqual(args2[2].data, true);
            }

            Assert.AreEqual(args[3].type, ArgumentType.Object);
            {
                Argument[] args3 = (Argument[])args[3].data;
                Assert.AreEqual(args3.Length, 2);

                Assert.AreEqual(args3[0].type, ArgumentType.Boolean);
                Assert.AreEqual(args3[0].data, false);

                Assert.AreEqual(args3[1].type, ArgumentType.StringSingle);
                Assert.AreEqual(args3[1].data, "p2");
            }
        }
Exemplo n.º 27
0
        public void FirstLevelTest2()
        {
            IPM pm = new PM(new List<ILevel>());
            Assert.AreEqual(0, pm.Levels.Count);

            var lvl = pm.FirstLevel;
        }
Exemplo n.º 28
0
        public void pinToTest2()
        {
            try {
                IPM pm = new PM("left.solution.right");
                pm.pinTo(100);
                Assert.Fail("1");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException), ex.GetType().ToString()); }

            try {
                IPM pm = new PM("left.solution.right");
                pm.pinTo(-1);
                Assert.Fail("2");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException), ex.GetType().ToString()); }

            try {
                IPM pm = new PM("left.solution.right"); //4
                pm.pinTo(4);
                Assert.Fail("4");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException), ex.GetType().ToString()); }

            try {
                IPM pm = new PM("left.solution.right"); //4
                pm.pinTo(1);
                pm.pinTo(2);
                pm.pinTo(1);
                Assert.Fail("5");
            }
            catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException), ex.GetType().ToString()); }
        }
Exemplo n.º 29
0
        public void FirstLevelTest3()
        {
            IPM pm = new PM("left.solution.right");

            Assert.AreEqual("left", pm.Levels[0].Data);

            string newData = "Test";
            pm.Levels[0] = new Level() {
                Data = newData
            };

            Assert.AreEqual(newData, pm.Levels[0].Data);
        }
Exemplo n.º 30
0
        protected string stSolution(string data)
        {
            Log.Trace("stSolution: started with '{0}'", data);
            IPM pm = new PM(data);

            if(!pm.Is(0, LevelType.Property, "solution")) {
                throw new SyntaxIncorrectException("Failed stSolution - '{0}'", data);
            }

            // solution.current.
            if(pm.Is(1, LevelType.Property, "current"))
            {
                if(!env.IsOpenedSolution) {
                    throw new NotSupportedOperationException("Property 'current' is not available. Open the Solution or use 'path()' method instead.");
                }
                return stSlnPMap(env.SolutionFile, pm.pinTo(2));
            }

            // solution.path("file").
            if(pm.Is(1, LevelType.Method, "path"))
            {
                Argument[] args = pm.Levels[1].Args;
                if(args.Length != 1 || args[0].type != ArgumentType.StringDouble) {
                    throw new InvalidArgumentException("stSolution: incorrect arguments to `solution.path(string sln)`");
                }
                return stSlnPMap((string)args[0].data, pm.pinTo(2));
            }

            throw new OperationNotFoundException("stSolution: not found - '{0}' /'{1}'", pm.Levels[1].Data, pm.Levels[1].Type);
        }
Exemplo n.º 31
0
        public void FirstLevelTest4()
        {
            IPM pm = new PM(new List<ILevel>());
            Assert.AreEqual(0, pm.Levels.Count);

            pm.FirstLevel = new Level() { };
        }