public void Replace(string pattern, string input, MatchEvaluator evaluator, RegexOptions options, int count, int start, string expected) { bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, start); bool isDefaultCount = RegexHelpers.IsDefaultCount(input, options, count); if (options == RegexOptions.None) { if (isDefaultStart && isDefaultCount) { // Use Replace(string, MatchEvaluator) or Replace(string, string, MatchEvaluator) Assert.Equal(expected, new Regex(pattern).Replace(input, evaluator)); Assert.Equal(expected, Regex.Replace(input, pattern, evaluator)); } if (isDefaultStart) { // Use Replace(string, MatchEvaluator, string, int) Assert.Equal(expected, new Regex(pattern).Replace(input, evaluator, count)); } // Use Replace(string, MatchEvaluator, int, int) Assert.Equal(expected, new Regex(pattern).Replace(input, evaluator, count, start)); } if (isDefaultStart && isDefaultCount) { // Use Replace(string, MatchEvaluator) or Replace(string, MatchEvaluator, RegexOptions) Assert.Equal(expected, new Regex(pattern, options).Replace(input, evaluator)); Assert.Equal(expected, Regex.Replace(input, pattern, evaluator, options)); } if (isDefaultStart) { // Use Replace(string, MatchEvaluator, string, int) Assert.Equal(expected, new Regex(pattern, options).Replace(input, evaluator, count)); } // Use Replace(string, MatchEvaluator, int, int) Assert.Equal(expected, new Regex(pattern, options).Replace(input, evaluator, count, start)); }
public void Match(string pattern, string input, RegexOptions options, int beginning, int length, bool expectedSuccess, string expectedValue) { bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, beginning); bool isDefaultCount = RegexHelpers.IsDefaultCount(input, options, length); if (options == RegexOptions.None) { if (isDefaultStart && isDefaultCount) { // Use Match(string) or Match(string, string) VerifyMatch(new Regex(pattern).Match(input), expectedSuccess, expectedValue); VerifyMatch(Regex.Match(input, pattern), expectedSuccess, expectedValue); Assert.Equal(expectedSuccess, new Regex(pattern).IsMatch(input)); Assert.Equal(expectedSuccess, Regex.IsMatch(input, pattern)); } if (beginning + length == input.Length) { // Use Match(string, int) VerifyMatch(new Regex(pattern).Match(input, beginning), expectedSuccess, expectedValue); Assert.Equal(expectedSuccess, new Regex(pattern).IsMatch(input, beginning)); } // Use Match(string, int, int) VerifyMatch(new Regex(pattern).Match(input, beginning, length), expectedSuccess, expectedValue); } if (isDefaultStart && isDefaultCount) { // Use Match(string) or Match(string, string, RegexOptions) VerifyMatch(new Regex(pattern, options).Match(input), expectedSuccess, expectedValue); VerifyMatch(Regex.Match(input, pattern, options), expectedSuccess, expectedValue); Assert.Equal(expectedSuccess, Regex.IsMatch(input, pattern, options)); } if (beginning + length == input.Length && (options & RegexOptions.RightToLeft) == 0) { // Use Match(string, int) VerifyMatch(new Regex(pattern, options).Match(input, beginning), expectedSuccess, expectedValue); } // Use Match(string, int, int) VerifyMatch(new Regex(pattern, options).Match(input, beginning, length), expectedSuccess, expectedValue); }