File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,6 +50,47 @@ func TestValidateUnionAllSchemasFail(t *testing.T) {
5050 assert .Equal (t , 5 , dest )
5151}
5252
53+ func TestValidateUnionDefaultBranchSucceeds (t * testing.T ) {
54+ validator := Union ([]ZogSchema {
55+ String ().Required (),
56+ Int ().Default (42 ),
57+ })
58+ dest := 0
59+
60+ errs := validator .Validate (& dest )
61+
62+ assert .Empty (t , errs )
63+ assert .Equal (t , 42 , dest )
64+ }
65+
66+ func TestValidateUnionCatchBranchSucceeds (t * testing.T ) {
67+ validator := Union ([]ZogSchema {
68+ String ().Required (),
69+ Int ().GT (10 , Message ("must be greater than 10" )).Catch (42 ),
70+ })
71+ dest := 5
72+
73+ errs := validator .Validate (& dest )
74+
75+ assert .Empty (t , errs )
76+ assert .Equal (t , 42 , dest )
77+ }
78+
79+ func TestValidateUnionInvalidDestinationTypeAllSchemasFail (t * testing.T ) {
80+ validator := Union ([]ZogSchema {
81+ String ().Required (),
82+ Int ().Required (),
83+ })
84+ dest := true
85+
86+ errs := validator .Validate (& dest )
87+
88+ assert .Len (t , errs , 2 )
89+ assert .Equal (t , zconst .IssueCodeInvalidType , errs [0 ].Code )
90+ assert .Equal (t , zconst .IssueCodeInvalidType , errs [1 ].Code )
91+ assert .True (t , dest )
92+ }
93+
5394func TestValidateUnionStringOrInt (t * testing.T ) {
5495 validator := Union ([]ZogSchema {
5596 String ().Required (),
You can’t perform that action at this time.
0 commit comments