Skip to content

Commit dc803e0

Browse files
CopilotdanmoseleyCopilot
authored
Add missing tests for resumeAt=2 path in regex expression conditional (#126657)
## Description The Code Review workflow on PR #126561 identified that the new tests cover `resumeAt=0` (yes-branch) and `resumeAt=1` (no-branch) paths but miss the `resumeAt=2` pass-through path — expression conditional with only a yes-branch (no no-branch) inside a loop. Adds 3 test cases to `Regex.MultipleMatches.Tests.cs`: - **Yes-only conditional, condition always fails** — `(?((?'-1'))(?'1'.)+)+(?!(?'-1'))` with `"abc"` exercises the pass-through path producing empty matches at each position (guarded with `#if !NETFRAMEWORK` since .NET Framework produces 3 empty matches vs 4 on .NET Core due to different empty-match-at-end-of-string semantics) - **Yes-only conditional with prefix capture, even input** — `((?'1'.)(?((?'-1'))(?'1'.)))+` with `"abcd"` exercises the yes-branch-taken path inside a loop - **Yes-only conditional with prefix capture, odd input** — same pattern with `"abc"` verifying partial match behavior The latter two test cases are the primary coverage for the `|| isInLoop` fix, since their non-backtracking yes-branch means `isInLoop` is the necessary trigger for `resumeAt = 2` (the old condition `postYesDoneLabel != originalDoneLabel` would have been false). These run on both .NET Core and .NET Framework. All 32,100 existing tests continue to pass. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com> Co-authored-by: Dan Moseley <danmose@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 62b476b commit dc803e0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.MultipleMatches.Tests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,22 @@ public static IEnumerable<object[]> Matches_TestData()
582582
new CaptureData("d", 10, 1),
583583
}
584584
};
585+
586+
// Yes-only expression conditional with prefix capture feeding the condition, inside a loop
587+
yield return new object[]
588+
{
589+
engine, @"((?'1'.)(?((?'-1'))(?'1'.)))+", "abcd", RegexOptions.None, new[]
590+
{
591+
new CaptureData("abcd", 0, 4),
592+
}
593+
};
594+
yield return new object[]
595+
{
596+
engine, @"((?'1'.)(?((?'-1'))(?'1'.)))+", "abc", RegexOptions.None, new[]
597+
{
598+
new CaptureData("ab", 0, 2),
599+
}
600+
};
585601
}
586602

587603
#if !NETFRAMEWORK // these tests currently fail on .NET Framework
@@ -611,6 +627,18 @@ public static IEnumerable<object[]> Matches_TestData()
611627
new CaptureData("anyexpress1", 10, 11),
612628
}
613629
};
630+
631+
// ExpressionConditional with only a yes-branch (no no-branch) inside a loop (empty matches differ on .NET Framework: https://github.com/dotnet/runtime/issues/24894)
632+
yield return new object[]
633+
{
634+
engine, @"(?((?'-1'))(?'1'.)+)+(?!(?'-1'))", "abc", RegexOptions.None, new[]
635+
{
636+
new CaptureData("", 0, 0),
637+
new CaptureData("", 1, 0),
638+
new CaptureData("", 2, 0),
639+
new CaptureData("", 3, 0),
640+
}
641+
};
614642
}
615643

616644
// Fails on .NET Framework: https://github.com/dotnet/runtime/issues/62094

0 commit comments

Comments
 (0)