Пример #1
0
        public void ParseRepeatBlock()
        {
            JSProgram program = new JSProgram();

            program.AddInputBlock("k", 10);
            program.AddOutputDeclarationBlock("z");

            string conditionalBlock = program.AddConstantBlock(3);

            program.AddScope("a");
            program.SetScope("a");
            string guardedBlock = program.AddOutputSegment("k", "z", 1, false);

            program.SetScope(JSProgram.DEFAULT_SCOPE_NAME);

            program.AddRepeatSegment(conditionalBlock, guardedBlock);
            program.Finish();

            TestTools.ExecuteJS(program);
            string xml = TestTools.GetWorkspaceString();

            (CDFG cdfg, var _) = XmlParser.Parse(xml);

            Assert.AreEqual(2, cdfg.Nodes.Count);

            DFG <Block> firstDFG = cdfg.StartDFG;

            Assert.AreEqual(5, firstDFG.Nodes.Count);

            (var _, DFG <Block> lastDFG) = cdfg.Nodes.Where(x => x.dfg != firstDFG).Single();
            Assert.AreEqual(1, lastDFG.Nodes.Count);
        }
Пример #2
0
        public void ParseOutputDeclarationBlock()
        {
            JSProgram program = new JSProgram();

            program.AddOutputDeclarationBlock("z");
            TestTools.ExecuteJS(program);

            XmlNode    node       = TestTools.GetWorkspace();
            ParserInfo parserInfo = new ParserInfo();

            parserInfo.EnterDFG();
            OutputDeclaration heater = (OutputDeclaration)XmlParser.ParseBlock(node, null, parserInfo, true);

            Assert.AreEqual(0, parserInfo.ParseExceptions.Count, parserInfo.ParseExceptions.FirstOrDefault()?.Message);
        }