Beispiel #1
0
        public void SetEndLocal()
        {
            EngineState s = EngineTests.CreateEngineState();

            void SingleTemplate(List <string> rawCodes, string destComp, string retComp, ErrorCheck check = ErrorCheck.Success)
            {
                s.Variables.DeleteKey(VarsType.Local, "Dest");
                s.ReturnValue = string.Empty;

                EngineTests.EvalLines(s, rawCodes, check);
                if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                {
                    string dest = s.Variables["Dest"];
                    string ret  = s.ReturnValue;
                    Assert.IsTrue(dest.Equals(destComp, StringComparison.Ordinal));
                    Assert.IsTrue(ret.Equals(retComp, StringComparison.Ordinal));
                }
            }

            void ScriptTemplate(string treePath, string entrySection, string destComp, string retComp, ErrorCheck check = ErrorCheck.Success)
            {
                s.Variables.DeleteKey(VarsType.Local, "Dest");
                s.ReturnValue = string.Empty;

                (EngineState st, _) = EngineTests.EvalScript(treePath, check, entrySection);
                if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                {
                    string dest = st.Variables["Dest"];
                    string ret  = st.ReturnValue;
                    Assert.IsTrue(dest.Equals(destComp, StringComparison.Ordinal));
                    Assert.IsTrue(ret.Equals(retComp, StringComparison.Ordinal));
                }
            }

            SingleTemplate(new List <string>
            {
                @"Set,%Dest%,0",
                @"Set,#r,A",
                @"System,SetLocal",
                @"Set,%Dest%,1",
                @"Set,#r,B",
                @"System,EndLocal",
            }, "0", "B");
            SingleTemplate(new List <string>
            {
                @"System,SetLocal",
                @"System,SetLocal",
                @"System,EndLocal",
            }, null, null, ErrorCheck.RuntimeError);
            SingleTemplate(new List <string>
            {
                @"System,EndLocal",
            }, null, null, ErrorCheck.RuntimeError);

            string scPath = Path.Combine(EngineTests.Project.ProjectName, "System", "SetEndLocal.script");

            ScriptTemplate(scPath, "Process-Simple", "0", "B");
            ScriptTemplate(scPath, "Process-Branch", "0", "B");
            ScriptTemplate(scPath, "Process-ImplicitEnd", "-1", "A", ErrorCheck.Warning);
        }
        public void Macro()
        {
            void ScriptTemplate(string treePath, string entrySection, ErrorCheck check = ErrorCheck.Success)
            {
                (EngineState s, _) = EngineTests.EvalScript(treePath, check, entrySection);
                if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                {
                    Dictionary <string, CodeCommand> macroDict = s.Macro.GetMacroDict(MacroType.Local);
                    Assert.IsTrue(macroDict.ContainsKey("SectionMacro"));
                    Assert.IsTrue(macroDict.ContainsKey("InlineMacro"));
                    Assert.IsTrue(macroDict.ContainsKey("CondMacro01"));
                    Assert.IsTrue(macroDict.ContainsKey("CondMacro02"));
                    Assert.IsTrue(macroDict.ContainsKey("PhoenixMacro"));

                    Assert.IsTrue(s.ReturnValue.Equals("T", StringComparison.Ordinal));
                }
            }

            string scPath = Path.Combine(EngineTests.Project.ProjectName, "Macro", "General.script");

            // ScriptTemplate(scPath, "Process-InlineMacro");
            // ScriptTemplate(scPath, "Process-SectionMacro");
            // ScriptTemplate(scPath, "Process-CondMacro01");
            // ScriptTemplate(scPath, "Process-CondMacro02");
            ScriptTemplate(scPath, "Process-PhoenixMacro");
        }
Beispiel #3
0
                static void ScriptTemplate(string treePath, string entrySection, MacroType type, ErrorCheck check = ErrorCheck.Success)
                {
                    (EngineState s, _) = EngineTests.EvalScript(treePath, check, entrySection);
                    if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                    {
                        Dictionary <string, CodeCommand> macroDict = s.Macro.GetMacroDict(type);
                        Assert.IsTrue(macroDict.ContainsKey("SectionMacro"));
                        Assert.IsTrue(macroDict.ContainsKey("InlineMacro"));

                        Assert.IsTrue(s.ReturnValue.Equals("T", StringComparison.Ordinal));
                    }
                }
