-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Port RE2 regex tests to improve test coverage #120845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
There was a problem hiding this 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 a subset of RE2's functional regex tests into the .NET test suite to expand coverage across multiple regex engines.
- Adds 142 test cases derived from RE2's re2_test.cc and search_test.cc.
- Updates test project file to include the new test file and adds RE2's BSD 3-Clause license to third-party notices.
- Exercises diverse regex features (anchors, word boundaries, quantifiers, escapes, Unicode) across all available engines.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
THIRD-PARTY-NOTICES.TXT | Adds RE2 BSD 3-Clause license attribution for the ported tests. |
System.Text.RegularExpressions.Tests.csproj | Includes the new RegexRe2Tests.cs file in the test compilation. |
RegexRe2Tests.cs | Introduces the ported RE2-derived test cases and supporting data generation logic. |
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexRe2Tests.cs
Show resolved
Hide resolved
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexRe2Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexRe2Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexRe2Tests.cs
Show resolved
Hide resolved
Removed 57 test cases that were already covered by existing tests in PCRE, Rust, or core regex tests: - Basic patterns like "a", "a*", "a+", "a?" with simple inputs - Simple anchor tests "^$", "^", "$" that duplicate existing coverage - Trivial quantifier tests already well-tested elsewhere - Basic UTF-8 tests with single character patterns Retained 85 unique test cases that add value: - Complex patterns and edge cases - Word boundary tests with various scenarios - Multiline mode tests - Case-insensitive matching - Octal/hexadecimal escapes - Non-trivial quantifier combinations Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions |
This PR ports functional regex tests from the RE2 test suite to improve .NET's regex test coverage, as requested in #120756.
Changes
Test Suite Additions
RegexRe2Tests.cs
: New test file containing 85 unique test cases ported from RE2'sre2_test.cc
andsearch_test.cc
Test Categories Covered
The ported tests validate:
^
,$
) in single-line and multiline modes with non-trivial cases\b
,\B
) with ASCII and special characters\141
, hexadecimal\x61
, unicode\u0061
)(?i)
){n}
,{n,}
,{n,m}
)Compatibility Adjustments
Several RE2-specific patterns were excluded or adapted for .NET compatibility:
\C
patterns: RE2's byte-matching construct is not supported in .NET\Q...\E
patterns: Quote meta syntax is not supported in .NET\x{...}
escapes: Changed to .NET-compatible\x
(2 digits) or\u
(4 digits) formatRegexHelpers.IsNonBacktracking()
checkLicense Attribution
THIRD-PARTY-NOTICES.TXT
: Added RE2 BSD 3-Clause license to properly attribute the ported tests.csproj
: AddedRegexRe2Tests.cs
to the compilationTesting
All 29,621 tests pass successfully, including the newly ported RE2 tests across all regex engines.
Fixes #120756
Original prompt
Fixes #61896
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.