public void ParseIfBlock() { JSProgram program = new JSProgram(); program.AddInputBlock("k", 10); program.AddOutputDeclarationBlock("z"); string left = program.AddConstantBlock(3); string right = program.AddConstantBlock(3); string conditionalBlock = program.AddBoolOPBlock(BoolOPTypes.EQ, left, right); program.AddScope("a"); program.SetScope("a"); string guardedBlock = program.AddOutputSegment("k", "z", 1, false); program.SetScope(JSProgram.DEFAULT_SCOPE_NAME); program.AddIfSegment(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); }
public void ParseBoolOPBlock() { JSProgram program = new JSProgram(); string a = program.AddConstantBlock(20); string b = program.AddConstantBlock(12); program.AddBoolOPBlock(BoolOPTypes.EQ, a, b); TestTools.ExecuteJS(program); XmlNode node = TestTools.GetWorkspace(); ParserInfo parserInfo = new ParserInfo(); BoolOP boolOP = (BoolOP)XmlParser.ParseBlock(node, new DFG <Block>(), parserInfo); Assert.AreEqual(0, parserInfo.ParseExceptions.Count, parserInfo.ParseExceptions.FirstOrDefault()?.Message); Assert.AreEqual(BoolOPTypes.EQ, boolOP.OPType); }