Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion error_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestErrorMessages(t *testing.T) {
"age": Int().GT(18).Required(),
"time": Time().Before(time.Now()).Required(),
"bool": Bool().True().Required(),
"slice": Slice(String()).Contains("foo").Required(),
"slice": Slice[string](String()).Contains("foo").Required(),
})

var u Msgs
Expand Down
6 changes: 3 additions & 3 deletions pointers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestPtrNestedStructs(t *testing.T) {
}

func TestPtrInSlice(t *testing.T) {
schema := Slice(Ptr(Int()))
schema := Slice[*int](Ptr(Int()))
var out []*int

data := []any{10, 20, 30}
Expand All @@ -154,7 +154,7 @@ func TestPtrSliceStruct(t *testing.T) {
Value int
}

schema := Slice(Ptr(Struct(Shape{
schema := Slice[string](Ptr(Struct(Shape{
"value": Int(),
})))
var out []*TestStruct
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestPtrToStruct(t *testing.T) {

func TestPtrToSlice(t *testing.T) {
var dest *[]*int
s := Ptr(Slice(Ptr(Int())))
s := Ptr(Slice[int](Ptr(Int())))
err := s.Parse([]any{10, 20, 30}, &dest)
assert.Nil(t, err)
assert.NotNil(t, dest)
Expand Down
6 changes: 3 additions & 3 deletions pointers_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestValidatePtrNestedStructs(t *testing.T) {
}

func TestValidatePtrInSlice(t *testing.T) {
schema := Slice(Ptr(Int()).NotNil())
schema := Slice[*int](Ptr(Int()).NotNil())
v1, v2, v3 := 10, 20, 30
var v4 *int
out := []*int{&v1, &v2, &v3, v4}
Expand All @@ -115,7 +115,7 @@ func TestValidatePtrSliceStruct(t *testing.T) {
Value int
}

schema := Slice(Ptr(Struct(Shape{
schema := Slice[*Shape](Ptr(Struct(Shape{
"value": Int(),
})))
out := []*TestStruct{
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestValidatePtrToStruct(t *testing.T) {
func TestValidatePtrToSlice(t *testing.T) {
v1, v2, v3 := 10, 20, 30
dest := &[]*int{&v1, &v2, &v3}
s := Ptr(Slice(Ptr(Int())))
s := Ptr(Slice[*int](Ptr(Int())))

errs := s.Validate(&dest)
assert.Empty(t, errs)
Expand Down
10 changes: 5 additions & 5 deletions preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestPreprocessTime(t *testing.T) {
func TestPreprocessSlice(t *testing.T) {
s := Preprocess(func(data string, ctx Ctx) (out []string, err error) {
return strings.Split(data, ","), nil
}, Slice(String().Min(1)))
}, Slice[string](String().Min(1)))

out := []string{}
errs := s.Parse("hello,world", &out)
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestPreprocessSliceOfStructs(t *testing.T) {
result[i] = User{Id: parts[0], Name: parts[1]}
}
return result, nil
}, Slice(Struct(Shape{
}, Slice[*Shape](Struct(Shape{
"Id": String().Min(1),
"Name": String().Min(1),
})))
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestPreprocessStructWithSlice(t *testing.T) {
}, nil
}, Struct(Shape{
"Id": String().Min(1),
"Names": Slice(String().Min(1)),
"Names": Slice[string](String().Min(1)),
}))

var out User
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestPreprocessPtrSlice(t *testing.T) {
s := Preprocess(func(data string, ctx Ctx) (out *[]string, err error) {
slice := strings.Split(data, ",")
return &slice, nil
}, Ptr(Slice(String().Min(1))))
}, Ptr(Slice[string](String().Min(1))))

var out *[]string
errs := s.Parse("a,b,c", &out)
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestPreprocessPartOfStruct(t *testing.T) {

func TestPreprocessInSlice(t *testing.T) {

s := Slice(
s := Slice[string](
Preprocess(func(data string, ctx Ctx) (out int, err error) {
return strconv.Atoi(data)
}, Int().GT(0)),
Expand Down
8 changes: 4 additions & 4 deletions preprocess_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestPreprocessTimeValidate(t *testing.T) {
func TestPreprocessSliceValidate(t *testing.T) {
s := Preprocess(func(data *[]string, ctx Ctx) (out []string, err error) {
return append(*data, "!"), nil
}, Slice(String().Min(1)))
}, Slice[string](String().Min(1)))

slice := []string{"hello", "world"}
errs := s.Validate(&slice)
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestPreprocessSliceOfStructsValidate(t *testing.T) {
result[i] = User{Id: u.Id + "!", Name: u.Name + "!"}
}
return result, nil
}, Slice(Struct(Shape{
}, Slice[*Shape](Struct(Shape{
"Id": String().Min(1),
"Name": String().Min(1),
})))
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestPreprocessStructWithSliceValidate(t *testing.T) {
}, nil
}, Struct(Shape{
"Id": String().Min(1),
"Names": Slice(String().Min(1)),
"Names": Slice[string](String().Min(1)),
}))

user := User{
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestPreprocessPtrSliceValidate(t *testing.T) {
s[i] = str + "!"
}
return &s, nil
}, Ptr(Slice(String().Min(1))))
}, Ptr(Slice[string](String().Min(1))))

slice := []string{"a", "b", "c"}
pslice := &slice
Expand Down
Loading
Loading