feat(assertion): Add RegularExpressionValueComparer - #974
Conversation
Reviewer's GuideAdds a reusable regular-expression ValueComparer that converts dataset values to strings, requires whole-value matches by default, preserves sibling null semantics, reports invalid patterns with row and column context, and is exposed, documented, and covered by unit and end-to-end tests. Sequence diagram for regular expression value comparisonsequenceDiagram
participant AssertPipeline
participant RegularExpressionValueComparer
participant DataType
participant Pattern
participant Matcher
AssertPipeline->>RegularExpressionValueComparer: isExpected(expectedTable, actualTable, rowNum, columnName, dataType, expectedValue, actualValue)
alt both values null
RegularExpressionValueComparer-->>AssertPipeline: true
else exactly one value null
RegularExpressionValueComparer-->>AssertPipeline: false
else non-null values
RegularExpressionValueComparer->>DataType: asString(expectedValue)
DataType-->>RegularExpressionValueComparer: regex
RegularExpressionValueComparer->>DataType: asString(actualValue)
DataType-->>RegularExpressionValueComparer: actualValueString
RegularExpressionValueComparer->>Pattern: compile(regex)
Pattern-->>RegularExpressionValueComparer: pattern
RegularExpressionValueComparer->>Matcher: matches()
Matcher-->>RegularExpressionValueComparer: whole-value result
RegularExpressionValueComparer-->>AssertPipeline: true or false
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reachedNext included review available in 39 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughAdds ChangesRegular expression value comparison
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This adds an opt-in regular-expression dataset comparer with documented whole-value matching behavior and clear invalid-pattern errors. Matching and failure paths are covered, and no merge-blocking product risk is evident. Sequence Diagram(s)sequenceDiagram
participant TestOrCaller
participant ValueComparers
participant RegularExpressionValueComparer
participant DataType
participant Pattern
TestOrCaller->>ValueComparers: select regularExpressionValueComparer
TestOrCaller->>RegularExpressionValueComparer: compare expected pattern and actual value
RegularExpressionValueComparer->>DataType: convert values to strings
RegularExpressionValueComparer->>Pattern: compile and match expected pattern
Pattern-->>RegularExpressionValueComparer: match result
RegularExpressionValueComparer-->>TestOrCaller: comparison result or DatabaseUnitException
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 4.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 41 functions across 4 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main/java/org/dbunit/assertion/comparer/value/RegularExpressionValueComparer.java" line_range="105-106" />
<code_context>
+ final String regex = DataType.asString(expectedValue);
+ final String actualValueString = DataType.asString(actualValue);
+ final Pattern pattern = compilePattern(rowNum, columnName, regex);
+ final Matcher matcher = pattern.matcher(actualValueString);
+ final boolean isMatching = matcher.matches();
+ log.debug("isMatching: regex={}, actualValueString={}, isMatching={}",
+ regex, actualValueString, isMatching);
</code_context>
<issue_to_address>
**issue (bug_risk):** Wrapping a pattern in `.*` does not provide a general partial match when the actual value contains a line terminator, because Java regex `.` excludes line terminators unless DOTALL is enabled; a pattern such as `.*foo.*` therefore fails for an actual value containing `foo` across or adjacent to a newline despite the documentation promising that this form matches part of the value.
**Triggers:** When the actual database value contains a newline or another line terminator and callers use the documented `.*pattern.*` form.
**Suggested fix:** Document the line-terminator limitation and suggest `(?s:.*pattern.*)`, or enable DOTALL for the wrapper semantics if universal partial matching is intended.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: src/main/java/org/dbunit/assertion/comparer/value/RegularExpressionValueComparer.java:106
Add a ValueComparer that reads the expected dataset value as a regular expression and passes when it matches the actual value in its entirety (Matcher.matches(), the same whole-value rule as String.matches()), for verifying columns whose format a test controls but whose exact content it does not - database-generated ids, UUID columns, or timestamps rendered into a text column. Wrapping the pattern in .* opts into a partial match. Null handling mirrors the sibling comparers: both null match, exactly one null does not. An invalid pattern raises DatabaseUnitException naming the row and column, consistent with IsActualEqualToExpectedJsonValueComparer. The comparer adds no dependency beyond java.util.regex, so it is also exposed as the ValueComparers.regularExpressionValueComparer constant. * Cover the comparer with RegularExpressionValueComparerTest: null handling, whole-value versus substring and prefix matches, character classes and quantifiers, alternation, escaped metacharacters, inline flags, case sensitivity, empty and zero-width patterns, non-string actual values, invalid-pattern reporting, and the compare() fail-message path. * Exercise it end to end through the assert pipeline in DbUnitValueComparerAssertIT. * Document it in valuecomparer.adoc. Refs: 973 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LaCA8dcNX7whN1143ZZwYJ
54dba96 to
430ec86
Compare
Add a ValueComparer that reads the expected dataset value as a regular expression and passes when it matches the actual value in its entirety (Matcher.matches(), the same whole-value rule as String.matches()), for verifying columns whose format a test controls but whose exact content it does not - database-generated ids, UUID columns, or timestamps rendered into a text column. Wrapping the pattern in .* opts into a partial match.
Null handling mirrors the sibling comparers: both null match, exactly one null does not. An invalid pattern raises DatabaseUnitException naming the row and column, consistent with IsActualEqualToExpectedJsonValueComparer.
The comparer adds no dependency beyond java.util.regex, so it is also exposed as the ValueComparers.regularExpressionValueComparer constant.
Refs: 973
Claude-Session: https://claude.ai/code/session_01LaCA8dcNX7whN1143ZZwYJ
Summary by Sourcery
Add regular-expression value comparison for validating controlled data formats without requiring exact generated values.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests:
Summary by CodeRabbit
New Features
.*for partial matches.Documentation