public void DifferentInstructionWithZeroArgumentsShouldNotMatch()
        {
            var pattern = ExpressionPattern.InstructionLiteral(1234);
            var input   = new InstructionExpression <int>(5678, ImmutableArray <Expression <int> > .Empty);

            Assert.False(pattern.Matches(input));
        }
        public void SameInstructionWithZeroArgumentsShouldMatch()
        {
            var pattern = ExpressionPattern.InstructionLiteral(1234);
            var input   = new InstructionExpression <int>(1234, ImmutableArray <Expression <int> > .Empty);

            Assert.True(pattern.Matches(input));
        }
        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));
        }
        public void InstructionWithAnyArgumentsShouldMatchIfInstructionIsEqual(bool sameInstruction, int argumentCount)
        {
            var pattern = ExpressionPattern
                          .InstructionLiteral(1234)
                          .WithAnyArguments();

            var arguments = new List <Expression <int> >(argumentCount);

            for (int i = 0; i < argumentCount; i++)
            {
                arguments.Add(new InstructionExpression <int>(0, ImmutableArray <Expression <int> > .Empty));
            }

            var input = new InstructionExpression <int>(sameInstruction ? 1234 : 5678, arguments);

            var result = pattern.Match(input);

            Assert.Equal(sameInstruction, result.IsSuccess);
        }