Exemplo n.º 1
0
        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));
        }