Ejemplo n.º 1
0
        public static void TestEvalFailedError(string input, object thisArray, Language language)
        {
            try
            {
                Eval eval = new Eval(input, language);
                eval.Evaluate(thisArray);
            }
            catch (ParseException pe)
            {
                throw new ApplicationException("Eval parse error not expected. Input string '" + input + "' and parse error at index '" + pe.Index.ToString() + "'.");
            }
            catch (Exception)
            {
                return;
            }

            throw new ApplicationException("Eval error expected but not found. Input string '" + input + "'.");
        }
Ejemplo n.º 2
0
        public static void TestEvalSuccess(string input, TypeCode resultCode, object resultValue, object thisArray, Language language)
        {
            Eval eval = new Eval(input, language);
            EvalResult result = eval.Evaluate(thisArray);

            if ((resultCode != result.Type) ||                             
                ((resultValue == null) && (result.Value != null)) ||       
                ((result.Value != null) && (Type.GetTypeCode(resultValue.GetType()) != resultCode)))   
                throw new ApplicationException("Eval result type incorrect. Expected '" + resultCode.ToString() + "' but received '" + result.Type.ToString() + "' for input string '" + input + "'.");
            else
            {
                // Check result specific value
                switch (resultCode)
                {
                    case TypeCode.Boolean:
                        if ((Boolean)resultValue == (Boolean)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Byte:
                        if ((Byte)resultValue == (Byte)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Char:
                        if ((Char)resultValue == (Char)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.DateTime:
                        if ((DateTime)resultValue == (DateTime)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.DBNull:
                        if ((DBNull)resultValue == (DBNull)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Decimal:
                        if ((Decimal)resultValue == (Decimal)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Double:
                        if ((Double)resultValue == (Double)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Empty:
                        if (resultValue == null)
                            return;
                        else
                            break;
                    case TypeCode.Int16:
                        if ((Int16)resultValue == (Int16)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Int32:
                        if ((Int32)resultValue == (Int32)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Int64:
                        if ((Int64)resultValue == (Int64)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Object:
                        if (resultValue == result.Value)
                            return;
                        else
                            break;
                    case TypeCode.SByte:
                        if ((SByte)resultValue == (SByte)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Single:
                        if ((Single)resultValue == (Single)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.String:
                        if ((String)resultValue == (String)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.UInt16:
                        if ((UInt16)resultValue == (UInt16)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.UInt32:
                        if ((UInt32)resultValue == (UInt32)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.UInt64:
                        if ((UInt64)resultValue == (UInt64)result.Value)
                            return;
                        else
                            break;
                }

                throw new ApplicationException("Eval result value incorrect. Expected '" + resultValue.ToString() + "' but received '" + result.Value.ToString() + "' for input string '" + input + "'.");
            }
        }