/// <summary> /// Returns a regular expression that matches this regular expression, followed by the specified one, and /// generates a result object that combines the result of this regular expression with the match of the other.</summary> protected TCombinedGenerex then <TOtherGenerex, TOtherGenerexMatch, TOtherMatch, TCombinedGenerex, TCombinedGenerexMatch, TCombinedResult>(TOtherGenerex other, Func <TResult, TOtherGenerexMatch, TCombinedResult> selector) where TOtherGenerex : GenerexBase <T, TOtherMatch, TOtherGenerex, TOtherGenerexMatch> where TOtherGenerexMatch : GenerexMatch <T> where TCombinedGenerex : GenerexWithResultBase <T, TCombinedResult, TCombinedGenerex, TCombinedGenerexMatch> where TCombinedGenerexMatch : GenerexMatch <T, TCombinedResult> { if (other == null) { throw new ArgumentNullException("other"); } if (selector == null) { throw new ArgumentNullException("selector"); } return(GenerexBase <T, LengthAndResult <TCombinedResult>, TCombinedGenerex, TCombinedGenerexMatch> .Constructor( (input, startIndex) => _forwardMatcher(input, startIndex).SelectMany(m => other._forwardMatcher(input, startIndex + m.Length) .Select(m2 => new LengthAndResult <TCombinedResult>(selector(m.Result, other.createMatch(input, startIndex + m.Length, m2)), m.Length + other.getLength(m2)))), (input, startIndex) => other._backwardMatcher(input, startIndex).Select(m2 => new { Match = other.createBackwardsMatch(input, startIndex, m2), Length = other.getLength(m2) }) .SelectMany(inf => _backwardMatcher(input, startIndex + inf.Length).Select(m => new LengthAndResult <TCombinedResult>(selector(m.Result, inf.Match), m.Length + inf.Length))) )); }
static void assertMatchesBase <T, TMatch, TGenerex, TGenerexMatch>(GenerexBase <T, TMatch, TGenerex, TGenerexMatch> generex, T[] input, Expectation isMatch, Expectation isMatchAt1, Expectation isMatchUpTo1, Expectation isMatchExact, Expectation isMatchReverse, object[] match, object[] matchExact, object[] matchReverse, int matches, int matchesReverse) where TGenerex : GenerexBase <T, TMatch, TGenerex, TGenerexMatch> where TGenerexMatch : GenerexMatch <T> { // Test 1: generex.Method(input) assertExpectation(isMatch, () => generex.IsMatch(input)); assertExpectation(isMatchAt1, () => generex.IsMatchAt(input, 1)); assertExpectation(isMatchUpTo1, () => generex.IsMatchUpTo(input, input.Length - 1)); assertExpectation(isMatchExact, () => generex.IsMatchExact(input)); assertExpectation(isMatchReverse, () => generex.IsMatchReverse(input)); assertIntOrThrow(matches, () => generex.Matches(input).Count()); assertIntOrThrow(matchesReverse, () => generex.MatchesReverse(input).Count()); // Test 2: input.Method(generex) assertExpectation(isMatch, () => input.IsMatch(generex)); assertExpectation(isMatchAt1, () => input.IsMatchAt(generex, 1)); assertExpectation(isMatchUpTo1, () => input.IsMatchUpTo(generex, input.Length - 1)); assertExpectation(isMatchExact, () => input.IsMatchExact(generex)); assertExpectation(isMatchReverse, () => input.IsMatchReverse(generex)); assertIntOrThrow(matches, () => input.Matches(generex).Count()); assertIntOrThrow(matchesReverse, () => input.MatchesReverse(generex).Count()); }