Example #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);
        }
Example #2
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);
        }
        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);
        }
Example #4
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);
        }
Example #5
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");
            }
        }
Example #6
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"));
        }
Example #7
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));
        }
Example #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);
        }
Example #9
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);
        }
Example #10
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);
 }
Example #11
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);
 }
Example #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);
 }
Example #13
0
        public void detectArgumentTest4()
        {
            IPM pm = new PM("solution(\"str \\\" data1 \\\" \", \"str \\' data2 \\' \", 'str \\' data3 \\' ', 'str \\\" data4 \\\" ')");

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

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

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

            Assert.AreEqual(args[2].type, ArgumentType.StringSingle);
            Assert.AreEqual(args[2].data, "str ' data3 ' ");

            Assert.AreEqual(args[3].type, ArgumentType.StringSingle);
            Assert.AreEqual(args[3].data, "str \\\" data4 \\\" ");
        }
        protected string stOut(string data)
        {
            IPM pm = new PM(data);

            if(!pm.Is(0, LevelType.Property, "out") && !pm.Is(0, LevelType.Method, "out")) {
                throw new SyntaxIncorrectException("Failed stOut - '{0}'", data);
            }

            string item = Settings._.DefaultOWPItem; // by default for all
            bool isGuid = false;

            if(pm.Is(0, LevelType.Method, "out"))
            {
                Argument[] args = pm.Levels[0].Args;
                if((args.Length < 1 || args.Length > 2)
                    || args[0].type != ArgumentType.StringDouble
                    || (args.Length == 2 && args[1].type != ArgumentType.Boolean))
                {
                    throw new InvalidArgumentException("stOut: incorrect arguments to `out(string ident [, boolean isGuid])`");
                }

                item    = (string)args[0].data;
                isGuid  = (args.Length == 2)? (bool)args[1].data : false; // optional isGuid param
            }

            Log.Trace("stOut: out = item('{0}'), isGuid('{1}')", item, isGuid);

            IItemEW ew = OWPItems._.getEW((isGuid)? new OWPIdent() { guid = item } : new OWPIdent() { item = item });
            string raw = StringHandler.escapeQuotes(ew.Raw);

            // #[OWP out.All] / #[OWP out] / #[OWP out("Build").All] / #[OWP out("Build")] ...
            if(pm.FinalEmptyIs(1, LevelType.Property, "All") || pm.FinalEmptyIs(1, LevelType.RightOperandEmpty)) {
                return raw;
            }

            // #[OWP out.Warnings.Count] ...
            if(pm.Is(1, LevelType.Property, "Warnings") && pm.FinalEmptyIs(2, LevelType.Property, "Count")) {
                return Value.from(ew.WarningsCount);
            }

            // #[OWP out.Warnings.Codes] ...
            if(pm.Is(1, LevelType.Property, "Warnings") && pm.FinalEmptyIs(2, LevelType.Property, "Codes")) {
                return Value.from(ew.Warnings);
            }

            // #[OWP out.Warnings.Raw] / #[OWP out.Warnings] ...
            if((pm.Is(1, LevelType.Property, "Warnings") && pm.FinalEmptyIs(2, LevelType.Property, "Raw"))
                || pm.FinalEmptyIs(1, LevelType.Property, "Warnings"))
            {
                return (ew.IsWarnings)? raw : String.Empty;
            }

            // #[OWP out.Errors.Count] ...
            if(pm.Is(1, LevelType.Property, "Errors") && pm.FinalEmptyIs(2, LevelType.Property, "Count")) {
                return Value.from(ew.ErrorsCount);
            }

            // #[OWP out.Errors.Codes] ...
            if(pm.Is(1, LevelType.Property, "Errors") && pm.FinalEmptyIs(2, LevelType.Property, "Codes")) {
                return Value.from(ew.Errors);
            }

            // #[OWP out.Errors.Raw] / #[OWP out.Errors] ...
            if((pm.Is(1, LevelType.Property, "Errors") && pm.FinalEmptyIs(2, LevelType.Property, "Raw"))
                || pm.FinalEmptyIs(1, LevelType.Property, "Errors"))
            {
                return (ew.IsErrors)? raw : String.Empty;
            }

            throw new OperationNotFoundException("stOut: not found - '{0}' /'{1}'", pm.Levels[1].Data, pm.Levels[1].Type);
        }
        protected string stHash(string data)
        {
            IPM pm = new PM(data);

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

            // hash.MD5("data")
            if(pm.FinalEmptyIs(1, LevelType.Method, "MD5"))
            {
                Argument[] args = pm.Levels[1].Args;
                if(args.Length != 1 || args[0].type != ArgumentType.StringDouble) {
                    throw new InvalidArgumentException("stHash: incorrect arguments to `hash.MD5(string data)`");
                }
                return ((string)args[0].data).MD5Hash();
            }

            // hash.SHA1("data")
            if(pm.FinalEmptyIs(1, LevelType.Method, "SHA1"))
            {
                Argument[] args = pm.Levels[1].Args;
                if(args.Length != 1 || args[0].type != ArgumentType.StringDouble) {
                    throw new InvalidArgumentException("stHash: incorrect arguments to `hash.SHA1(string data)`");
                }
                return ((string)args[0].data).SHA1Hash();
            }

            throw new OperationNotFoundException("stHash: not found - '{0}' /'{1}'", pm.Levels[1].Data, pm.Levels[1].Type);
        }