Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions main/OpenCover.Framework/Persistance/BasePersistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ private static void TransformSequences_JoinWithBranches (IEnumerable<Method> met
}
}

private static readonly RegexOptions regexOptions = RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.ExplicitCapture;
private static readonly Regex contractRegex = new Regex(@"^Contract\s\.\s(Requi|Ensu)res", regexOptions);
private static void TransformSequences_RemoveCompilerGeneratedBranches (IEnumerable<Method> methods, SourceRepository sourceRepository)
{
foreach (var method in methods) {
Expand Down Expand Up @@ -686,15 +688,12 @@ private static void TransformSequences_RemoveCompilerGeneratedBranches (IEnumera
if (sp.Offset <= startOffset || sp.Offset >= finalOffset) {
sp.BranchPoints = new List<BranchPoint>();
} else {
var trimmed = Regex.Replace(sourceRepository.GetSequencePointText(sp), @"\s", "");
if (trimmed.Length > 18 && trimmed[0] == 'C' && trimmed[8] == '.') {
if (trimmed.StartsWith ("Contract.Requires", StringComparison.Ordinal) ) {
var text = sourceRepository.GetSequencePointText(sp);
if (text[0] == 'C' && text.Length > 18) {
if (contractRegex.IsMatch(text)) {
sp.BranchPoints = new List<BranchPoint>();
}
else if (trimmed.StartsWith ("Contract.Ensures", StringComparison.Ordinal) ) {
sp.BranchPoints = new List<BranchPoint>();
}
} else if (trimmed == "in") {
} else if (text == "in") {
sp.BranchPoints = new List<BranchPoint>();
}
}
Expand Down