예제 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public static string GetWindowText(
            IntPtr handle,
            ref Result error
            )
        {
            try
            {
                int length = UnsafeNativeMethods.GetWindowTextLength(handle);

                if (length > 0)
                {
                    length++; /* NUL terminator */

                    StringBuilder buffer = StringOps.NewStringBuilder(length);

                    if (UnsafeNativeMethods.GetWindowText(
                            handle, buffer, length) > 0)
                    {
                        return(buffer.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                error = e;
            }

            return(null);
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////

        private static string TranslateSubSpec(
            Regex regEx,        // original regular expression.
            string pattern,     // original pattern string.
            string input,       // original input string.
            string replacement, // original replacement string.
            string text,        // string with the subSpecs to process.
            bool quote,         // use list element quoting?
            bool extra,         // \P|I|S|M#|N<n> permitted in subSpec.
            bool strict,        // strict conformance to the Tcl docs.
            Match match         // current Regex match, if any.
            )
        {
            //
            // NOTE: Garbage in, garbage out.
            //
            if (String.IsNullOrEmpty(text))
            {
                return(text);
            }

            StringBuilder builder = StringOps.NewStringBuilder();

            for (int index = 0; index < text.Length; index++)
            {
                char character = text[index];

                HandleSubSpecChar(
                    regEx, pattern, input, replacement, text,
                    quote, extra, strict, match, builder,
                    character, ref index);
            }

            return(builder.ToString());
        }
예제 #3
0
        ///////////////////////////////////////////////////////////////////////

        private string Flatten()
        {
            if (results == null)
            {
                return(null);
            }

            long   capacity = EstimateCapacity();
            Result error    = null;

            if (!IsCapacityOk(capacity, MaximumCapacity, ref error))
            {
                throw new ScriptEngineException(error);
            }

            StringBuilder builder = StringOps.NewStringBuilder((int)capacity);

            foreach (Result result in results)
            {
                if (result == null)
                {
                    continue;
                }
                builder.Append(result);
            }

            return(builder.ToString());
        }
예제 #4
0
        ///////////////////////////////////////////////////////////////////////

        public string ToRawString(
            string separator
            )
        {
            StringBuilder result = StringOps.NewStringBuilder();

            foreach (IPair <string> element in this)
            {
                if (result.Length > 0)
                {
                    result.Append(separator);
                }

                if (element != null)
                {
                    result.Append(element.X);
                    result.Append(element.Y);
                }
                else
                {
                    result.Append((string)null);
                    result.Append((string)null);
                }
            }

            return(result.ToString());
        }
예제 #5
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region Public Network Server Methods
        public static ReturnCode GetServerScript(
            TcpClient client,
            string channelId,
            string oldScript,
            ref string newScript,
            ref Result error
            )
        {
            try
            {
                if (client != null)
                {
                    Socket socket = client.Client;

                    if (socket != null)
                    {
                        IPEndPoint endPoint = socket.RemoteEndPoint as IPEndPoint;

                        if (endPoint != null)
                        {
                            StringBuilder builder = StringOps.NewStringBuilder(oldScript);

                            builder.Append(Characters.Space);
                            builder.Append(channelId);
                            builder.Append(Characters.Space);
                            builder.Append(endPoint.Address);
                            builder.Append(Characters.Space);
                            builder.Append(endPoint.Port);

                            newScript = builder.ToString();

                            return(ReturnCode.Ok);
                        }
                        else
                        {
                            error = "invalid remote endpoint";
                        }
                    }
                    else
                    {
                        error = "invalid client socket";
                    }
                }
                else
                {
                    error = "invalid client";
                }
            }
            catch (Exception e)
            {
                error = e;
            }

            return(ReturnCode.Error);
        }
예제 #6
0
        ///////////////////////////////////////////////////////////////////////

        public string ToRawString()
        {
            StringBuilder result = StringOps.NewStringBuilder();

            foreach (string element in this)
            {
                result.Append(element);
            }

            return(result.ToString());
        }
예제 #7
0
            ///////////////////////////////////////////////////////////////////////////////////////////

            #region Private Methods
            private bool EnumWindowCallback(
                IntPtr hWnd,
                IntPtr lParam
                )
            {
                try
                {
                    string text   = null;
                    int    length = UnsafeNativeMethods.GetWindowTextLength(hWnd);

                    if (length > 0)
                    {
                        length++; /* NUL terminator */

                        buffer = StringOps.NewStringBuilder(buffer, length);

                        if (UnsafeNativeMethods.GetWindowText(
                                hWnd, buffer, length) > 0)
                        {
                            text = buffer.ToString();
                        }
                    }

                    string @class = null;
                    length = UnsafeNativeMethods.MAX_CLASS_NAME;

                    buffer = StringOps.NewStringBuilder(buffer, length);

                    if (UnsafeNativeMethods.GetClassName(
                            hWnd, buffer, length) > 0)
                    {
                        @class = buffer.ToString();
                    }

                    windows[hWnd] = new Pair <string>(@class, text);
                    return(true);
                }
                catch (Exception e)
                {
                    if (traceException)
                    {
                        //
                        // NOTE: Nothing much we can do here except log the
                        //       failure.
                        //
                        TraceOps.DebugTrace(
                            e, typeof(EnumWindowCallback).Name,
                            TracePriority.NativeError);
                    }
                }

                return(false);
            }
예제 #8
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public static string Concat(IList list, int startIndex, int stopIndex, string separator)
        {
            StringBuilder result = StringOps.NewStringBuilder();

            if (list != null)
            {
                if (CheckStartAndStopIndex(
                        0, list.Count - 1, ref startIndex, ref stopIndex))
                {
                    //
                    // NOTE: This function joins each of its arguments together
                    //       with spaces after trimming leading and trailing
                    //       white-space from each of them. If all the arguments
                    //       are lists, this has the same effect as concatenating
                    //       them into a single list. It permits any number of
                    //       arguments; if no args are supplied, the result is an
                    //       empty string.
                    //
                    for (int index = startIndex; index <= stopIndex; index++)
                    {
                        object element = list[index];

                        if (element == null)
                        {
                            continue;
                        }

                        string value = element.ToString();

                        if (String.IsNullOrEmpty(value))
                        {
                            continue;
                        }

                        value = value.Trim();

                        if (String.IsNullOrEmpty(value))
                        {
                            continue;
                        }

                        if (result.Length > 0)
                        {
                            result.Append(separator);
                        }

                        result.Append(value);
                    }
                }
            }

            return(result.ToString());
        }
예제 #9
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public static string Format( /* 0.1 */
            IDictionary <long, string> flags,
            bool legacy,
            bool compact,
            bool space,
            bool sort,
            ref Result error
            )
        {
            if (flags != null)
            {
                StringBuilder result = StringOps.NewStringBuilder();
                LongList      keys   = new LongList(flags.Keys);

                if (sort)
                {
                    keys.Sort(); /* NOTE: O(N^2) is the worst case. */
                }
                for (int index = 0; index < keys.Count; index++)
                {
                    long key = keys[index];

                    string keyFlags = compact ? (string)DictionaryToChars(
                        CharsToDictionary(flags[key]), sort) : flags[key];

                    if (key != NoKey)
                    {
                        result.AppendFormat(
                            legacy ? LegacyFlagFormat : FlagFormat,
                            key, keyFlags);
                    }
                    else
                    {
                        result.Append(keyFlags);
                    }

                    if (space && ((index + 1) < keys.Count))
                    {
                        result.Append(Characters.Space);
                    }
                }

                return(result.ToString());
            }

            error = "invalid flags";
            return(null);
        }
예제 #10
0
        ///////////////////////////////////////////////////////////////////////

        public string ToRawString(
            string separator
            )
        {
            StringBuilder result = StringOps.NewStringBuilder();

            foreach (string element in this)
            {
                if (result.Length > 0)
                {
                    result.Append(separator);
                }

                result.Append(element);
            }

            return(result.ToString());
        }
예제 #11
0
파일: TokenList.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public string ToString(
            string pattern,
            bool noCase
            )
        {
            StringBuilder result = StringOps.NewStringBuilder();

            for (int index = 0; index < this.Count; index++)
            {
                result.Append(this[index].ToString());

                if ((index + 1) < this.Count)
                {
                    result.Append(Characters.LineFeed);
                }
            }

            return(result.ToString());
        }
예제 #12
0
파일: ArrayOps.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        public static string ToHexadecimalString(
            byte[] array
            )
        {
            if (array == null)
            {
                return(null);
            }

            StringBuilder result = StringOps.NewStringBuilder();

            int length = array.Length;

            for (int index = 0; index < length; index++)
            {
                result.Append(FormatOps.Hexadecimal(array[index], false));
            }

            return(result.ToString());
        }
예제 #13
0
        ///////////////////////////////////////////////////////////////////////

        public string ToRawString(
            ToStringFlags toStringFlags,
            string separator
            )
        {
            StringBuilder result = StringOps.NewStringBuilder();

            foreach (Result element in this)
            {
                if (element != null)
                {
                    if ((separator != null) && (result.Length > 0))
                    {
                        result.Append(separator);
                    }

                    result.Append(element.ToString(toStringFlags));
                }
            }

            return(result.ToString());
        }
예제 #14
0
        ///////////////////////////////////////////////////////////////////////

        #region Private Static Methods
        private static StringBuilder NewStringBuilder(
            int capacity /* in */
            )
        {
            return(StringOps.NewStringBuilder(capacity));
        }
예제 #15
0
        ///////////////////////////////////////////////////////////////////////

        public string GetString(
            bool nested
            )
        {
            if (items == null)
            {
                return(null);
            }

            StringBuilder result = StringOps.NewStringBuilder();

            foreach (KeyValuePair <long, object> pair in items)
            {
                object value = pair.Value;

                if (value == null)
                {
                    continue;
                }

                ///////////////////////////////////////////////////////////////

                //
                // HACK: Add a command separator to the overall result.  This
                //       may have issues if literal strings are mixed in with
                //       the actual commands, especially if they contain any
                //       line-ending characters.  Right now, this is not done
                //       if the current value happens to be a string instead
                //       of a string list.
                //
                if ((result.Length > 0) && !(value is string))
                {
                    result.Append(nested ?
                                  Characters.SemiColon : Characters.LineFeed);
                }

                ///////////////////////////////////////////////////////////////

                //
                // NOTE: Always attempt to normalize the block line-endings to
                //       line-feed only, as required by the script engine.
                //
                StringBuilder block = StringOps.NewStringBuilder(
                    (value is IScript) ? ((IScript)value).Text :
                    value.ToString());

                StringOps.FixupLineEndings(block);

                ///////////////////////////////////////////////////////////////

                result.Append(block);
            }

            if (nested && (result.Length > 0))
            {
                result.Insert(0, Characters.OpenBracket);
                result.Append(Characters.CloseBracket);
            }

            return(result.ToString());
        }
예제 #16
0
파일: Append.cs 프로젝트: jdruin/F5Eagle
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count >= 2)
                    {
                        string varName = arguments[1];

                        if (arguments.Count == 2)
                        {
                            //
                            // NOTE: *SPECIAL CASE* For compatibility with Tcl, we must generate
                            //       an error if only two arguments are supplied and the variable
                            //       does not exist.
                            //
                            code = interpreter.GetVariableValue(
                                VariableFlags.DirectGetValueMask, varName, ref result,
                                ref result);
                        }
                        else
                        {
                            lock (interpreter.SyncRoot) /* TRANSACTIONAL */
                            {
                                StringBuilder builder;

                                if (interpreter.GetVariableValue(
                                        VariableFlags.DirectGetValueMask, varName,
                                        ref result) == ReturnCode.Ok)
                                {
                                    builder = StringOps.GetStringBuilderFromObject(result);
                                }
                                else
                                {
                                    builder = StringOps.NewStringBuilder();
                                }

                                for (int argumentIndex = 2; argumentIndex < arguments.Count; argumentIndex++)
                                {
                                    builder.Append(arguments[argumentIndex]);
                                }

                                code = interpreter.SetVariableValue2(
                                    VariableFlags.DirectSetValueMask, varName, builder,
                                    (TraceList)null, ref result);

                                if (code == ReturnCode.Ok)
                                {
                                    result = builder;
                                }
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"append varName ?value ...?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
예제 #17
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        private static ReturnCode Combine(
            IList <StringBuilder> list1,     /* in */
            IList <StringBuilder> list2,     /* in */
            ref IList <StringBuilder> list3, /* in, out */
            ref Result error                 /* out */
            )
        {
            if (list1 == null)
            {
                if (list2 == null)
                {
                    error = "cannot combine, neither list is valid";
                    return(ReturnCode.Error);
                }

                if (list3 != null)
                {
                    GenericOps <StringBuilder> .AddRange(list3, list2);
                }
                else
                {
                    list3 = new List <StringBuilder>(list2);
                }
            }
            else if (list2 == null)
            {
                if (list3 != null)
                {
                    GenericOps <StringBuilder> .AddRange(list3, list1);
                }
                else
                {
                    list3 = new List <StringBuilder>(list1);
                }
            }
            else
            {
                if ((list1.Count > 0) || (list2.Count > 0))
                {
                    if (list3 == null)
                    {
                        list3 = new List <StringBuilder>();
                    }
                }

                foreach (StringBuilder element1 in list1)
                {
                    foreach (StringBuilder element2 in list2)
                    {
                        int capacity = 0;

                        if (element1 != null)
                        {
                            capacity += element1.Length;
                        }

                        if (element2 != null)
                        {
                            capacity += element2.Length;
                        }

                        StringBuilder element3 = StringOps.NewStringBuilder(
                            capacity);

                        element3.Append(element1);
                        element3.Append(element2);

                        list3.Add(element3);
                    }
                }
            }

            return(ReturnCode.Ok);
        }
예제 #18
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region Public Methods
        public static IDictionary <long, string> Parse( /* 0.0 */
            string text,
            bool complex,
            bool space,
            bool sort,
            ref Result error
            )
        {
            if (text == null)
            {
                error = "invalid flags";
                return(null);
            }

            StringBuilder name  = StringOps.NewStringBuilder();
            StringBuilder value = StringOps.NewStringBuilder();

            IDictionary <long, IDictionary <char, long> > perKeyFlags =
                new Dictionary <long, IDictionary <char, long> >();

            bool haveName      = false;
            bool open          = false;
            long nonComplexKey = DefaultKey;
            long key           = nonComplexKey;

            for (int index = 0; index < text.Length; index++)
            {
                char character = text[index];

                switch (character)
                {
                case Characters.OpenBrace:
                {
                    if (!complex)
                    {
                        error = String.Format(
                            "unexpected open brace at index {0}, simple-only mode",
                            index);

                        return(null);
                    }

                    if (open)
                    {
                        error = String.Format(
                            "unexpected open brace at index {0}, already open",
                            index);

                        return(null);
                    }

                    //
                    // NOTE: This code cannot be reached.
                    //
                    // if (name.Length > 0)
                    // {
                    //     error = String.Format(
                    //         "unexpected name at index {0}",
                    //         index);
                    //
                    //     return null;
                    // }
                    //

                    if (value.Length > 0)
                    {
                        if (!Union(perKeyFlags, value, nonComplexKey, false))
                        {
                            //
                            // NOTE: This code cannot be reached.
                            //
                            error = String.Format(
                                "union of flags failed at index {0} for key {1}",
                                index, nonComplexKey);

                            return(null);
                        }

                        value.Length = 0;
                    }

                    open = true;
                    break;
                }

                case Characters.CloseBrace:
                {
                    if (!complex)
                    {
                        error = String.Format(
                            "unexpected close brace at index {0}, simple-only mode",
                            index);

                        return(null);
                    }

                    if (!open)
                    {
                        error = String.Format(
                            "unexpected close brace at index {0}, already closed",
                            index);

                        return(null);
                    }

                    if (!haveName)
                    {
                        error = String.Format(
                            "unexpected close brace at index {0}, name incomplete",
                            index);

                        return(null);
                    }

                    if (name.Length == 0)
                    {
                        error = String.Format(
                            "unexpected close brace at index {0}, name missing",
                            index);

                        return(null);
                    }

                    if (!HexadecimalNameToKey(name.ToString(), ref key))
                    {
                        //
                        // NOTE: This code cannot be reached.
                        //
                        error = String.Format(
                            "invalid name {0}, must be a hexadecimal long integer",
                            FormatOps.WrapOrNull(name));

                        return(null);
                    }

                    if (!Union(perKeyFlags, value, key, false))
                    {
                        //
                        // NOTE: This code cannot be reached.
                        //
                        error = String.Format(
                            "union of flags failed at index {0} for key {1}",
                            index, key);

                        return(null);
                    }

                    name.Length  = 0;
                    value.Length = 0;

                    haveName = false;
                    open     = false;
                    break;
                }

                default:
                {
                    if (haveName || !open)
                    {
                        if (space && Parser.IsWhiteSpace(character))
                        {
                            continue;
                        }

                        if (!CharIsValidValue(character))
                        {
                            error = String.Format(
                                "invalid value character '{0}' at index {1}",
                                character, index);

                            return(null);
                        }

                        value.Append(character);
                    }
                    else
                    {
                        if (space && Parser.IsWhiteSpace(character))
                        {
                            continue;
                        }

                        if (character == NameSepatator)
                        {
                            haveName = true;
                            continue;
                        }

                        if (!CharIsValidName(character))
                        {
                            error = String.Format(
                                "invalid name character '{0}' at index {1}",
                                character, index);

                            return(null);
                        }

                        name.Append(character);

                        if (name.Length == NameLength)
                        {
                            haveName = true;
                        }
                    }
                    break;
                }
                }
            }

            if (complex && open)
            {
                error = "close brace expected";

                return(null);
            }

            //
            // NOTE: This code cannot be reached.
            //
            // if (name.Length > 0)
            // {
            //     error = String.Format(
            //         "unexpected name at index {0}",
            //         text.Length);
            //
            //     return null;
            // }
            //

            if (value.Length > 0)
            {
                if (!Union(perKeyFlags, value, nonComplexKey, false))
                {
                    //
                    // NOTE: This code cannot be reached.
                    //
                    error = String.Format(
                        "union of flags failed at index {0} for key {1}",
                        text.Length, nonComplexKey);

                    return(null);
                }

                /* value.Length = 0; */
            }

            //
            // NOTE: Return the merged flags dictionary to the caller, sorted
            //       if necessary.
            //
            return(Merge(perKeyFlags, sort));
        }
예제 #19
0
        ///////////////////////////////////////////////////////////////////////

#if SHELL && INTERACTIVE_COMMANDS
        public static ReturnCode GetHelp(
            XmlDocument document,
            ref string text,
            ref Result error
            )
        {
            if (document == null)
            {
                error = "invalid xml document";
                return(ReturnCode.Error);
            }

            try
            {
                XmlNamespaceManager namespaceManager = null;

                if (GetNamespaceManager(
                        document.NameTable, ref namespaceManager,
                        ref error) != ReturnCode.Ok)
                {
                    return(ReturnCode.Error);
                }

                XmlNodeList nodeList = document.SelectNodes(
                    HelpXPath, namespaceManager);

                if ((nodeList == null) || (nodeList.Count == 0))
                {
                    error = "no help nodes found";
                    return(ReturnCode.Error);
                }

                StringBuilder builder = StringOps.NewStringBuilder();

                foreach (XmlNode node in nodeList)
                {
                    if (node == null)
                    {
                        continue;
                    }

                    string nodeText = node.InnerText.Trim();

                    if (String.IsNullOrEmpty(nodeText))
                    {
                        continue;
                    }

                    if (builder.Length > 0)
                    {
                        builder.Append(Characters.Space);
                    }

                    builder.Append(nodeText);
                }

                if (builder.Length == 0)
                {
                    error = "no help text found";
                    return(ReturnCode.Error);
                }

                text = builder.ToString();
                return(ReturnCode.Ok);
            }
            catch (Exception e)
            {
                error = e;
            }

            return(ReturnCode.Error);
        }
예제 #20
0
파일: Test1.cs 프로젝트: jdruin/F5Eagle
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if ((arguments.Count == 5) || (arguments.Count == 6))
                    {
                        ///////////////////////////////////////////////////////////////////////////////////////////////
                        //
                        // test name description ?constraints? body result
                        //
                        ///////////////////////////////////////////////////////////////////////////////////////////////

                        string name = arguments[1];

#if DEBUGGER
                        if (DebuggerOps.CanHitBreakpoints(interpreter,
                                                          EngineFlags.None, BreakpointType.Test))
                        {
                            code = interpreter.CheckBreakpoints(
                                code, BreakpointType.Test, name,
                                null, null, this, null, clientData,
                                arguments, ref result);
                        }

                        if (code == ReturnCode.Ok)
#endif
                        {
                            string description = arguments[2];

                            string          constraints;
                            string          body;
                            IScriptLocation bodyLocation;
                            string          expectedResult;

                            if (arguments.Count == 6)
                            {
                                constraints    = arguments[3];
                                body           = arguments[4];
                                bodyLocation   = arguments[4];
                                expectedResult = arguments[5];
                            }
                            else
                            {
                                constraints    = null;
                                body           = arguments[3];
                                bodyLocation   = arguments[3];
                                expectedResult = arguments[4];
                            }

                            ReturnCodeList returnCodes = new ReturnCodeList(new ReturnCode[] {
                                ReturnCode.Ok, ReturnCode.Return
                            });

                            MatchMode mode = StringOps.DefaultResultMatchMode;

                            bool noCase = false;

                            ///////////////////////////////////////////////////////////////////////////////////////////////

                            int testLevels = interpreter.EnterTestLevel();

                            try
                            {
                                //
                                // NOTE: Create a place to put all the output of the this command.
                                //
                                StringBuilder testData = StringOps.NewStringBuilder();

                                //
                                // NOTE: Are we going to skip this test?
                                //
                                bool skip = false;
                                bool fail = true;

                                code = TestOps.CheckConstraints(
                                    interpreter, testLevels, name, constraints,
                                    false, false, testData, ref skip, ref fail,
                                    ref result);

                                //
                                // NOTE: Track the fact that we handled this test.
                                //
                                int[] testStatistics = null;

                                if (code == ReturnCode.Ok)
                                {
                                    testStatistics = interpreter.TestStatistics;

                                    if ((testStatistics != null) && (testLevels == 1) && skip)
                                    {
                                        Interlocked.Increment(ref testStatistics[
                                                                  (int)TestInformationType.Total]);
                                    }
                                }

                                if ((code == ReturnCode.Ok) && !skip)
                                {
                                    code = TestOps.RecordInformation(
                                        interpreter, TestInformationType.Counts, name,
                                        null, true, ref result);
                                }

                                //
                                // NOTE: Check test constraints to see if we should run the test.
                                //
                                if ((code == ReturnCode.Ok) && !skip)
                                {
                                    ReturnCode bodyCode   = ReturnCode.Ok;
                                    Result     bodyResult = null;

                                    //
                                    // NOTE: Only run the test body if the setup is successful.
                                    //
                                    if (body != null)
                                    {
                                        TestOps.AppendFormat(
                                            interpreter, testData, TestOutputType.Start,
                                            "---- {0} start", name);

                                        TestOps.AppendLine(
                                            interpreter, testData, TestOutputType.Start);

                                        int savedPreviousLevels = interpreter.BeginNestedExecution();

                                        try
                                        {
                                            ICallFrame frame = interpreter.NewTrackingCallFrame(
                                                StringList.MakeList(this.Name, "body", name),
                                                CallFrameFlags.Test);

                                            interpreter.PushAutomaticCallFrame(frame);

                                            try
                                            {
                                                bodyCode = interpreter.EvaluateScript(
                                                    body, bodyLocation, ref bodyResult);

                                                if ((bodyResult == null) && ScriptOps.HasFlags(
                                                        interpreter, InterpreterFlags.TestNullIsEmpty,
                                                        true))
                                                {
                                                    bodyResult = String.Empty;
                                                }

                                                if (bodyCode == ReturnCode.Error)
                                                {
                                                    /* IGNORED */
                                                    interpreter.CopyErrorInformation(
                                                        VariableFlags.None, ref bodyResult);
                                                }
                                            }
                                            finally
                                            {
                                                //
                                                // NOTE: Pop the original call frame that we pushed above
                                                //       and any intervening scope call frames that may be
                                                //       leftover (i.e. they were not explicitly closed).
                                                //
                                                /* IGNORED */
                                                interpreter.PopScopeCallFramesAndOneMore();
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            bodyResult = e;
                                            bodyCode   = ReturnCode.Error;
                                        }
                                        finally
                                        {
                                            interpreter.EndNestedExecution(savedPreviousLevels);
                                        }
                                    }

                                    //
                                    // NOTE: Did we fail to match the return code?
                                    //
                                    bool codeFailure = !returnCodes.Contains(bodyCode);

                                    //
                                    // NOTE: Does the actual result match the expected result?
                                    //
                                    bool       scriptFailure = false;
                                    ReturnCode scriptCode    = ReturnCode.Ok;
                                    Result     scriptResult  = null;

                                    if (!codeFailure)
                                    {
                                        if (expectedResult != null)
                                        {
                                            scriptCode = TestOps.Match(
                                                interpreter, mode, bodyResult,
                                                expectedResult, noCase, null,
                                                TestOps.RegExOptions, false,
                                                ref scriptFailure, ref scriptResult);

                                            if (scriptCode == ReturnCode.Ok)
                                            {
                                                scriptFailure = !scriptFailure;
                                            }
                                            else
                                            {
                                                scriptFailure = true;
                                            }
                                        }
                                    }

                                    //
                                    // NOTE: If any of the important things failed, the test fails.
                                    //
                                    if (!(codeFailure || scriptFailure))
                                    {
                                        //
                                        // PASS: Test ran with no errors and the results match
                                        //       what we expected.
                                        //
                                        if ((testStatistics != null) && (testLevels == 1))
                                        {
                                            Interlocked.Increment(ref testStatistics[
                                                                      (int)TestInformationType.Passed]);

                                            Interlocked.Increment(ref testStatistics[
                                                                      (int)TestInformationType.Total]);
                                        }

                                        TestOps.AppendFormat(
                                            interpreter, testData, TestOutputType.Pass,
                                            "++++ {0} PASSED", name);

                                        TestOps.AppendLine(
                                            interpreter, testData, TestOutputType.Pass);
                                    }
                                    else
                                    {
                                        //
                                        // FAIL: Test ran with errors or the result does not match
                                        //       what we expected.
                                        //
                                        if ((testStatistics != null) && (testLevels == 1))
                                        {
                                            if (fail)
                                            {
                                                Interlocked.Increment(ref testStatistics[
                                                                          (int)TestInformationType.Failed]);

                                                Interlocked.Increment(ref testStatistics[
                                                                          (int)TestInformationType.Total]);
                                            }
                                        }

                                        //
                                        // NOTE: Keep track of each test that fails.
                                        //
                                        if (testLevels == 1)
                                        {
                                            TestOps.RecordInformation(
                                                interpreter, TestInformationType.FailedNames,
                                                name, null, true);
                                        }

                                        TestOps.AppendLine(
                                            interpreter, testData, TestOutputType.Fail);

                                        TestOps.AppendFormat(
                                            interpreter, testData, TestOutputType.Fail,
                                            "==== {0} {1} {2}", name, description.Trim(),
                                            fail ? "FAILED" : "IGNORED");

                                        TestOps.AppendLine(
                                            interpreter, testData, TestOutputType.Fail);

                                        if (body != null)
                                        {
                                            TestOps.AppendLine(
                                                interpreter, testData, TestOutputType.Body,
                                                "==== Contents of test case:");

                                            TestOps.AppendLine(
                                                interpreter, testData, TestOutputType.Body,
                                                body);
                                        }

                                        if (scriptFailure)
                                        {
                                            if (scriptCode == ReturnCode.Ok)
                                            {
                                                TestOps.AppendLine(
                                                    interpreter, testData, TestOutputType.Reason,
                                                    "---- Result was:");

                                                TestOps.AppendLine(
                                                    interpreter, testData, TestOutputType.Reason,
                                                    bodyResult);

                                                TestOps.AppendFormat(
                                                    interpreter, testData, TestOutputType.Reason,
                                                    "---- Result should have been ({0} matching):",
                                                    mode);

                                                TestOps.AppendLine(
                                                    interpreter, testData, TestOutputType.Reason);

                                                TestOps.AppendLine(
                                                    interpreter, testData, TestOutputType.Reason,
                                                    expectedResult);
                                            }
                                            else
                                            {
                                                TestOps.Append(
                                                    interpreter, testData, TestOutputType.Reason,
                                                    "---- Error testing result: ");

                                                TestOps.AppendLine(
                                                    interpreter, testData, TestOutputType.Reason,
                                                    scriptResult);

                                                if ((scriptResult != null) &&
                                                    (scriptResult.ErrorInfo != null))
                                                {
                                                    TestOps.Append(
                                                        interpreter, testData, TestOutputType.Error,
                                                        "---- errorInfo(matchResult): ");

                                                    TestOps.AppendLine(
                                                        interpreter, testData, TestOutputType.Error,
                                                        scriptResult.ErrorInfo);

                                                    TestOps.Append(
                                                        interpreter, testData, TestOutputType.Error,
                                                        "---- errorCode(matchResult): ");

                                                    TestOps.AppendLine(
                                                        interpreter, testData, TestOutputType.Error,
                                                        scriptResult.ErrorCode);
                                                }
                                            }
                                        }

                                        if (codeFailure)
                                        {
                                            ReturnCodeDictionary returnCodeMessages =
                                                interpreter.TestReturnCodeMessages;

                                            string codeMessage;

                                            if ((returnCodeMessages == null) ||
                                                (!returnCodeMessages.TryGetValue(
                                                     bodyCode, out codeMessage) &&
                                                 !returnCodeMessages.TryGetValue(
                                                     ReturnCode.Invalid, out codeMessage)))
                                            {
                                                codeMessage = "Unknown";
                                            }

                                            TestOps.AppendFormat(
                                                interpreter, testData, TestOutputType.Reason,
                                                "---- {0}; Return code was: {1}",
                                                codeMessage, bodyCode);

                                            TestOps.AppendLine(
                                                interpreter, testData, TestOutputType.Reason);

                                            TestOps.Append(
                                                interpreter, testData, TestOutputType.Reason,
                                                "---- Return code should have been one of: ");

                                            TestOps.AppendLine(
                                                interpreter, testData, TestOutputType.Reason,
                                                returnCodes.ToString());

                                            if ((bodyResult != null) &&
                                                (bodyResult.ErrorInfo != null) &&
                                                !returnCodes.Contains(ReturnCode.Error))
                                            {
                                                TestOps.Append(
                                                    interpreter, testData, TestOutputType.Error,
                                                    "---- errorInfo(body): ");

                                                TestOps.AppendLine(
                                                    interpreter, testData, TestOutputType.Error,
                                                    bodyResult.ErrorInfo);

                                                TestOps.Append(
                                                    interpreter, testData, TestOutputType.Error,
                                                    "---- errorCode(body): ");

                                                TestOps.AppendLine(
                                                    interpreter, testData, TestOutputType.Error,
                                                    bodyResult.ErrorCode);
                                            }
                                        }

                                        TestOps.AppendFormat(
                                            interpreter, testData, TestOutputType.Fail,
                                            "==== {0} {1}", name, fail ? "FAILED" : "IGNORED");

                                        TestOps.AppendLine(
                                            interpreter, testData, TestOutputType.Fail);
                                    }
                                }

                                //
                                // NOTE: Did the above code succeed?
                                //
                                if (code == ReturnCode.Ok)
                                {
                                    //
                                    // NOTE: The result is the complete output produced by the
                                    //       entire test.
                                    //
                                    if (testData != null)
                                    {
                                        result = testData;
                                    }
                                    else
                                    {
                                        result = String.Empty;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Engine.SetExceptionErrorCode(interpreter, e);

                                result = e;
                                code   = ReturnCode.Error;
                            }
                            finally
                            {
                                interpreter.ExitTestLevel();
                            }
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} name description constraints body result\"",
                            this.Name);

                        code = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }