Esempio n. 1
0
        public bool VerifyDecimalParse(string sInput, decimal dExpectedValue)
        {
            decimal dValue;

            if (!ParseUtil.ParseDecimal(sInput, out dValue))
            {
                return(false);
            }
            Assert.AreEqual(dExpectedValue, dValue);
            return(true);
        }
Esempio n. 2
0
        private string TranslateIfLogic(string sInput)
        {
            //Groups
            //    1    2  3            4    5   6
            //@"(if)(.*?)([!=><]=|<|>)(.*?)(then )(.*)");
            //Groups
            //    1    2  3            4    5      6    7      8
            //@"(if)(.*?)([!=><]=|<|>)(.*?)(then )(.*?)( else )(.*)");
            Match  zIfMatch = null;
            string sOutput  = string.Empty;
            bool   bHasElse = false;

            if (s_regexIfThenElseStatement.IsMatch(sInput))
            {
                zIfMatch = s_regexIfThenElseStatement.Match(sInput);
                bHasElse = true;
            }
            else if (s_regexIfThenStatement.IsMatch(sInput))
            {
                zIfMatch = s_regexIfThenStatement.Match(sInput);
            }
            if (null != zIfMatch)
            {
                string sCompareType = zIfMatch.Groups[3].ToString();
                var    eCheck       = LogicCheck.Equals;
                switch (sCompareType)
                {
                case "!=":
                    eCheck = LogicCheck.NotEquals;
                    break;

                case "==":
                    eCheck = LogicCheck.Equals;
                    break;

                case ">":
                    eCheck = LogicCheck.GreaterThan;
                    break;

                case "<":
                    eCheck = LogicCheck.LessThan;
                    break;

                case ">=":
                    eCheck = LogicCheck.GreaterThanOrEqualTo;
                    break;

                case "<=":
                    eCheck = LogicCheck.LessThanOrEqualTo;
                    break;
                }
                if (eCheck == LogicCheck.Equals || eCheck == LogicCheck.NotEquals)
                {
                    bool bCompare = CompareIfSet(zIfMatch.Groups[2].ToString(), zIfMatch.Groups[4].ToString());
                    if (eCheck == LogicCheck.NotEquals)
                    {
                        bCompare = !bCompare;
                    }
                    if (bCompare)
                    {
                        sOutput = zIfMatch.Groups[6].ToString();
                    }
                    else
                    {
                        if (bHasElse)
                        {
                            sOutput = zIfMatch.Groups[8].ToString();
                        }
                    }
                }
                else // numeric check
                {
                    decimal nValue1;
                    decimal nValue2;
                    bool    bSuccess = ParseUtil.ParseDecimal(zIfMatch.Groups[2].ToString(), out nValue1);
                    bSuccess &= ParseUtil.ParseDecimal(zIfMatch.Groups[4].ToString(), out nValue2);
                    if (!bSuccess)
                    {
                        return(string.Empty); // a mess!
                    }
                    bool bCompare = false;
                    switch (eCheck)
                    {
                    case LogicCheck.GreaterThan:
                        bCompare = nValue1 > nValue2;
                        break;

                    case LogicCheck.GreaterThanOrEqualTo:
                        bCompare = nValue1 >= nValue2;
                        break;

                    case LogicCheck.LessThan:
                        bCompare = nValue1 < nValue2;
                        break;

                    case LogicCheck.LessThanOrEqualTo:
                        bCompare = nValue1 <= nValue2;
                        break;
                    }
                    if (bCompare)
                    {
                        sOutput = zIfMatch.Groups[6].ToString();
                    }
                    else
                    {
                        if (bHasElse)
                        {
                            sOutput = zIfMatch.Groups[8].ToString();
                        }
                    }
                }
            }
            return(sOutput);
        }