public void TestComplexCapture() { var valueExpression = new InstructionExpression <DummyInstruction>(DummyInstruction.Push(0, 1), ArraySegment <Expression <DummyInstruction> > .Empty); var statement = new ExpressionStatement <DummyInstruction>(new InstructionExpression <DummyInstruction>(DummyInstruction.Ret(1), new List <Expression <DummyInstruction> > { valueExpression })); // Define capture group. var returnValueGroup = new CaptureGroup("returnValue"); // Create ret(?) pattern. var pattern = StatementPattern.Expression( ExpressionPattern .Instruction(new DummyInstructionPattern(DummyOpCode.Ret)) .WithArguments( ExpressionPattern.Any <DummyInstruction>().CaptureAs(returnValueGroup) ) ); // Match. var result = pattern.Match(statement); // Extract return expression node. var capturedObject = result.Captures[returnValueGroup][0]; Assert.Same(valueExpression, capturedObject); }
public void SameInstructionWithDifferentArgumentCountShouldNotMatch() { var pattern = ExpressionPattern .InstructionLiteral(1234) .WithArguments(ExpressionPattern.Any <int>(), ExpressionPattern.Any <int>()); var arguments = new List <Expression <int> >(2) { new InstructionExpression <int>(0, ImmutableArray <Expression <int> > .Empty), }; var input = new InstructionExpression <int>(1234, arguments); Assert.False(pattern.Matches(input)); }
public void SameInstructionWithComplexMatchingArgumentsShouldNotMatch() { var pattern = ExpressionPattern .InstructionLiteral(1234) .WithArguments( ExpressionPattern.InstructionLiteral(1234) | ExpressionPattern.InstructionLiteral(5678), ExpressionPattern.Any <int>()); var arguments = new List <Expression <int> >(2) { new InstructionExpression <int>(5678, ImmutableArray <Expression <int> > .Empty), new InstructionExpression <int>(1, ImmutableArray <Expression <int> > .Empty), }; var input = new InstructionExpression <int>(1234, arguments); Assert.True(pattern.Matches(input)); }