IsDefaultCount() public static méthode

public static IsDefaultCount ( string input, RegexOptions options, int count ) : bool
input string
options RegexOptions
count int
Résultat bool
Exemple #1
0
        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 async Task Replace(RegexEngine engine, string pattern, string input, string replacement, RegexOptions options, int count, int start, string expected)
        {
            // A few tests exceed the 1000 limit, they reach 6003
            RegexHelpers.SetSafeSizeThreshold(6005);
            Regex r;

            try
            {
                r = await RegexHelpers.GetRegexAsync(engine, pattern, options);
            }
            finally
            {
                RegexHelpers.RestoreSafeSizeThresholdToDefault();
            }

            bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, start);
            bool isDefaultCount = RegexHelpers.IsDefaultCount(input, options, count);

            if (isDefaultStart)
            {
                if (isDefaultCount)
                {
                    Assert.Equal(expected, r.Replace(input, replacement));
                    Assert.Equal(expected, Regex.Replace(input, pattern, replacement, options));
                }

                Assert.Equal(expected, r.Replace(input, replacement, count));
            }

            Assert.Equal(expected, r.Replace(input, replacement, count, start));
        }
Exemple #3
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.IsDefaultCount(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 async Task Replace_MatchEvaluator_Test(RegexEngine engine, 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);

            Regex r = await RegexHelpers.GetRegexAsync(engine, pattern, options);

            if (isDefaultStart && isDefaultCount)
            {
                Assert.Equal(expected, r.Replace(input, evaluator));
            }

            if (isDefaultStart)
            {
                Assert.Equal(expected, r.Replace(input, evaluator, count));
            }

            Assert.Equal(expected, r.Replace(input, evaluator, count, start));
        }
Exemple #5
0
        public async Task Split(RegexEngine engine, string pattern, string input, RegexOptions options, int count, int start, string[] expected)
        {
            bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, start);
            bool isDefaultCount = RegexHelpers.IsDefaultCount(input, options, count);

            Regex r = await RegexHelpers.GetRegexAsync(engine, pattern, options);

            if (isDefaultStart && isDefaultCount)
            {
                Assert.Equal(expected, r.Split(input));
            }

            if (isDefaultStart)
            {
                Assert.Equal(expected, r.Split(input, count));
            }

            Assert.Equal(expected, r.Split(input, 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);
        }
Exemple #7
0
        public async Task Replace(RegexEngine engine, string pattern, string input, string replacement, RegexOptions options, int count, int start, string expected)
        {
            Regex r = await RegexHelpers.GetRegexAsync(engine, pattern, options);

            bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, start);
            bool isDefaultCount = RegexHelpers.IsDefaultCount(input, options, count);

            if (isDefaultStart)
            {
                if (isDefaultCount)
                {
                    Assert.Equal(expected, r.Replace(input, replacement));
                    Assert.Equal(expected, Regex.Replace(input, pattern, replacement, options));
                }

                Assert.Equal(expected, r.Replace(input, replacement, count));
            }

            Assert.Equal(expected, r.Replace(input, replacement, count, start));
        }