@@ -5883,6 +5883,133 @@ func TestOneOfCIValidation(t *testing.T) {
58835883 Equal (t , panicCount , len (panicSpecs ))
58845884}
58855885
5886+ func TestNoneOfValidation (t * testing.T ) {
5887+ validate := New ()
5888+
5889+ passSpecs := []struct {
5890+ f any
5891+ t string
5892+ }{
5893+ {f : "" , t : "noneof=red green" },
5894+ {f : "yellow" , t : "noneof=red green" },
5895+ {f : "green" , t : "noneof='red green' blue" },
5896+ {f : 5 , t : "noneof=red green" },
5897+ {f : 6 , t : "noneof=red green" },
5898+ {f : 6 , t : "noneof=7" },
5899+ {f : int8 (5 ), t : "noneof=red green" },
5900+ {f : int16 (5 ), t : "noneof=red green" },
5901+ {f : int32 (5 ), t : "noneof=red green" },
5902+ {f : int64 (5 ), t : "noneof=red green" },
5903+ {f : uint (6 ), t : "noneof=7" },
5904+ {f : uint8 (6 ), t : "noneof=7" },
5905+ {f : uint16 (6 ), t : "noneof=7" },
5906+ {f : uint32 (6 ), t : "noneof=7" },
5907+ {f : uint64 (6 ), t : "noneof=7" },
5908+ }
5909+ for _ , spec := range passSpecs {
5910+ t .Logf ("%#v" , spec )
5911+ errs := validate .Var (spec .f , spec .t )
5912+ Equal (t , errs , nil )
5913+ }
5914+
5915+ failSpecs := []struct {
5916+ f any
5917+ t string
5918+ }{
5919+ {f : "red" , t : "noneof=red green" },
5920+ {f : "green" , t : "noneof=red green" },
5921+ {f : "red green" , t : "noneof='red green' blue'" },
5922+ {f : "blue" , t : "noneof='red green' blue'" },
5923+ {f : 5 , t : "noneof=5 6" },
5924+ {f : 6 , t : "noneof=5 6" },
5925+ {f : int8 (6 ), t : "noneof=5 6" },
5926+ {f : int16 (6 ), t : "noneof=5 6" },
5927+ {f : int32 (6 ), t : "noneof=5 6" },
5928+ {f : int64 (6 ), t : "noneof=5 6" },
5929+ {f : uint (6 ), t : "noneof=5 6" },
5930+ {f : uint8 (6 ), t : "noneof=5 6" },
5931+ {f : uint16 (6 ), t : "noneof=5 6" },
5932+ {f : uint32 (6 ), t : "noneof=5 6" },
5933+ {f : uint64 (6 ), t : "noneof=5 6" },
5934+ }
5935+ for _ , spec := range failSpecs {
5936+ t .Logf ("%#v" , spec )
5937+ errs := validate .Var (spec .f , spec .t )
5938+ AssertError (t , errs , "" , "" , "" , "" , "noneof" )
5939+ }
5940+
5941+ PanicMatches (t , func () {
5942+ _ = validate .Var (3.14 , "noneof=red green" )
5943+ }, "Bad field type float64" )
5944+ }
5945+
5946+ func TestNoneOfCIValidation (t * testing.T ) {
5947+ validate := New ()
5948+
5949+ passSpecs := []struct {
5950+ f any
5951+ t string
5952+ }{
5953+ {f : "" , t : "noneofci=red green" },
5954+ {f : "yellow" , t : "noneofci=red green" },
5955+ {f : "green" , t : "noneofci='red yellow' blue" },
5956+ {f : "RED" , t : "noneofci=blue green" },
5957+ {f : "RED" , t : "noneofci=BLUE GREEN" },
5958+ {f : "ReD" , t : "noneofci=BLUE GREEN" },
5959+ {f : "gReEn" , t : "noneofci=rEd BlUe" },
5960+ {f : "red Green" , t : "noneofci='BLUE YELLOW' Orange" },
5961+ {f : "Red green" , t : "noneofci='Blue Yellow' ORANGE" },
5962+ {f : "rEd GrEeN" , t : "noneofci='bLuE YeLlOw' OrAnGe" },
5963+ {f : "BlUe" , t : "noneofci='RED GREEN' Yellow" },
5964+ {f : "bLuE" , t : "noneofci='red green' YELLOW" },
5965+ }
5966+ for _ , spec := range passSpecs {
5967+ t .Logf ("%#v" , spec )
5968+ errs := validate .Var (spec .f , spec .t )
5969+ Equal (t , errs , nil )
5970+ }
5971+
5972+ failSpecs := []struct {
5973+ f any
5974+ t string
5975+ }{
5976+ {f : "red" , t : "noneofci=red green" },
5977+ {f : "green" , t : "noneofci=red green" },
5978+ {f : "red green" , t : "noneofci='red green' blue'" },
5979+ }
5980+ for _ , spec := range failSpecs {
5981+ t .Logf ("%#v" , spec )
5982+ errs := validate .Var (spec .f , spec .t )
5983+ AssertError (t , errs , "" , "" , "" , "" , "noneofci" )
5984+ }
5985+
5986+ panicSpecs := []struct {
5987+ f any
5988+ t string
5989+ }{
5990+ {f : 3.14 , t : "noneofci=red green" },
5991+ {f : 5 , t : "noneofci=red green" },
5992+ {f : int8 (5 ), t : "noneofci=red green" },
5993+ {f : int16 (5 ), t : "noneofci=red green" },
5994+ {f : int32 (5 ), t : "noneofci=red green" },
5995+ {f : int64 (5 ), t : "noneofci=red green" },
5996+ {f : uint (5 ), t : "noneofci=red green" },
5997+ {f : uint8 (5 ), t : "noneofci=red green" },
5998+ {f : uint16 (5 ), t : "noneofci=red green" },
5999+ {f : uint32 (5 ), t : "noneofci=red green" },
6000+ {f : uint64 (5 ), t : "noneofci=red green" },
6001+ }
6002+ panicCount := 0
6003+ for _ , spec := range panicSpecs {
6004+ t .Logf ("%#v" , spec )
6005+ PanicMatches (t , func () {
6006+ _ = validate .Var (spec .f , spec .t )
6007+ }, fmt .Sprintf ("Bad field type %T" , spec .f ))
6008+ panicCount ++
6009+ }
6010+ Equal (t , panicCount , len (panicSpecs ))
6011+ }
6012+
58866013func TestBase32Validation (t * testing.T ) {
58876014 validate := New ()
58886015
0 commit comments