@@ -5680,6 +5680,82 @@ func TestOneOfValidation(t *testing.T) {
5680
5680
}, "Bad field type float64" )
5681
5681
}
5682
5682
5683
+ func TestOneOfCIValidation (t * testing.T ) {
5684
+ validate := New ()
5685
+
5686
+ passSpecs := []struct {
5687
+ f interface {}
5688
+ t string
5689
+ }{
5690
+ {f : "red" , t : "oneofci=RED GREEN" },
5691
+ {f : "RED" , t : "oneofci=red green" },
5692
+ {f : "red" , t : "oneofci=red green" },
5693
+ {f : "RED" , t : "oneofci=RED GREEN" },
5694
+ {f : "green" , t : "oneofci=red green" },
5695
+ {f : "red green" , t : "oneofci='red green' blue" },
5696
+ {f : "blue" , t : "oneofci='red green' blue" },
5697
+ {f : "GREEN" , t : "oneofci=Red Green" },
5698
+ {f : "ReD" , t : "oneofci=RED GREEN" },
5699
+ {f : "gReEn" , t : "oneofci=rEd GrEeN" },
5700
+ {f : "RED GREEN" , t : "oneofci='red green' blue" },
5701
+ {f : "red Green" , t : "oneofci='RED GREEN' Blue" },
5702
+ {f : "Red green" , t : "oneofci='Red Green' BLUE" },
5703
+ {f : "rEd GrEeN" , t : "oneofci='ReD gReEn' BlUe" },
5704
+ {f : "BLUE" , t : "oneofci='Red Green' BLUE" },
5705
+ {f : "BlUe" , t : "oneofci='RED GREEN' Blue" },
5706
+ {f : "bLuE" , t : "oneofci='red green' BLUE" },
5707
+ }
5708
+
5709
+ for _ , spec := range passSpecs {
5710
+ t .Logf ("%#v" , spec )
5711
+ errs := validate .Var (spec .f , spec .t )
5712
+ Equal (t , errs , nil )
5713
+ }
5714
+
5715
+ failSpecs := []struct {
5716
+ f interface {}
5717
+ t string
5718
+ }{
5719
+ {f : "" , t : "oneofci=red green" },
5720
+ {f : "yellow" , t : "oneofci=red green" },
5721
+ {f : "green" , t : "oneofci='red green' blue" },
5722
+ }
5723
+
5724
+ for _ , spec := range failSpecs {
5725
+ t .Logf ("%#v" , spec )
5726
+ errs := validate .Var (spec .f , spec .t )
5727
+ AssertError (t , errs , "" , "" , "" , "" , "oneofci" )
5728
+ }
5729
+
5730
+ panicSpecs := []struct {
5731
+ f interface {}
5732
+ t string
5733
+ }{
5734
+ {f : 3.14 , t : "oneofci=red green" },
5735
+ {f : 5 , t : "oneofci=red green" },
5736
+ {f : uint (6 ), t : "oneofci=7" },
5737
+ {f : int8 (5 ), t : "oneofci=red green" },
5738
+ {f : int16 (5 ), t : "oneofci=red green" },
5739
+ {f : int32 (5 ), t : "oneofci=red green" },
5740
+ {f : int64 (5 ), t : "oneofci=red green" },
5741
+ {f : uint (5 ), t : "oneofci=red green" },
5742
+ {f : uint8 (5 ), t : "oneofci=red green" },
5743
+ {f : uint16 (5 ), t : "oneofci=red green" },
5744
+ {f : uint32 (5 ), t : "oneofci=red green" },
5745
+ {f : uint64 (5 ), t : "oneofci=red green" },
5746
+ }
5747
+
5748
+ panicCount := 0
5749
+ for _ , spec := range panicSpecs {
5750
+ t .Logf ("%#v" , spec )
5751
+ PanicMatches (t , func () {
5752
+ _ = validate .Var (spec .f , spec .t )
5753
+ }, fmt .Sprintf ("Bad field type %T" , spec .f ))
5754
+ panicCount ++
5755
+ }
5756
+ Equal (t , panicCount , len (panicSpecs ))
5757
+ }
5758
+
5683
5759
func TestBase32Validation (t * testing.T ) {
5684
5760
validate := New ()
5685
5761
0 commit comments