github.com/mailru/activerecord@v1.12.2/pkg/iproto/util/pool/poolflag/poolflag_test.go (about) 1 package poolflag 2 3 import ( 4 "flag" 5 "reflect" 6 "testing" 7 ) 8 9 func TestFlagSetWrapperFloat64Slice(t *testing.T) { 10 for _, test := range []struct { 11 name string 12 args []string 13 def []float64 14 exp []float64 15 err bool 16 }{ 17 { 18 def: []float64{1, 2, 3}, 19 exp: []float64{1, 2, 3}, 20 }, 21 { 22 def: []float64{1, 2, 3}, 23 args: []string{"-slice=3,4,5"}, 24 exp: []float64{3, 4, 5}, 25 }, 26 { 27 def: []float64{1, 2, 3}, 28 args: []string{"-slice= 3.14, 3.15 "}, 29 exp: []float64{3.14, 3.15}, 30 }, 31 { 32 def: []float64{1, 2, 3}, 33 exp: []float64{1, 2, 3}, 34 args: []string{"-slice=3.x"}, 35 err: true, 36 }, 37 } { 38 t.Run(test.name, func(t *testing.T) { 39 f := flag.NewFlagSet("test", flag.ContinueOnError) 40 w := flagSetWrapper{f} 41 42 v := w.Float64Slice("slice", test.def, "description") 43 44 err := f.Parse(test.args) 45 if test.err && err == nil { 46 t.Errorf("unexpected nil error") 47 } 48 if !test.err && err != nil { 49 t.Errorf("unexpected error: %v", err) 50 } 51 52 if act, exp := *v, test.exp; !reflect.DeepEqual(act, exp) { 53 t.Errorf("unexpected value: %v; want %v", act, exp) 54 } 55 }) 56 } 57 }