Skip to content
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

Add String Variant Validator #50

Merged
merged 3 commits into from
Jun 30, 2023
Merged

Add String Variant Validator #50

merged 3 commits into from
Jun 30, 2023

Conversation

josestg
Copy link
Member

@josestg josestg commented Jun 30, 2023

This feature basically provides a simple StringValidator for string variants (~string). In the current latest version, if we need a validator for the type VariantExample string, which is a string variant, we have to convert VariantExample to a string in order to use the StringValidator. These changes add a new API that reuses the StringValidator rules for string variants without any conversion.

Before:

type Variant string

const (
   VariantA Variant = "A"
   VariantB Variant = "B"
)

var validator = goval.String().In(string(VariantA), string(VariantB))

After:

type Variant string

const (
   VariantA Variant = "A"
   VariantB Variant = "B"
)

var validator = goval.StringVariant[Variant]().In(VariantA, VariantB)

#49)

* feat(string): impl variant validator and ensure backward compatibility

* refactor(string): use sort name
@josestg josestg self-assigned this Jun 30, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jun 30, 2023

Codecov Report

Merging #50 (7edf4e5) into main (db76598) will decrease coverage by 0.27%.
The diff coverage is 93.54%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main      #50      +/-   ##
==========================================
- Coverage   92.07%   91.81%   -0.27%     
==========================================
  Files          13       13              
  Lines         454      464      +10     
==========================================
+ Hits          418      426       +8     
- Misses         27       29       +2     
  Partials        9        9              
Impacted Files Coverage Δ
errors.go 81.63% <60.00%> (-2.46%) ⬇️
goval.go 97.70% <100.00%> (+0.08%) ⬆️
string.go 100.00% <100.00%> (ø)

@josestg josestg merged commit 84da936 into main Jun 30, 2023
@dimasadyaksa
Copy link
Member

Hi @josestg , do we need to implement NumberVariant also ?

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.

3 participants