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)); } } }
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; } } }
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); } }
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())); } } }
private static void CompareRemainingString(PcreMatch actualMatch, ExpectedMatch expectedMatch) { Assert.That(actualMatch.Subject.Substring(actualMatch.Index + actualMatch.Length), Is.EqualTo(expectedMatch.RemainingString.UnescapeGroup())); }
private static void CompareMark(PcreMatch actualMatch, ExpectedMatch expectedMatch) { Assert.That(actualMatch.Mark, Is.EqualTo(expectedMatch.Mark.UnescapeGroup())); }
public override void Append(PcreMatch match, StringBuilder sb) => sb.Append(match.Subject);
public override void Append(PcreMatch match, StringBuilder sb) { var endOfMatch = match.EndIndex; sb.Append(match.Subject, endOfMatch, match.Subject.Length - endOfMatch); }
public override void Append(PcreMatch match, StringBuilder sb) => sb.Append(_text, _startIndex, _length);
public abstract void Append(PcreMatch match, StringBuilder sb);
public void PcreRegex_Good() { PcreMatch match = pcreregex.Match(goodGibberish); Assert.True(match.Success); }
public override void Append(PcreMatch match, StringBuilder sb) { sb.Append(match.Subject, 0, match.Index); }