コード例 #1
0
ファイル: PcreTests.cs プロジェクト: yusufozturk/pcre-net
        private static void CompareGroups(TestPattern pattern, PcreMatch actualMatch, ExpectedMatch expectedMatch)
        {
            var actualGroups   = actualMatch.ToList();
            var expectedGroups = expectedMatch.Groups.ToList();

            Assert.That(actualGroups.Count, Is.GreaterThanOrEqualTo(expectedGroups.Count));

            for (var groupIndex = 0; groupIndex < actualGroups.Count; ++groupIndex)
            {
                var actualGroup   = actualGroups[groupIndex];
                var expectedGroup = groupIndex < expectedGroups.Count
                    ? expectedGroups[groupIndex]
                    : ExpectedGroup.Unset;

                Assert.That(actualGroup.Success, Is.EqualTo(expectedGroup.IsMatch));

                if (expectedGroup.IsMatch)
                {
                    var expectedValue = pattern.SubjectLiteral
                        ? expectedGroup.Value
                        : expectedGroup.Value.UnescapeGroup();

                    Assert.That(actualGroup.Value, Is.EqualTo(expectedValue));
                }
            }
        }
コード例 #2
0
 public override void Append(PcreMatch match, StringBuilder sb)
 {
     for (var i = match.CaptureCount; i > 0; --i)
     {
         var group = match[i];
         if (group != null && group.Success)
         {
             sb.Append(match.Subject, group.Index, group.Length);
             return;
         }
     }
 }
コード例 #3
0
            public override void Append(PcreMatch match, StringBuilder sb)
            {
                var group = match[_name] ?? match[_index];

                if (group == null)
                {
                    _fallback?.Append(match, sb);
                    return;
                }

                if (group.Success)
                {
                    sb.Append(match.Subject, group.Index, group.Length);
                }
            }
コード例 #4
0
        private static void CompareGroups(PcreMatch actualMatch, ExpectedMatch expectedMatch)
        {
            var actualGroups   = actualMatch.ToList();
            var expectedGroups = expectedMatch.Groups.ToList();

            Assert.That(actualGroups.Count, Is.GreaterThanOrEqualTo(expectedGroups.Count));

            for (var groupIndex = 0; groupIndex < actualGroups.Count; ++groupIndex)
            {
                var actualGroup   = actualGroups[groupIndex];
                var expectedGroup = groupIndex < expectedGroups.Count
                    ? expectedGroups[groupIndex]
                    : ExpectedGroup.Unset;

                Console.WriteLine("    Group #{0}: {1}", groupIndex, expectedGroup.Value);

                Assert.That(actualGroup.Success, Is.EqualTo(expectedGroup.IsMatch));

                if (expectedGroup.IsMatch)
                {
                    Assert.That(actualGroup.Value, Is.EqualTo(expectedGroup.Value.UnescapeGroup()));
                }
            }
        }
コード例 #5
0
 private static void CompareRemainingString(PcreMatch actualMatch, ExpectedMatch expectedMatch)
 {
     Assert.That(actualMatch.Subject.Substring(actualMatch.Index + actualMatch.Length), Is.EqualTo(expectedMatch.RemainingString.UnescapeGroup()));
 }
コード例 #6
0
 private static void CompareMark(PcreMatch actualMatch, ExpectedMatch expectedMatch)
 {
     Assert.That(actualMatch.Mark, Is.EqualTo(expectedMatch.Mark.UnescapeGroup()));
 }
コード例 #7
0
 public override void Append(PcreMatch match, StringBuilder sb)
 => sb.Append(match.Subject);
コード例 #8
0
            public override void Append(PcreMatch match, StringBuilder sb)
            {
                var endOfMatch = match.EndIndex;

                sb.Append(match.Subject, endOfMatch, match.Subject.Length - endOfMatch);
            }
コード例 #9
0
 public override void Append(PcreMatch match, StringBuilder sb)
 => sb.Append(_text, _startIndex, _length);
コード例 #10
0
 public abstract void Append(PcreMatch match, StringBuilder sb);
コード例 #11
0
ファイル: StressTests.cs プロジェクト: BaisilG/Patterns
        public void PcreRegex_Good()
        {
            PcreMatch match = pcreregex.Match(goodGibberish);

            Assert.True(match.Success);
        }
コード例 #12
0
 public override void Append(PcreMatch match, StringBuilder sb)
 {
     sb.Append(match.Subject, 0, match.Index);
 }