github.com/jduhamel/gcli@v0.2.4-0.20151019142748-0d5307cd7e21/command/flag_flag_test.go (about) 1 package command 2 3 import ( 4 "flag" 5 "reflect" 6 "testing" 7 8 "github.com/tcnksm/gcli/skeleton" 9 ) 10 11 func TestFlagFlag_implements(t *testing.T) { 12 var raw interface{} 13 raw = new(FlagFlag) 14 if _, ok := raw.(flag.Value); !ok { 15 t.Fatal("FlagFlag should be flag.Value") 16 } 17 } 18 19 func TestFlagFlag_Set(t *testing.T) { 20 tests := []struct { 21 arg string 22 success bool 23 expect FlagFlag 24 }{ 25 { 26 arg: `debug:string:"Run as debug mode"`, 27 success: true, 28 expect: []*skeleton.Flag{ 29 { 30 Name: "debug", 31 LongName: "debug", 32 VariableName: "debug", 33 ShortName: "d", 34 TypeString: skeleton.TypeStringString, 35 Default: "", 36 Description: "Run as debug mode", 37 }, 38 }, 39 }, 40 { 41 arg: `debug,help,test`, 42 success: true, 43 expect: []*skeleton.Flag{ 44 {Name: "debug", LongName: "debug", VariableName: "debug", ShortName: "d", TypeString: skeleton.TypeStringString, Default: ""}, 45 {Name: "help", LongName: "help", VariableName: "help", ShortName: "h", TypeString: skeleton.TypeStringString, Default: ""}, 46 {Name: "test", LongName: "test", VariableName: "test", ShortName: "t", TypeString: skeleton.TypeStringString, Default: ""}, 47 }, 48 }, 49 } 50 51 for i, tt := range tests { 52 c := new(FlagFlag) 53 err := c.Set(tt.arg) 54 if tt.success && err != nil { 55 t.Fatalf("#%d Set(%q) expects not to happen error: %s", i, tt.arg, err) 56 } 57 58 if !reflect.DeepEqual(*c, tt.expect) { 59 t.Errorf("#%d expects %v to be eq %v", i, *c, tt.expect) 60 } 61 } 62 }