Ejemplo n.º 1
0
        public void Beep_Template(EngineState s, string rawCode, BeepType beepType)
        {
            SectionAddress addr = EngineTests.DummySectionAddress();
            CodeCommand    cmd  = CodeParser.ParseStatement(rawCode, addr);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Beep));
            CodeInfo_Beep info = cmd.Info as CodeInfo_Beep;

            Assert.IsTrue(info.Type == beepType);
        }
Ejemplo n.º 2
0
        public void StrFormat_Date_4()
        {
            string         rawCode = "StrFormat,Date,%Dest%,yyymdd_hhnnss.zzz";
            SectionAddress addr    = EngineTests.DummySectionAddress();
            CodeCommand    cmd     = CodeParser.ParseStatement(rawCode, addr);

            // Successfully induced error
            if (cmd.Type == CodeType.Error)
            {
                return;
            }

            Assert.Fail();
        }
Ejemplo n.º 3
0
        public void StrFormat_Date_2()
        {
            string         rawCode = "StrFormat,DATE,#9,yyyymmddhhnnsszzz";
            SectionAddress addr    = EngineTests.DummySectionAddress();
            CodeCommand    cmd     = CodeParser.ParseStatement(rawCode, addr);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_StrFormat));
            CodeInfo_StrFormat info = cmd.Info as CodeInfo_StrFormat;

            Debug.Assert(info.SubInfo.GetType() == typeof(StrFormatInfo_Date));
            StrFormatInfo_Date subInfo = info.SubInfo as StrFormatInfo_Date;

            Assert.IsTrue(subInfo.FormatString.Equals("yyyyMMddHHmmssfff", StringComparison.Ordinal));
        }
Ejemplo n.º 4
0
        public void StrFormat_Date_1()
        {
            string         rawCode = "StrFormat,Date,%Dest%,yyyy-mm-dd_hh:nn:ss.zzz";
            SectionAddress addr    = EngineTests.DummySectionAddress();
            CodeCommand    cmd     = CodeParser.ParseStatement(rawCode, addr);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_StrFormat));
            CodeInfo_StrFormat info = cmd.Info as CodeInfo_StrFormat;

            Debug.Assert(info.SubInfo.GetType() == typeof(StrFormatInfo_Date));
            StrFormatInfo_Date subInfo = info.SubInfo as StrFormatInfo_Date;

            Assert.IsTrue(subInfo.FormatString.Equals("yyyy-MM-dd_HH:mm:ss.fff", StringComparison.Ordinal));
        }
Ejemplo n.º 5
0
        public void CodeParserEx()
        {
            StringBuilder b = new StringBuilder();

            b.AppendLine("If,ExistDir,%BaseDir%,Begin");
            b.AppendLine("  Set,%A%,True");
            b.AppendLine("  Echo,Hello");
            b.AppendLine("End");
            b.AppendLine("Else,Echo,World");
            b.AppendLine(@"FileCopy,1,2");

            PEBakeryScriptParser parser = Setup(b.ToString());

            CodesVisitor       visitor = new CodesVisitor(EngineTests.DummySectionAddress());
            List <CodeCommand> cmds    = visitor.Visit(parser.codes());

            Assert.IsTrue(cmds != null);
        }
Ejemplo n.º 6
0
        public void Branch_IfExistMacro()
        {
            EngineState         s    = EngineTests.CreateEngineState();
            BranchConditionType type = BranchConditionType.ExistMacro;
            BranchCondition     cond;

            // Test if Unicode can be used in macro name
            s.Macro.MacroDict["대한"]    = CodeParser.ParseStatement("Echo,054-790-6641", EngineTests.DummySectionAddress());
            s.Macro.LocalDict["Sonic"] = CodeParser.ParseStatement("Echo,Tails", EngineTests.DummySectionAddress());
            s.Variables.SetValue(VarsType.Local, "Tails", "Sonic");

            cond = new BranchCondition(type, false, "대한");
            Assert.IsTrue(cond.Check(s, out string d));
            cond = new BranchCondition(type, false, "민국");
            Assert.IsFalse(cond.Check(s, out d));
            cond = new BranchCondition(type, false, "Sonic");
            Assert.IsTrue(cond.Check(s, out d));
            cond = new BranchCondition(type, false, "%Tails%");
            Assert.IsTrue(cond.Check(s, out d));

            cond = new BranchCondition(type, true, "대한");
            Assert.IsFalse(cond.Check(s, out d));
            cond = new BranchCondition(type, true, "민국");
            Assert.IsTrue(cond.Check(s, out d));
            cond = new BranchCondition(type, true, "Sonic");
            Assert.IsFalse(cond.Check(s, out d));
            cond = new BranchCondition(type, true, "%Tails%");
            Assert.IsFalse(cond.Check(s, out d));

            BranchCondition_Single_Template(s, @"If,ExistMacro,대한,Set,%Dest%,T", "T");
            BranchCondition_Single_Template(s, @"If,ExistMacro,민국,Set,%Dest%,T", "F");
            BranchCondition_Single_Template(s, @"If,ExistMacro,Sonic,Set,%Dest%,T", "T");
            BranchCondition_Single_Template(s, @"If,ExistMacro,%Tails%,Set,%Dest%,T", "T");
            BranchCondition_Single_Template(s, @"If,Not,ExistMacro,대한,Set,%Dest%,T", "F");
            BranchCondition_Single_Template(s, @"If,Not,ExistMacro,민국,Set,%Dest%,T", "T");
            BranchCondition_Single_Template(s, @"If,Not,ExistMacro,Sonic,Set,%Dest%,T", "F");
            BranchCondition_Single_Template(s, @"If,Not,ExistMacro,%Tails%,Set,%Dest%,T", "F");
        }