Exemplo n.º 1
0
        public void Split(string pattern, string input, RegexOptions options, int count, int start, string[] expected)
        {
            bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, start);
            bool isDefaultCount = RegexHelpers.IsDefaultStart(input, options, count);

            if (options == RegexOptions.None)
            {
                // Use Split(string), Split(string, string), Split(string, int) or Split(string, int, int)
                if (isDefaultStart && isDefaultCount)
                {
                    // Use Split(string) or Split(string, string)
                    Assert.Equal(expected, new Regex(pattern).Split(input));
                    Assert.Equal(expected, Regex.Split(input, pattern));
                }
                if (isDefaultStart)
                {
                    // Use Split(string, int)
                    Assert.Equal(expected, new Regex(pattern).Split(input, count));
                }
                // Use Split(string, int, int)
                Assert.Equal(expected, new Regex(pattern).Split(input, count, start));
            }
            if (isDefaultStart && isDefaultCount)
            {
                // Use Split(string, string, RegexOptions)
                Assert.Equal(expected, Regex.Split(input, pattern, options));
            }
            if (isDefaultStart)
            {
                // Use Split(string, int)
                Assert.Equal(expected, new Regex(pattern, options).Split(input, count));
            }
            // Use Split(string, int, int, int)
            Assert.Equal(expected, new Regex(pattern, options).Split(input, count, start));
        }
        public void Replace2(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));
        }
Exemplo n.º 3
0
        public void Match2(string pattern, string input, RegexOptions options, int beginning, int length, CaptureData[] expected)
        {
            bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, beginning);
            bool isDefaultCount = RegexHelpers.IsDefaultStart(input, options, length);

            if (options == RegexOptions.None)
            {
                if (isDefaultStart && isDefaultCount)
                {
                    // Use Match(string) or Match(string, string)
                    VerifyMatch(new Regex(pattern).Match(input), true, expected);
                    VerifyMatch(Regex.Match(input, pattern), true, expected);

                    Assert.True(new Regex(pattern).IsMatch(input));
                    Assert.True(Regex.IsMatch(input, pattern));
                }
                if (beginning + length == input.Length)
                {
                    // Use Match(string, int)
                    VerifyMatch(new Regex(pattern).Match(input, beginning), true, expected);

                    Assert.True(new Regex(pattern).IsMatch(input, beginning));
                }
                else
                {
                    // Use Match(string, int, int)
                    VerifyMatch(new Regex(pattern).Match(input, beginning, length), true, expected);
                }
            }
            if (isDefaultStart && isDefaultCount)
            {
                // Use Match(string) or Match(string, string, RegexOptions)
                VerifyMatch(new Regex(pattern, options).Match(input), true, expected);
                VerifyMatch(Regex.Match(input, pattern, options), true, expected);

                Assert.True(Regex.IsMatch(input, pattern, options));
            }
            if (beginning + length == input.Length)
            {
                // Use Match(string, int)
                VerifyMatch(new Regex(pattern, options).Match(input, beginning), true, expected);
            }
            if ((options & RegexOptions.RightToLeft) == 0)
            {
                // Use Match(string, int, int)
                VerifyMatch(new Regex(pattern, options).Match(input, beginning, length), true, expected);
            }
        }
Exemplo n.º 4
0
        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);
        }