Ejemplo n.º 1
0
        public void WhenPartMatchesReturnsTrueCharacterClassMatchesReturnsTrue()
        {
            var mockCharacterClassPart = new Mock <ICharacterClassPart>();

            mockCharacterClassPart.Setup(m => m.Matches(It.IsAny <char>())).Returns(true);

            var sut = new CharacterClass(new[] { mockCharacterClassPart.Object }, false, false, 0, "[a]");

            Assert.That(sut.Matches('a'), Is.True);
        }
Ejemplo n.º 2
0
        protected override bool Matches(State state)
        {
            if (Negated)
            {
                throw new NotImplementedException();
            }

            if (IsAtBeginningOfInput(state) ||
                IsAtBeginningOfLine(state) ||
                IsAtEndOfInput(state) ||
                IsAtEndOfLine(state))
            {
                return(true);
            }

            // Make sure we have at least two charaters in the input, and we're not at the beginning or the end of the input.
            Debug.Assert(state.Input.Length > 1 && state.Index > 0 && state.Index < state.Input.Length);

            var isMatch = _wordCharacters.Matches(state.Input[state.Index])
                          != _wordCharacters.Matches(state.Input[state.Index - 1]);

            return(isMatch);
        }