public void PrecompiledRegex_MatchesTest()
        {
            string[]       expectedMatches = textWithMultipleMatches.Split(Environment.NewLine);
            RegexTestClass testClass       = new RegexTestClass();

            // Test Matches overloads
            Assert.Equal(1, testClass.Matches(text).Count);
            Assert.Equal(0, testClass.Matches(text, startat: 7).Count);
            MatchCollection multipleMatches = testClass.Matches(textWithMultipleMatches);

            Assert.Equal(4, multipleMatches.Count);
            for (int i = 0; i < expectedMatches.Length; i++)
            {
                Assert.Equal(expectedMatches[i], multipleMatches[i].Value.Trim()); // Calling Trim since the match will contain the new line as part of the match.
            }
        }
예제 #2
0
        public void TestPrecompiledRegex()
        {
            string         text      = "asdf134success1245something";
            RegexTestClass testClass = new RegexTestClass();

            Assert.Equal(1, testClass.Matches(text).Count);
            Assert.Equal(1, testClass.Match(text).Groups[0].Captures.Count);
            Assert.Equal(text, testClass.Match(text).Groups[0].Value);
            Assert.Equal(new int[] { 0, 1, 2 }, testClass.GetGroupNumbers());
            Assert.Equal(new string[] { "0", "1", "output" }, testClass.GetGroupNames());
        }