Exemplo n.º 1
0
 public void FinalEmptyIsTest3()
 {
     IPM pm = new PM("left.solution.right");
     Assert.AreEqual(pm.Is(0, LevelType.Property, "right"), false);
     Assert.AreEqual(pm.FinalEmptyIs(1, LevelType.Property, "right"), false);
     Assert.AreEqual(pm.Is(2, LevelType.Property, "right"), true);
 }
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
0
        protected string stRaise(string data)
        {
            IPM pm = new PM(data);

            if(!pm.FinalEmptyIs(0, LevelType.Method, "raise")) {
                throw new OperationNotFoundException("stRaise: not found - '{0}' /'{1}'", pm.Levels[1].Data, pm.Levels[1].Type);
            }

            Argument[] args = pm.Levels[0].Args;

            if(args.Length != 4
                || args[0].type != ArgumentType.StringDouble
                || args[1].type != ArgumentType.Integer)
            {
                throw new InvalidArgumentException("stRaise: incorrect arguments to `raise(string guid, integer id, mixed customIn, mixed customOut)`");
            }

            string guid = (string)args[0].data;
            int id      = (int)args[1].data;

            object customIn;
            if(args[2].type == ArgumentType.Object) {
                customIn = (object)Value.extract((Argument[])args[2].data);
            }
            else {
                customIn = args[2].data;
            }

            object customOut;
            if(args[3].type == ArgumentType.Object) {
                customOut = (object)Value.extract((Argument[])args[3].data);
            }
            else {
                customOut = args[3].data;
            }

            Log.Trace("stRaise: guid - '{0}', id - '{1}', In - '{2}', Out - '{3}' ", guid, id, customIn, customOut);
            raise(guid, id, ref customIn, ref customOut);
            return String.Empty;
        }
Exemplo n.º 6
0
        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);
        }