Skip to content

18 feat not in string validation#27

Merged
alexgarzao merged 9 commits intomainfrom
18-feat-not-in-string-validation
Jul 18, 2025
Merged

18 feat not in string validation#27
alexgarzao merged 9 commits intomainfrom
18-feat-not-in-string-validation

Conversation

@alexgarzao
Copy link
Copy Markdown
Collaborator

Closes #18

This PR introduces support for the "nin" (not in) validation rule, which ensures that a field's value is not among a specified set of values. The changes include updates to validation logic, test cases, and documentation to accommodate this new feature.

Feature Addition: "nin" Validation Rule

  • Updated the README.md to document the "nin" validation rule, specifying its supported types and usage. ([README.mdL67-R67](https://github.com/opencodeco/validgen/pull/27/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L67-R67))
  • Added the nin validation rule to the ParserValidation function in validgen/parser_validation.go, allowing it to parse "nin" rules. ([validgen/parser_validation.goR37](https://github.com/opencodeco/validgen/pull/27/files#diff-624caa67bdb0ba682f775f0fa90bbfa9ff8df232412316dd08381274997123b6R37))
  • Introduced the NotInOp constant in validgen/test_elements.go and updated the GetTestElements function to handle "nin" validations, including setting the appropriate concatenation operator (&&). ([[1]](https://github.com/opencodeco/validgen/pull/27/files#diff-d28674cf641191cff72b6b261ebd77c638dca5b9477702dd1475d7e6f77468cbL11-R21), [[2]](https://github.com/opencodeco/validgen/pull/27/files#diff-d28674cf641191cff72b6b261ebd77c638dca5b9477702dd1475d7e6f77468cbR47), [[3]](https://github.com/opencodeco/validgen/pull/27/files#diff-d28674cf641191cff72b6b261ebd77c638dca5b9477702dd1475d7e6f77468cbL56-R60), [[4]](https://github.com/opencodeco/validgen/pull/27/files#diff-d28674cf641191cff72b6b261ebd77c638dca5b9477702dd1475d7e6f77468cbR83-R92), [[5]](https://github.com/opencodeco/validgen/pull/27/files#diff-d28674cf641191cff72b6b261ebd77c638dca5b9477702dd1475d7e6f77468cbR102))

Test Enhancements

  • Added test cases in tests/endtoend/string.go to validate the behavior of the "nin" rule, including scenarios where the validation passes and fails. ([[1]](https://github.com/opencodeco/validgen/pull/27/files#diff-4f0802d7c2e573b0e4aaa631328677086e14b794beeb22c7fa1219a7bb92c4cbR14), [[2]](https://github.com/opencodeco/validgen/pull/27/files#diff-4f0802d7c2e573b0e4aaa631328677086e14b794beeb22c7fa1219a7bb92c4cbR29), [[3]](https://github.com/opencodeco/validgen/pull/27/files#diff-4f0802d7c2e573b0e4aaa631328677086e14b794beeb22c7fa1219a7bb92c4cbR40), [[4]](https://github.com/opencodeco/validgen/pull/27/files#diff-4f0802d7c2e573b0e4aaa631328677086e14b794beeb22c7fa1219a7bb92c4cbR56))
  • Updated the TestGetTestElementsWithStringFields function in validgen/get_test_elements_string_test.go to include a test case for "nin" validation with string fields. ([[1]](https://github.com/opencodeco/validgen/pull/27/files#diff-3b9d1a12858980987436bb3f555f8f3861f65a83e810b28aaffda521dc11c071R132), [[2]](https://github.com/opencodeco/validgen/pull/27/files#diff-3b9d1a12858980987436bb3f555f8f3861f65a83e810b28aaffda521dc11c071R146-R163))
  • Added a test case for the IfCode function in validgen/if_code_test.go to verify the generated code for "nin" validations. ([validgen/if_code_test.goR54-R66](https://github.com/opencodeco/validgen/pull/27/files#diff-871326416a200a07b2b5ef890daed108971c94f739c84d93d27975fda2643ee4R54-R66))

Validation Logic Updates

  • Modified the StringTypeValidate function in tests/endtoend/stringtype_validator.go to include validation logic for the "nin" rule, ensuring that the value is not in the specified set. ([tests/endtoend/stringtype_validator.goR48-R51](https://github.com/opencodeco/validgen/pull/27/files#diff-1d142222f7677210e08405f7a33515144de5511e39890fe4a562583328b24724R48-R51))
  • Adjusted the IfCode function in validgen/if_code.go to use the appropriate concatenation operator (&& for "nin"). ([validgen/if_code.goL31-R31](https://github.com/opencodeco/validgen/pull/27/files#diff-2f7f06c49877e879996207790c5bd1f998c9511e51b9ab2cecf77ade0a445f24L31-R31))

@alexgarzao alexgarzao self-assigned this Jul 18, 2025
@alexgarzao alexgarzao requested a review from Copilot July 18, 2025 00:59

This comment was marked as outdated.

Copy link
Copy Markdown
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 introduces support for the "nin" (not in) validation rule to ValidGen, which ensures that a field's value is not among a specified set of values. This complements the existing "in" validation rule by providing the inverse functionality.

  • Adds "nin" validation rule support with proper parsing, code generation, and error handling
  • Updates validation logic to use appropriate concatenation operators ("&&" for "nin", "||" for "in")
  • Includes comprehensive test coverage for the new validation rule

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
README.md Updates documentation to mark "nin" validation as implemented for string types
validgen/parser_validation.go Adds "nin" to the list of supported validations that accept multiple values
validgen/test_elements.go Introduces NotInOp constant, adds "nin" mapping, and implements concatenation operator logic
validgen/if_code.go Updates condition generation to use dynamic concatenation operators
validgen/if_code_test.go Adds test case for "nin" validation code generation
validgen/get_test_elements_string_test.go Updates existing tests and adds new test for "nin" validation
tests/endtoend/string.go Adds test struct field and validation scenarios for "nin" rule
tests/endtoend/stringtype_validator.go Contains generated validation code for the new "nin" field
Comments suppressed due to low confidence (1)

validgen/test_elements.go:28

  • The validation logic for missing concat operator should be moved to the GetTestElements function where the concatOperator is set, rather than in IfCode. This would provide earlier error detection and better separation of concerns.
		loperand     string

@alexgarzao alexgarzao merged commit 4cc459c into main Jul 18, 2025
1 check passed
@alexgarzao alexgarzao deleted the 18-feat-not-in-string-validation branch July 18, 2025 22:13
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.

Feat: String validations

6 participants