Commit c973d55
Port NIM regex tests to improve test coverage (#120846)
Fixes #61895
This PR ports regex functional tests from the
[nim-regex](https://github.com/nitely/nim-regex) project to increase
.NET's regex test coverage, following the same pattern used for PCRE and
Rust test suites.
## Changes
- Added `RegexNimTests.cs` with 156 unique test cases focusing on
patterns not already covered by existing tests
- Updated `System.Text.RegularExpressions.Tests.csproj` to include the
new test file
- All tests pass across all regex engines (Interpreter, Compiled,
NonBacktracking, SourceGenerated)
## Test Coverage
The ported tests provide additional coverage for unique patterns
including:
- **Escaped quantifiers**: `\*+`, `\??`, `\++?` - testing literal `*`,
`+`, `?` characters with quantifiers
- **Nested repetitions**: `(a*)*`, `(a*)*b`, `((a)*(a)*)*` - edge case
patterns
- **Complex patterns**: `a(b|c)*d`, `((a(b)*)*(b)*)`, alternations with
grouping
- **Unicode character classes**: `\d` matching `۲`, `\D` matching `⅕`
- **Lookahead/lookbehind**: Positive/negative assertions (filtered for
NonBacktracking engine)
- **Named groups**: `(?<name>...)` syntax
- **Word boundary edge cases**: `\b\b\b` patterns
- **Empty patterns and special cases**
## Deduplication
After analysis, 25 duplicate and trivial test cases were removed that
were already covered by existing tests in `Regex.Match.Tests.cs`,
`Regex.Groups.Tests.cs`, and other test files. The remaining tests focus
on unique patterns and edge cases.
## Compatibility Notes
Some NIM-specific patterns were excluded or adapted for .NET
compatibility:
- **Removed** `\y` escape sequence (not recognized in .NET)
- **Removed** `(?U)` ungreedy flag (not supported in .NET)
- **Removed** Unicode case folding tests (ß ↔ ss) due to different
behavior
- **Converted** named group syntax from `(?P<name>)` to .NET's
`(?<name>)` format
- **Filtered** lookahead/lookbehind tests for NonBacktracking engine
(throws NotSupportedException)
## Test Results
- Total tests: 29,899 (added ~600+ test executions across all engines)
- Failures: 0
- All tests pass successfully
The MIT license for nim-regex was already present in
`THIRD-PARTY-NOTICES.TXT`.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Port nim regex tests</issue_title>
> <issue_description>Nim has lots of regex functional tests we should
port over to improve our coverage:
>
https://github.com/nitely/nim-regex/blob/eeefb4f51264ff3bc3b36caf55672a74f52f5ef5/tests/tests.nim</issue_description>
>
> <agent_instructions>You can see in
https://github.com/dotnet/runtime/tree/main/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests
we have a file of tests ported from PCRE and a file of tests ported from
Rust. Please similarly port the cited NIM tests (or a newer version if
there is one); any that don't pass but should need to be marked as
[ActiveIssue(...)]... any that don't pass but that's expected should be
removed.</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@</author><body>
> Tagging subscribers to this area: @eerhardt,
@dotnet/area-system-text-regularexpressions
> See info in
[area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md)
if you want to be subscribed.
> <details>
> <summary>Issue Details</summary>
> <hr />
>
> Nim has lots of regex functional tests we should port over to improve
our coverage:
>
https://github.com/nitely/nim-regex/blob/eeefb4f51264ff3bc3b36caf55672a74f52f5ef5/tests/tests.nim
>
> <table>
> <tr>
> <th align="left">Author:</th>
> <td>stephentoub</td>
> </tr>
> <tr>
> <th align="left">Assignees:</th>
> <td>-</td>
> </tr>
> <tr>
> <th align="left">Labels:</th>
> <td>
>
> `area-System.Text.RegularExpressions`
>
> </td>
> </tr>
> <tr>
> <th align="left">Milestone:</th>
> <td>.NET 7.0</td>
> </tr>
> </table>
> </details></body></comment_new>
> <comment_new><author>@joperezr</author><body>
> This will likely miss ZBB but will still make it before 7.0. Adjusting
the milestone just because this is not technically a blocker for
7.0.</body></comment_new>
> </comments>
>
</details>
Fixes #61895
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/runtime/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: stephentoub <[email protected]>1 parent de8005b commit c973d55
File tree
2 files changed
+203
-0
lines changed- src/libraries/System.Text.RegularExpressions/tests/FunctionalTests
2 files changed
+203
-0
lines changedLines changed: 202 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
0 commit comments