Skip to content

Commit

Permalink
Make values parameter in OneOf to be variadic (#12)
Browse files Browse the repository at this point in the history
This PR alters the signature of `validate.OneOf` function so that its
second parameter, `values`, becomes a variadic parameter instead of a
flat slice type.

This aims to improve the experience of restraining values.
  • Loading branch information
jvcoutinho committed Feb 27, 2024
1 parent 0889409 commit 1b71356
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion validate/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NotEqualField[T comparable](target *T, field *T) Field {
}

// OneOf validates if target is one of values.
func OneOf[T comparable](target *T, values []T) Field {
func OneOf[T comparable](target *T, values ...T) Field {
return Field{
Valid: target != nil && slices.Contains(values, *target),
Message: fmt.Sprintf("{0} should be one of %v", values),
Expand Down
2 changes: 1 addition & 1 deletion validate/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestOneOf(t *testing.T) {
t.Parallel()

// Act
result := validate.OneOf(test.target, test.values)
result := validate.OneOf(test.target, test.values...)

// Assert
expectedResult := validate.Field{
Expand Down

0 comments on commit 1b71356

Please sign in to comment.