Ejemplo n.º 1
0
        private void ApplyRichTextBoxScript(RichTextBox richTextBox, bool refreshSelection = true)
        {
            if (richTextBox.Lines.Length != 0)
            {
                bool succeeded = mScriptParsingPlugin.ApplyLinesInternal(
                    richTextBox.Lines,
                    0,
                    richTextBox.Lines.Length,
                    GlueViewState.Self.CurrentElement,
                    mClassLevelCodeContext, null);

                //if (succeeded && richTextBox.BackColor != Color.White)
                //{
                //    richTextBox.BackColor = Color.White;
                //}
                //else if (!succeeded && richTextBox.BackColor != Color.Pink)
                //{
                //    richTextBox.BackColor = Color.Pink;
                //}
                if (refreshSelection)
                {
                    richTextBox.Invoke((MethodInvoker)(() =>
                    {
                        int oldSelection = richTextBox.SelectionStart;

                        if (!succeeded)
                        {
                            int errorLine = mScriptParsingPlugin.LastErrorLine;

                            if (errorLine != -1)
                            {
                                MarkLineAsRed(richTextBox, errorLine);
                            }
                        }
                        else
                        {
                            richTextBox.Select(0, richTextBox.Text.Length);


                            richTextBox.SelectionBackColor = System.Drawing.Color.White;
                            richTextBox.SelectionColor = System.Drawing.Color.Black;
                            //richTextBox.SelectionColor = Color.Red;
                        }
                        richTextBox.Select(oldSelection, 0);
                    }));
                }
            }
            else
            {
                //if (richTextBox.BackColor != Color.White)
                //{
                //    richTextBox.BackColor = Color.White;
                //}
            }
        }
        public void TestUnaryAndAssignmentOperators()
        {
            CodeContext codeContext = new CodeContext(null);

            string[] lines = new string[] { "int m = 3;", "m++;" };

            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, null, codeContext);

            if ((int)codeContext.VariableStack[0]["m"] != 4)
            {
                throw new Exception("The ++ operator is not working.");
            }

            lines = new string[] { "m=8;" };
            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, null, codeContext);
            if ((int)codeContext.VariableStack[0]["m"] != 8)
            {
                throw new Exception("The += operator is not working.");
            }

            lines = new string[] { "m+=3;" };
            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, null, codeContext);
            if ((int)codeContext.VariableStack[0]["m"] != 11)
            {
                throw new Exception("The += operator is not working.");
            }

            lines = new string[] { "m-=3;" };
            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, null, codeContext);
            if ((int)codeContext.VariableStack[0]["m"] != 8)
            {
                throw new Exception("The += operator is not working.");
            }

            lines = new string[] { "m*=3;" };
            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, null, codeContext);
            if ((int)codeContext.VariableStack[0]["m"] != 24)
            {
                throw new Exception("The += operator is not working.");
            }
        }