-
Notifications
You must be signed in to change notification settings - Fork 2
55 operations fields same struct #66
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
Conversation
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
This PR implements cross-field validation support for ValidGen, enabling field-to-field comparisons within structs. It adds six new validation operations (eqfield, neqfield, gtefield, gtfield, ltefield, ltfield) that allow validating one field against another field's value, with proper type checking and error handling.
Key changes include:
- Added support for cross-field validation operations with type compatibility checks
- Implemented comprehensive analyzer validation to ensure field operations reference existing fields and have matching types
- Extended code generation to handle field-to-field comparisons with appropriate error messages
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
internal/analyzer/operations.go |
New file defining all validation operations with metadata including field operation flags and valid types |
internal/analyzer/analyzer.go |
Added field operation analysis to validate cross-field references and type compatibility |
internal/analyzer/parser_validation.go |
Refactored to use centralized operations configuration |
internal/codegenerator/test_elements.go |
Added condition mappings for new cross-field validation operations |
tests/endtoend/ |
Added comprehensive end-to-end tests for cross-field validations |
internal/codegenerator/get_test_elements_between_fields_test.go |
Unit tests for cross-field test element generation |
internal/codegenerator/build_func_validator_test.go |
Updated validator function generation tests |
internal/analyzer/analyzer_test.go |
New comprehensive analyzer tests for field operations |
README.md |
Updated documentation with new validation operations and examples |
| "eqfield": { | ||
| Name: "eqfield", | ||
| CountValues: ONE_VALUE, | ||
| IsFieldOperation: true, | ||
| ValidTypes: map[string]bool{ | ||
| "string": true, | ||
| "uint8": true, | ||
| }, | ||
| }, | ||
| "neqfield": { | ||
| Name: "neqfield", | ||
| CountValues: ONE_VALUE, | ||
| IsFieldOperation: true, | ||
| ValidTypes: map[string]bool{ | ||
| "string": true, | ||
| "uint8": true, | ||
| }, | ||
| }, | ||
| "gtefield": { | ||
| Name: "gtefield", | ||
| CountValues: ONE_VALUE, | ||
| IsFieldOperation: true, | ||
| ValidTypes: map[string]bool{ | ||
| "uint8": true, | ||
| }, | ||
| }, | ||
| "gtfield": { | ||
| Name: "gtfield", | ||
| CountValues: ONE_VALUE, | ||
| IsFieldOperation: true, | ||
| ValidTypes: map[string]bool{ | ||
| "uint8": true, | ||
| }, | ||
| }, | ||
| "ltefield": { | ||
| Name: "ltefield", | ||
| CountValues: ONE_VALUE, | ||
| IsFieldOperation: true, | ||
| ValidTypes: map[string]bool{ | ||
| "uint8": true, | ||
| }, | ||
| }, | ||
| "ltfield": { | ||
| Name: "ltfield", | ||
| CountValues: ONE_VALUE, | ||
| IsFieldOperation: true, | ||
| ValidTypes: map[string]bool{ | ||
| "uint8": true, | ||
| }, | ||
| }, |
Copilot
AI
Aug 29, 2025
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.
[nitpick] The operation definitions contain significant duplication. Consider extracting common patterns into helper functions or using a more structured approach to reduce redundancy and improve maintainability.
Closes #55
This PR adds support for cross-field validations (field-to-field comparisons), allowing validations such as "field must be equal to another field" or "field must be greater than another field". It introduces new validation keywords (
eqfield,neqfield,gtefield,gtfield,ltefield,ltfield), updates the analyzer to check correctness of these operations, and extends the code generator and documentation accordingly. Comprehensive unit tests for these features are also included.Cross-field validation support:
eqfield,neqfield,gtefield,gtfield,ltefield,ltfield, including their parsing, validation, and enforcement of type compatibility. [1] [2] [3]Testing enhancements:
Documentation updates:
README.mdto document the new cross-field validation operations, their supported types, and usage examples. [1] [2] [3] [4]These changes collectively make
validgenmore powerful and expressive by enabling validation rules that compare values between fields within a struct.