Ejemplo n.º 1
0
        public static void RunExpressionTest(InstructionSpan instructions, Expression expectedExpression)
        {
            // Add a `pop` to the end to make it a full statement
            instructions = BuildSpan(
                instructions.First.Offset,
                Enumerable.Concat(instructions, new[] { Instruction.Create(OpCodes.Pop) }));

            var controlFlowGraph = ControlFlowGraphBuilder.Build(instructions.ToList(), Array.Empty <ExceptionHandler>());
            var actualGraph      = SyntaxGraphBuilder.Create(controlFlowGraph, new MethodVariables());

            // Extract the expression
            Assert.Equal(1, actualGraph.Nodes.Count);

            var node = actualGraph.Nodes.First();

            Assert.Equal(1, node.Statements.Count);
            var discardStatement = Assert.IsType <DiscardStatement>(node.Statements.Single());

            Assert.Equal(expectedExpression, discardStatement.Value);
        }
Ejemplo n.º 2
0
        public static void RunControlFlowTest(InstructionSpan instructions, ControlFlowGraph expectedGraph)
        {
            var actualGraph = ControlFlowGraphBuilder.Build(instructions.ToList(), Array.Empty <ExceptionHandler>());

            Assert.Equal(expectedGraph, actualGraph, TestControlFlowGraphComparer.Instance);
        }