Skip to content

Conversation

@alexgarzao
Copy link
Collaborator

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:

  • Added support for new validation operations between fields: eqfield, neqfield, gtefield, gtfield, ltefield, ltfield, including their parsing, validation, and enforcement of type compatibility. [1] [2] [3]
  • Updated the code generator to handle these new operations and produce appropriate error messages and validation logic. [1] [2]

Testing enhancements:

  • Added comprehensive analyzer and code generator tests to cover valid and invalid cross-field operations, ensuring type checks and correct error reporting. [1] [2]

Documentation updates:

  • Updated README.md to document the new cross-field validation operations, their supported types, and usage examples. [1] [2] [3] [4]

These changes collectively make validgen more powerful and expressive by enabling validation rules that compare values between fields within a struct.

@alexgarzao alexgarzao self-assigned this Aug 28, 2025
@alexgarzao alexgarzao requested a review from Copilot August 28, 2025 23:52

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot August 29, 2025 01:49

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot August 29, 2025 14:43

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot August 29, 2025 17:32
Copy link
Contributor

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

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

Comment on lines +126 to +175
"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,
},
},
Copy link

Copilot AI Aug 29, 2025

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.

Copilot uses AI. Check for mistakes.
@alexgarzao alexgarzao merged commit 481ac65 into main Aug 29, 2025
4 checks passed
@alexgarzao alexgarzao deleted the 55-operations-fields-same-struct branch August 29, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deal with operations between fields in the same struct

6 participants