Beispiel #4
0
        public void AddVariables()
        {
            // Add variables
            {
                EngineState s      = EngineTests.CreateEngineState();
                string      scPath = Path.Combine(EngineTests.BaseDir, Project.Names.Projects, "TestSuite", "Control", "General.script");

                void VariableTemplate(string rawCode, VarsType varsType)
                {
                    s.ReturnValue = string.Empty;
                    EngineTests.Eval(s, rawCode, CodeType.AddVariables, ErrorCheck.Success);

                    Assert.IsTrue(s.Variables.GetValue(varsType, "A").Equals("1", StringComparison.Ordinal));
                    Assert.IsTrue(s.Variables.GetValue(varsType, "B").Equals("2", StringComparison.Ordinal));
                    Assert.IsTrue(s.Variables.GetValue(varsType, "C").Equals("3", StringComparison.Ordinal));

                    Dictionary <string, CodeCommand> macroDict = s.Macro.GetMacroDict(varsType == VarsType.Global ? MacroType.Global : MacroType.Local);

                    Assert.IsTrue(macroDict.ContainsKey("InlineMacro"));
                    EngineTests.Eval(s, "InlineMacro", CodeType.Macro, ErrorCheck.Success);
                    Assert.IsTrue(s.ReturnValue.Equals("T", StringComparison.Ordinal));
                }

                VariableTemplate($"AddVariables,{scPath},TestVars", VarsType.Local);
                VariableTemplate($"AddVariables,{scPath},TestVars,GLOBAL", VarsType.Global);
            }

            // Add macro
            {
                void ScriptTemplate(string treePath, string entrySection, MacroType type, ErrorCheck check = ErrorCheck.Success)
                {
                    (EngineState s, _) = EngineTests.EvalScript(treePath, check, entrySection);
                    if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                    {
                        Dictionary <string, CodeCommand> macroDict = s.Macro.GetMacroDict(type);
                        Assert.IsTrue(macroDict.ContainsKey("SectionMacro"));
                        Assert.IsTrue(macroDict.ContainsKey("InlineMacro"));

                        Assert.IsTrue(s.ReturnValue.Equals("T", StringComparison.Ordinal));
                    }
                }

                string scPath = Path.Combine(EngineTests.Project.ProjectName, "Control", "General.script");
                ScriptTemplate(scPath, "Process-SectionMacro-Global", MacroType.Global);
                ScriptTemplate(scPath, "Process-SectionMacro-Local", MacroType.Local);
                ScriptTemplate(scPath, "Process-InlineMacro-Global", MacroType.Global);
                ScriptTemplate(scPath, "Process-InlineMacro-Local", MacroType.Local);
            }
        }
Beispiel #5
0
        public void OnBuildScriptExit()
        {
            void ScriptTemplate(string treePath, string entrySection, ErrorCheck check = ErrorCheck.Success)
            {
                (EngineState s, _) = EngineTests.EvalScript(treePath, check, entrySection);
                string destStr = s.Variables["Dest"];

                Assert.IsTrue(destStr.Equals("T", StringComparison.Ordinal));
            }

            string scPath = Path.Combine(EngineTests.Project.ProjectName, "System", "Callback.script");

            // OnBuildExit
            ScriptTemplate(scPath, "Process-BuildCallback");

            // OnScriptExit
            ScriptTemplate(scPath, "Process-ScriptCallback");
        }
Beispiel #6
0
        public void GetParam()
        {
            string scPath = Path.Combine(EngineTests.Project.ProjectName, "Control", "General.script");

            void ScriptTemplate(string treePath, string entrySection, ErrorCheck check = ErrorCheck.Success)
            {
                (EngineState s, _) = EngineTests.EvalScript(treePath, check, entrySection);
                if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                {
                    string destStr = s.Variables.GetValue(VarsType.Local, "Dest");
                    Assert.IsTrue(destStr.Equals("T", StringComparison.Ordinal));
                }
            }

            ScriptTemplate(scPath, "Process-GetParam00");
            ScriptTemplate(scPath, "Process-GetParam01");
            ScriptTemplate(scPath, "Process-GetParam09");
            ScriptTemplate(scPath, "Process-GetParam12");
            ScriptTemplate(scPath, "Process-GetParam16");
            ScriptTemplate(scPath, "Process-GetParam18");
        }
Beispiel #7
0
        public void ErrorOff()
        {
            EngineState s = EngineTests.CreateEngineState();

            void SingleTemplate(List <string> rawCodes, ErrorCheck check = ErrorCheck.Success)
            {
                EngineTests.EvalLines(s, rawCodes, check);
            }

            void ScriptTemplate(string treePath, ErrorCheck check = ErrorCheck.Success)
            {
                EngineTests.EvalScript(treePath, check);
            }

            SingleTemplate(new List <string>
            {
                @"System,ErrorOff",
                @"Error1",
            });
            SingleTemplate(new List <string>
            {
                @"System,ErrorOff,3",
                @"Error1",
                @"Error2",
                @"Error3",
            });
            SingleTemplate(new List <string>
            {
                @"System,ErrorOff,2",
                @"Error1",
                @"Error2",
                @"Error3",
            }, ErrorCheck.RuntimeError);

            string scPath = Path.Combine(EngineTests.Project.ProjectName, "System", "ErrorOff.script");

            ScriptTemplate(scPath);
        }