Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 17, 2025

Fixes #61895

This PR ports regex functional tests from the 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.

Original prompt

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)

@ 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.
Issue Details

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

Author: stephentoub
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: .NET 7.0
@joperezr 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.

Fixes #61895


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits October 17, 2025 13:50
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Port Nim regex functional tests for coverage Port NIM regex tests to improve test coverage Oct 17, 2025
Copilot finished work on behalf of stephentoub October 17, 2025 14:19
@Copilot Copilot AI requested a review from stephentoub October 17, 2025 14:19
@stephentoub stephentoub marked this pull request as ready for review October 17, 2025 14:22
@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 14:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Ports Nim regex functional tests to expand .NET regex engine coverage and align with existing PCRE and Rust imported suites.

  • Adds 181 Nim-derived test cases in a new RegexNimTests.cs file.
  • Updates the test project file to include the new test source.
  • Tests exercise multiple engines; lookaround tests are conditionally included.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
System.Text.RegularExpressions.Tests.csproj Adds RegexNimTests.cs to build for inclusion of new test cases.
RegexNimTests.cs Introduces Nim-sourced regex functional tests across patterns, quantifiers, character classes, anchors, options, and lookarounds.

Copilot AI and others added 2 commits October 17, 2025 14:49
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@Copilot Copilot AI requested a review from stephentoub October 17, 2025 14:51
Copilot finished work on behalf of stephentoub October 17, 2025 14:51
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port nim regex tests

3 participants